Skip to content

[GitHub][workflows] Ask reviewers to merge new contributor's PRs #80659

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/approved-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "Prompt reviewers to merge PRs on behalf of new contributors."

permissions:
contents: read

on:
pull_request_review:
types:
- submitted

jobs:
merge_on_behalf_information_comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
# If this PR was approved, and is authored by a new contributor. New
# contributor statuses don't work as expected, so we check that it is not
# any other status instead.
# (see https://github.com/orgs/community/discussions/78038)
if: >-
(github.repository == 'llvm/llvm-project') &&
(github.event.review.state == 'APPROVED') &&
(github.event.pull_request.author_association != 'COLLABORATOR') &&
(github.event.pull_request.author_association != 'CONTRIBUTOR') &&
(github.event.pull_request.author_association != 'MANNEQUIN') &&
(github.event.pull_request.author_association != 'MEMBER') &&
(github.event.pull_request.author_association != 'OWNER')
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 Information 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 }}"
39 changes: 39 additions & 0 deletions llvm/utils/git/github-automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,32 @@ 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):
repo = github.Github(token).get_repo(repo)
self.pr = repo.get_issue(pr_number).as_pull_request()
self.author = author

def run(self) -> bool:
# 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}, as a new contributor 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)
"""
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
Expand Down Expand Up @@ -647,6 +673,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",
Expand Down Expand Up @@ -700,6 +734,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,
Expand Down