-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Missing important field to find branch in fork from same organization #2872
Description
Hi everyone!
In a few days ago, I've been working in a script automation that uses the go-githhub library (btw that is awsome!). One of the steps was create a Pull request from a fork. Not a personal one, but from the same ownership from upstream repository. However it was there that I through by a problematic question because my branch from this fork couldn't be found anyway.
The struct using to the method can be found with these fields:
- struct:
// NewPullRequest represents a new pull request to be created.
type NewPullRequest struct {
Title *string `json:"title,omitempty"`
Head *string `json:"head,omitempty"`
Base *string `json:"base,omitempty"`
Body *string `json:"body,omitempty"`
Issue *int `json:"issue,omitempty"`
MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"`
Draft *bool `json:"draft,omitempty"`
}
- method:
// GitHub API docs: https://docs.github.com/en/rest/pulls/pulls#create-a-pull-request
func (s *PullRequestsService) Create(ctx context.Context, owner string, repo string, pull *NewPullRequest) (*PullRequest, *Response, error)
I tried mount the branch path to pass in Head field with some variation like:
- {branch-name}
- {forked-repository-name}/{branch-name}
- {ownership}:{forked-repository-name}/{branch-name}
- {ownership}/{forked-repository-name}/{branch-name}
And I always receive the response 422: Unprocessable Entity pointing Head value as Invalid Message. With some research the possibilites were that the path was not well formed or the brach couldn't be reached.
So, reading Create method from github api documentation I could notice that field head_repo and its doc says: The name of the repository where the changes in the pull request were made. This field is required for cross-repository pull requests if both repositories are owned by the same organization.
So I thought: "This is exactly that I need". I create a new method calling a http post request by hand. The json body was adjusted to receive:
- head: {branch-path}
- head_repo: {owner}/{forked-repository-name}
And worked not using go-github library.
Then, after all of this, I forked go-github to try this change adding this field found in github api documentation in PullRequest structure to pass these values and guess what? - It worked again!
I create a pull request that add this field for review. :)