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

Does git machete support creating a PR from a fork to the upstream repo? #925

Open
cspotcode opened this issue May 3, 2023 · 5 comments · May be fixed by #1246
Open

Does git machete support creating a PR from a fork to the upstream repo? #925

cspotcode opened this issue May 3, 2023 · 5 comments · May be fixed by #1246
Assignees
Labels
bug Something isn't working github Relates to integration with GitHub gitlab Relates to integration with GitLab
Milestone

Comments

@cspotcode
Copy link
Contributor

Forgive my skipping the issue template. I'm not sure if git machete is meant to be used for the common open-source workflow, where you're creating a PR from your fork repo to the project's main repo? So the PR's base and head are on different remotes.

git machete github create-pr is giving me this error, and I'm not sure if I should dig into the problem, or if this is a known limitation of git machete.

Creating a PR from foo to development... {'message': 'Validation Failed', 'errors': [{'resource': 'PullRequest', 'field': 'head', 'code': 'invalid'}], 'documentation_url': 'https://docs.github.com/rest/reference/pulls#create-a-pull-request'}

I have two remotes, origin which is the project's main repo, and me which is my github fork. foo is a branch pushed to my fork, and development is the default branch of the project's main repo.

@PawelLipski PawelLipski added this to the v3.17.3 milestone May 3, 2023
@PawelLipski PawelLipski self-assigned this May 3, 2023
@PawelLipski PawelLipski added bug Something isn't working github Relates to integration with GitHub labels May 3, 2023
@PawelLipski
Copy link
Collaborator

PawelLipski commented May 3, 2023

EDIT: debug logs not needed anymore

Huh this flow should definitely be supported and I'm pretty sure I've used github create-pr in a similar manner a couple times already (beyond development of git-machete itself)... still, I'll investigate that. In the meantime, if you could re-run the failing command in debug mode and attach the output:

git machete github create-pr --debug

I hope the data included in the debug (like repo URL, branch names etc.) won't be subject to any NDAs on your side (given it's open source).
Note that access tokens will all be redacted in the output, you can ofc verify yourself by grepping for ghp.

@PawelLipski
Copy link
Collaborator

Whoops okay... indeed, support for this scenario seems to be missing 😯 not sure how come we've missed that. To be added soon

@PawelLipski PawelLipski linked a pull request May 3, 2023 that will close this issue
@cspotcode
Copy link
Contributor Author

It's perhaps moot, since you can't exactly do stacked PRs when working with github forks. The problem is, if I want to create stacked PRs for contributing to an OSS project ossteam/libfoo from my fork cspotcode/libfoo:

First PR is from cspotcode/libfoo branch branch-1 into ossteam/libfoo branch master
Second PR is from cspotcode/libfoo branch branch-2 into cspotcode/libfoo branch branch-1

That second PR will not appear in the PR queue for ossteam/libfoo since it's not targetting a branch on their repo, it's targetting a branch on mine. Kinda breaks the workflow. Not git-machete's fault, there's nothing you can really do. I suppose I could make the first PR, wait for it to merge, and then be able to submit the second one.

@PawelLipski
Copy link
Collaborator

PawelLipski commented May 4, 2023

It's perhaps moot, since you can't exactly do stacked PRs when working with github forks

Yeah, GitHub doesn't support working with stacked PRs on forks :/ Anyway, as a quick workaround to keep the effects of git machete github create-pr on PRs directly to origin branch, you can use git machete github anno-prs right after creating the PR, this works correctly for PRs from forks. Lmk if you find any issues with that approach, that should be way easier to fix than adding support for forks in create-pr 🤔

@PawelLipski PawelLipski removed this from the v3.18.0 milestone May 4, 2023
@PawelLipski PawelLipski removed their assignment Jun 1, 2023
@PawelLipski PawelLipski reopened this Apr 2, 2024
@PawelLipski
Copy link
Collaborator

Still, I think getting errors like this one:

Creating a draft PR from foo-bar-1 to master... __fire_github_api_request(method=POST, path=/repos/VirtusLab/git-machete/pulls, request_body={'head': 'foo-bar-1', 'base': 'master', 'title': 'wip', 'body': '', 'draft': 'True'}): firing a POST request to https://api.github.com/repos/VirtusLab/git-machete/pulls with a bearer token and request body {'head': 'foo-bar-1', 'base': 'master', 'title': 'wip', 'body': '', 'draft': 'True'}
{'resource': 'PullRequest', 'field': 'head', 'code': 'invalid'}

should be avoided.

What I'd go for here is to add support for creating PRs from forks indeed. More specifically:

  1. before creating a PR, check whether remote for tracking base and head branches are different
  2. if they're different, use the "head": "fork:branch" format instead of "head": "branch" in POST request body (TBD how to do it for GitLab, see Add GitLab support #1189)
  3. display an extra warning to the user that it won't work for stacked PRs as well due to GitHub's limitations (TBD how it looks like in GitLab, as well)

@PawelLipski PawelLipski modified the milestones: v3.25.0, v3.25.1 Apr 2, 2024
@PawelLipski PawelLipski self-assigned this Apr 9, 2024
@PawelLipski PawelLipski added the gitlab Relates to integration with GitLab label Apr 9, 2024
@PawelLipski PawelLipski modified the milestones: v3.25.1, v3.25.2 Apr 19, 2024
@PawelLipski PawelLipski linked a pull request May 8, 2024 that will close this issue
@PawelLipski PawelLipski modified the milestones: v3.25.3, v3.26.1 May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working github Relates to integration with GitHub gitlab Relates to integration with GitLab
Projects
None yet
2 participants