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

Clarify permissions needed for auto-merge (--pr-merge) #280

Open
MPV opened this issue Nov 20, 2023 · 7 comments
Open

Clarify permissions needed for auto-merge (--pr-merge) #280

MPV opened this issue Nov 20, 2023 · 7 comments

Comments

@MPV
Copy link
Contributor

MPV commented Nov 20, 2023

Hi,
Could we clarify the permissions needed for auto-merge (--pr-merge), as described here:

--pr-merge (bool): if enabled, the Pull Requests will be automatically merged. It will wait until the PRs are “mergeable” before merging them. Default to false.

-- https://dailymotion-oss.github.io/octopilot/v1.5.3/index.html#merging-pull-requests

I'm running it using a GitHub App myself, but I imagine the same permission model might apply to personal access tokens (PAT).

@MPV
Copy link
Contributor Author

MPV commented Nov 20, 2023

For example, before I realized I needed to grant repository admin view permissions, I got errors like this:

failed to retrieve the required status checks for branch master: GET https://api.github.com/repos/my-org/my-repo/branches/master/protection/required_status_checks: 403 Resource not accessible by integration []

...as seen in this excerpt:

[...]
time="2023-11-20T08:21:25Z" level=debug msg="Pull Request is mergeable" pull-request="https://github.com/my-org/my-repo/pull/16" repository=my-org/my-repo
time="2023-11-20T08:21:25Z" level=error msg="Repository update failed" error="failed to merge Pull Request https://github.com/my-org/my-repo/pull/16: failed to wait until Pull Request https://github.com/my-org/my-repo/pull/16 is mergeable: failed to retrieve the required status checks for branch master: GET https://api.github.com/repos/my-org/my-repo/branches/master/protection/required_status_checks: 403 Resource not accessible by integration []" repository=my-org/my-repo

...likely related to this issue:

@MPV
Copy link
Contributor Author

MPV commented Nov 20, 2023

But now when I've granted "repo admin view" permissions, I instead get this error (which I've yet to find the permission for):

failed to retrieve combined status of Pull Request https://github.com/my-org/my-repo/pull/3 for ref 0e5f7f8ce0e2372dbf53ce955223e8ac2e5c4b73: GET https://api.github.com/repos/my-org/my-repo/commits/0e5f7f8ce0e2372dbf53ce955223e8ac2e5c4b73/status: 403 Resource not accessible by integration []

...as seen in this excerpt:

time="2023-11-20T08:33:15Z" level=debug msg="Pull Request is mergeable" pull-request="https://github.com/my-org/my-repo/pull/3" repository=my-org/my-repo
time="2023-11-20T08:33:16Z" level=error msg="Repository update failed" error="failed to merge Pull Request https://github.com/my-org/my-repo/pull/3: failed to wait until Pull Request https://github.com/my-org/my-repo/pull/3 is mergeable: failed to retrieve combined status of Pull Request https://github.com/my-org/my-repo/pull/3 for ref 0e5f7f8ce0e2372dbf53ce955223e8ac2e5c4b73: GET https://api.github.com/repos/my-org/my-repo/commits/0e5f7f8ce0e2372dbf53ce955223e8ac2e5c4b73/status: 403 Resource not accessible by integration []" repository=my-org/my-repo

@MPV MPV changed the title Clarify permissions needed for auto-merge Clarify permissions needed for auto-merge (--pr-merge) Nov 20, 2023
@MPV
Copy link
Contributor Author

MPV commented Nov 20, 2023

But now when I've granted "repo admin view" permissions, I instead get this error (which I've yet to find the permission for):

failed to retrieve combined status of Pull Request https://github.com/my-org/my-repo/pull/3 for ref 0e5f7f8ce0e2372dbf53ce955223e8ac2e5c4b73: GET https://api.github.com/repos/my-org/my-repo/commits/0e5f7f8ce0e2372dbf53ce955223e8ac2e5c4b73/status: 403 Resource not accessible by integration []

I solved this one by granting Commit Statuses: Read. ✅

...as outlined here (I finally found those docs):

@MPV
Copy link
Contributor Author

MPV commented Nov 20, 2023

So far the permissions I've granted are:

What Permission Comment
Administration Read-only
Checks Read-only
Commit statuses Read-only
Contents Read and write
Metadata (mandatory) Read-only
Pull requests Read and write
Workflows Read and write (as I'm making changes to such files)

@MPV
Copy link
Contributor Author

MPV commented Nov 20, 2023

...and now I'm at a place where it's failing with:

to merge Pull Request https://github.com/my-org/my-repo/pull/3: PUT https://api.github.com/repos/my-org/my-repo/pulls/3/merge: 405 Repository rule violations found\n\nAt least 1 approving review is required by reviewers with write access.\n\n []

...as seen in this excerpt:

time="2023-11-20T09:00:35Z" level=debug msg="Pull Request can be merged" pull-request="https://github.com/my-org/my-repo/pull/3" repository=my-org/my-repo
time="2023-11-20T09:00:37Z" level=error msg="Repository update failed" error="failed to merge Pull Request https://github.com/my-org/my-repo/pull/3: failed to merge Pull Request https://github.com/my-org/my-repo/pull/3: PUT https://api.github.com/repos/my-org/my-repo/pulls/3/merge: 405 Repository rule violations found\n\nAt least 1 approving review is required by reviewers with write access.\n\n []" repository=my-org/my-repo

@vbehar
Copy link
Collaborator

vbehar commented Nov 22, 2023

thanks for the detailed report. Indeed we need to do a better job at documenting the repository settings.
for your last issue (required review), we could also add an extra option to auto-approve the PR, although again depending on the repository settings this might or might not work.
I'll also have a look at github API to see if we can enable auto-merging by github when everything is OK

@MPV
Copy link
Contributor Author

MPV commented Nov 24, 2023

for your last issue (required review), we could also add an extra option to auto-approve the PR, although again depending on the repository settings this might or might not work.

I'll also have a look at github API to see if we can enable auto-merging by github when everything is OK

That's amazing ideas! 😍

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

No branches or pull requests

2 participants