Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing important field to find branch in fork from same organization #2872

Closed
r-aramizu opened this issue Aug 15, 2023 · 0 comments · Fixed by #2873
Closed

Missing important field to find branch in fork from same organization #2872

r-aramizu opened this issue Aug 15, 2023 · 0 comments · Fixed by #2873

Comments

@r-aramizu
Copy link
Contributor

r-aramizu commented Aug 15, 2023

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"`
}

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. :)

@r-aramizu r-aramizu changed the title Missing field important to find branch in fork from same owner Missing field important to find branch in fork from same organization Aug 15, 2023
@r-aramizu r-aramizu changed the title Missing field important to find branch in fork from same organization Missing important field to find branch in fork from same organization Aug 16, 2023
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 a pull request may close this issue.

1 participant