Skip to content

Conversation

obnyis
Copy link

@obnyis obnyis commented Jul 18, 2025

This should hopefully fix #3742 - tested on a private enterprise repo

image

I did some testing to discover why this was failing, and found that the "List pull requests" endpoint always returns an empty array if run against an enterprise owned repo when the head query is set - I asume this also applies to other private repos.

@@ -119,10 +119,39 @@ export class GitHubHelper {
head: headBranch,
base: inputs.base
})
let existingPullNumber: number | undefined = undefined
if (pulls?.length === 0 || pulls === null || pulls === undefined) {
core.error(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used error here just so I could find it easier during testing, but should I change this to info or warning instead?

@peter-evans
Copy link
Owner

Interesting. Thank you for looking into this.

First of all, please confirm what version of this action you are using.

I asume this also applies to other private repos

This is not happening on private repos on github.com, so perhaps it's an enterprise issue. I think I need to know more about your testing setup so I can try and reproduce the error. Are you using self-hosted GitHub enterprise, or GitHub-hosted cloud enterprise?

Please provide as much detail as you can about your testing setup.

@obnyis
Copy link
Author

obnyis commented Jul 19, 2025

Using the latest version of the action with peter-evans/create-pull-request@v7 as per the usage notes in the readme.

This is on GitHub-hosted cloud enterprise.

I tested the API using curl commands directly, on a new repo that only had 2 pull requests (one closed and one open)

Starting from a query without any parameters, I was able to confirm that a single element was in the response array, and the value in .[0].head.label was the expected organization:ref-name

curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/pulls

Then tried only adding the head query parameter with the exact value that was seen in the previous query, and got an empty list back. I tried a couple of variations on the format of that argument: changed organization to user, then repo name, and then tried with the value url encoded for all 3 of those

curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/pulls?head=<OWNER>:<headref>

@peter-evans
Copy link
Owner

@obnyis I now understand why this happens. It's a bug that affects the list endpoint when called on forks with the same owner as the repository parent. This has occurred since the ability to fork a repository to the same organization as its parent was added.

I can see that there is already an internal issue tracking this bug.

I'm now going to see if I can reproduce it in my test suite so I have a way to track this behaviour.

@obnyis
Copy link
Author

obnyis commented Jul 30, 2025

@peter-evans Thanks for looking into that, and confirming the bug is on forks only.

I've changed my own tests and workflows to prevent the action running on forks, and confirmed that it works correctly when running on the source repo.

I'll leave it up to you for when you want to close this PR, or if you want me to keep it open and refactor any part of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Private GH repo: Cannot read properties of undefined (reading 'number')
2 participants