-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[GitHub][workflows] Ask reviewers to merge PRs when author cannot #81142
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ede1f5f
[GitHub][workflows] Ask reviewers to merge PRs when author can not
DavidSpickett f7fb148
_ -> -
DavidSpickett 582aac7
Address reviewer instead.
DavidSpickett 1e566a4
We need reviewer and author names.
DavidSpickett 5b135d3
Modify message if reviewer also does not have merge permission.
DavidSpickett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: "Prompt reviewers to merge PRs on behalf of authors" | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
pull_request_review: | ||
types: | ||
- submitted | ||
|
||
jobs: | ||
merge-on-behalf-information-comment: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
if: >- | ||
(github.repository == 'llvm/llvm-project') && | ||
(github.event.review.state == 'APPROVED') | ||
steps: | ||
- name: Checkout Automation Script | ||
uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: llvm/utils/git/ | ||
ref: main | ||
|
||
- name: Setup Automation Script | ||
working-directory: ./llvm/utils/git/ | ||
run: | | ||
pip install -r requirements.txt | ||
|
||
- name: Add Merge On Behalf Comment | ||
working-directory: ./llvm/utils/git/ | ||
run: | | ||
python3 ./github-automation.py \ | ||
--token '${{ secrets.GITHUB_TOKEN }}' \ | ||
pr-merge-on-behalf-information \ | ||
--issue-number "${{ github.event.pull_request.number }}" \ | ||
--author "${{ github.event.pull_request.user.login }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -298,6 +298,44 @@ def run(self) -> bool: | |
return True | ||
|
||
|
||
class PRMergeOnBehalfInformation: | ||
COMMENT_TAG = "<!--LLVM MERGE ON BEHALF INFORMATION COMMENT-->\n" | ||
|
||
def __init__(self, token: str, repo: str, pr_number: int, author: str): | ||
self.repo = github.Github(token).get_repo(repo) | ||
self.pr = self.repo.get_issue(pr_number).as_pull_request() | ||
self.author = author | ||
|
||
def run(self) -> bool: | ||
# Check this first because it only costs 1 API point. | ||
try: | ||
if self.repo.get_collaborator_permission(self.author) in ["admin", "write"]: | ||
return | ||
# There is a UnknownObjectException for this scenario, but this method | ||
# does not use it. | ||
except github.GithubException as e: | ||
# 404 means the author was not found in the collaborator list, so we | ||
# know they don't have push permissions. Anything else is a real API | ||
# issue, raise it so it is visible. | ||
if e.status != 404: | ||
raise e | ||
|
||
# A review can be approved more than once, only comment the first time. | ||
for comment in self.pr.as_issue().get_comments(): | ||
if self.COMMENT_TAG in comment.body: | ||
return | ||
|
||
# This text is using Markdown formatting. | ||
comment = f"""\ | ||
{self.COMMENT_TAG} | ||
@{self.author} you do not have permissions to merge your own PRs yet. Please let us know when you are happy for this to be merged, and one of the reviewers can merge it on your behalf. | ||
|
||
(if many approvals are required, please wait until everyone has approved before merging) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this message should be directed at the reviewer, not the author. |
||
""" | ||
self.pr.as_issue().create_comment(comment) | ||
return True | ||
|
||
|
||
def setup_llvmbot_git(git_dir="."): | ||
""" | ||
Configure the git repo in `git_dir` with the llvmbot account so | ||
|
@@ -647,6 +685,14 @@ def execute_command(self) -> bool: | |
pr_buildbot_information_parser.add_argument("--issue-number", type=int, required=True) | ||
pr_buildbot_information_parser.add_argument("--author", type=str, required=True) | ||
|
||
pr_merge_on_behalf_information_parser = subparsers.add_parser( | ||
"pr-merge-on-behalf-information" | ||
) | ||
pr_merge_on_behalf_information_parser.add_argument( | ||
"--issue-number", type=int, required=True | ||
) | ||
pr_merge_on_behalf_information_parser.add_argument("--author", type=str, required=True) | ||
|
||
release_workflow_parser = subparsers.add_parser("release-workflow") | ||
release_workflow_parser.add_argument( | ||
"--llvm-project-dir", | ||
|
@@ -700,6 +746,11 @@ def execute_command(self) -> bool: | |
args.token, args.repo, args.issue_number, args.author | ||
) | ||
pr_buildbot_information.run() | ||
elif args.command == "pr-merge-on-behalf-information": | ||
pr_merge_on_behalf_information = PRMergeOnBehalfInformation( | ||
args.token, args.repo, args.issue_number, args.author | ||
) | ||
pr_merge_on_behalf_information.run() | ||
elif args.command == "release-workflow": | ||
release_workflow = ReleaseWorkflow( | ||
args.token, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the default GITHUB_TOKEN @mention people?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can @mention people but not teams so this should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my fork it was able to @ mention me at least (but I could have different settings so that could be why).