-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Describe the bug
GitHub introduce the feature of forking internally here: https://github.blog/changelog/2022-06-27-improved-innersource-collaboration-and-enterprise-fork-policies/
Fork a repository to the same organization as its parent Previously, a repository could be forked only to a different organization or user account. Now, a repository can be forked to the same organization as its parent repository, addressing situations where people are working in one organization and don’t want to fork a repository to a different organization or user account.
But I don't think you've updated your API or tools to support this.
The REST API to create a pull request from an internally forked repository does not work.
However visiting an URL like this works for generating a PR: https://github.com/myorg/myrepo/compare/main...myorg:myrepoforked:mybranch?expand=1
However this does not work programmatically via the API:
# in the myrepoforked directory on the mybranch branch
gh api --method POST -H "Accept: application/vnd.github.v3+json" repos/myorg/myrepo/pulls -F title=test -F body=test -F base=main -F head='myorg:myrepoforked:mybranch'
{
"message": "Validation Failed",
"errors": [
{
"resource": "PullRequest",
"field": "head",
"code": "invalid"
}
],
"documentation_url": "https://docs.github.com/rest/reference/pulls#create-a-pull-request"
}
gh: Validation Failed (HTTP 422)
This is the same issue when using curl directly on the GH API.
I can workaround this by:
# in the myrepoforked directory on the mybranch branch
gh pr create --repo "myorg/myrepo" --title "test" --body "test"
^ actually this doesn't work as expected, running into this error:
gh pr create --repo "myorg/myrepo" --title "test" --body "test" Creating pull request for mybranch into main in myorg/myrepo pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between main and mybranch, Head ref must be a branch (createPullRequest)I went through these issues that seem relevant but can't find a solution:
- PR Create - GraphQL error due to wrong head branch detected #1820
- gh pr create from one remote to other remote #1985
gh pr createdoes not work on remote branches #5465- 'gh pr create' fails if skipping pushing with "GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and <branch>, Head ref must be a branch" #2691
- Detect push target for local branches without upstream configuration #575
However, this type of forking is poorly supported as when I go to list out PRs, things start failing again:
# in the myrepoforked directory on the mybranch branch
gh pr list --repo "myorg/myrepo" --head "mybranch" --state all
Showing 2 of 2 pull requests in myorg/myrepo that match your search
#27 test myorg:mybranch about 28 minutes ago
#26 test mybranch about 1 hour ago
^ notice the PR from myrepoforked is myorg:mybranch and a PR from the branch in myrepo is just mybranch.
Now if I wanted to filter on the forked repo's mybranch and not the original repo's mybranch, it fails:
# in the myrepoforked directory on the mybranch branch
gh pr list --repo "myorg/myrepo" --head "myorg:mybranch" --state all
no pull requests match your search in myorg/myrepo
Steps to reproduce the behavior
- Create a private or internal repository in an organization
- Fork that repo inside the organization under a different name
- Create a branch in the fork
- Attempt to open a PR with the fork's branch back to the original repository with the REST API or the gh CLI tool
- Failure
Expected vs actual behavior
Expected: working with branches in forks with different names in the same organization/user should work.
Actual: does not work.
Logs
gh --version
gh version 2.18.0 (2022-10-18)
https://github.com/cli/cli/releases/tag/v2.18.0
Related
This is related to #2300 and #4859 from what I can find, but note that the method of providing the "base" repo via the --repo flag is not in parity with the REST documentation.