[llvm] workflows: Add some automation for commit access requests (PR #123113)
Tom Stellard via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 15 16:38:51 PST 2025
https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/123113
>From 83ee7a3bc34de2898fe4f2286f9b1c6679beee67 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Wed, 15 Jan 2025 07:52:08 -0800
Subject: [PATCH 1/4] workflows: Add some automation for commit access requests
* Greet the user and ask them to read the developer policy.
* Post their contribution stats on the issue.
---
.github/workflows/commit-access-greeter.yml | 39 +++++++++++++
llvm/utils/git/github-automation.py | 64 +++++++++++++++++++++
2 files changed, 103 insertions(+)
create mode 100644 .github/workflows/commit-access-greeter.yml
diff --git a/.github/workflows/commit-access-greeter.yml b/.github/workflows/commit-access-greeter.yml
new file mode 100644
index 00000000000000..29a1b578f8af8b
--- /dev/null
+++ b/.github/workflows/commit-access-greeter.yml
@@ -0,0 +1,39 @@
+name: Commit Access Greeter
+
+on:
+ issues:
+ types:
+ - labeled
+
+permissions:
+ contents: read
+
+jobs:
+ commit-access-greeter:
+ permissions:
+ issues: write
+ if: >-
+ github.repository_owner == 'llvm' &&
+ github.event.label.name == 'infra:commit-access-request'
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/checkout at 11bd71901bbe5b1630ceea73d27597364c9af683
+ with:
+ sparse-checkout: llvm/utils/git/
+
+ - name: Setup Automation Script
+ working-directory: ./llvm/utils/git/
+ run: |
+ pip install --require-hashes -r requirements.txt
+
+ - name: Add comments to issue
+ working-directory: ./llvm/utils/git/
+ env:
+ LABEL_NAME: ${{ github.event.label.name }}
+ GITHUB_TOKEN: ${{ github.token }}
+ ISSUE_NUMBER: ${{ github.event.issue.number }}
+ run: |
+ python3 ./github-automation.py \
+ --token $GITHUB_TOKEN \
+ commit-request-greeter \
+ --issue-number $ISSUE_NUMBER
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index da467f46b4dd31..1921bbefa0ada6 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -209,6 +209,14 @@ def _get_current_team(self) -> Optional[github.Team.Team]:
return None
+def get_top_values(values : dict, top : int = 3) -> list:
+ return [v for v in sorted(values.items(), key = lambda x: x[1], reverse = True)][:top]
+
+
+def get_user_values_str(values: list) -> str:
+ return ', '.join([f'@{v[0]} ({v[1]})' for v in values])
+
+
class PRGreeter:
COMMENT_TAG = "<!--LLVM NEW CONTRIBUTOR COMMENT-->\n"
@@ -240,6 +248,56 @@ def run(self) -> bool:
self.pr.as_issue().create_comment(comment)
return True
+class CommitRequestGreeter:
+ def __init__(self, token: str, repo: str, issue_number: int):
+ self.repo = github.Github(token).get_repo(repo)
+ self.issue = self.repo.get_issue(issue_number)
+
+ def run(self) -> bool:
+ # Post greeter comment:
+ comment = f"""
+@{self.issue.user.login} thank you for apply for commit access. Please review the project's [code review policy](https://llvm.org/docs/CodeReview.html).
+"""
+ self.issue.create_comment(comment)
+
+ #Post activity summary:
+ total_prs = 0
+ merged_prs = 0
+ merged_by = {}
+ reviewed_by = {}
+ for i in self.repo.get_issues(creator = self.issue.user.login, state = 'all'):
+ issue_reviewed_by = set()
+ try:
+ pr = i.as_pull_request()
+ total_prs += 1
+ for c in pr.get_review_comments():
+ if c.user.login == self.issue.user.login:
+ continue
+ issue_reviewed_by.add(c.user.login)
+ for r in issue_reviewed_by:
+ if r not in reviewed_by:
+ reviewed_by[r] = 1
+ else:
+ reviewed_by[r] += 1
+ if pr.is_merged():
+ merged_prs += 1
+ merger = pr.merged_by.login
+ if merger not in merged_by:
+ merged_by[merger] = 1
+ else:
+ merged_by[merger] += 1
+ continue
+
+ except github.GithubException:
+ continue
+
+ comment = f"""
+### Activity Summary:
+* [{total_prs} Pull Requests](https://github.com/llvm/llvm-project/pulls/{self.issue.user.login}) ({merged_prs} merged)
+* Top 3 Committers: {get_user_values_str(get_top_values(merged_by))}
+* Top 3 Reviewers: {get_user_values_str(get_top_values(reviewed_by))}"""
+ self.issue.create_comment(comment)
+
class PRBuildbotInformation:
COMMENT_TAG = "<!--LLVM BUILDBOT INFORMATION COMMENT-->\n"
@@ -676,6 +734,9 @@ def request_release_note(token: str, repo_name: str, pr_number: int):
pr_greeter_parser = subparsers.add_parser("pr-greeter")
pr_greeter_parser.add_argument("--issue-number", type=int, required=True)
+commit_request_greeter = subparsers.add_parser("commit-request-greeter")
+commit_request_greeter.add_argument("--issue-number", type=int, required=True)
+
pr_buildbot_information_parser = subparsers.add_parser("pr-buildbot-information")
pr_buildbot_information_parser.add_argument("--issue-number", type=int, required=True)
pr_buildbot_information_parser.add_argument("--author", type=str, required=True)
@@ -746,6 +807,9 @@ def request_release_note(token: str, repo_name: str, pr_number: int):
elif args.command == "pr-greeter":
pr_greeter = PRGreeter(args.token, args.repo, args.issue_number)
pr_greeter.run()
+elif args.command == "commit-request-greeter":
+ commit_greeter = CommitRequestGreeter(args.token, args.repo, args.issue_number)
+ commit_greeter.run()
elif args.command == "pr-buildbot-information":
pr_buildbot_information = PRBuildbotInformation(
args.token, args.repo, args.issue_number, args.author
>From 2d2d2c97188befb35944ec8973bc8e1ab69aaae5 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Wed, 15 Jan 2025 11:39:20 -0800
Subject: [PATCH 2/4] Fix formatting
---
llvm/utils/git/github-automation.py | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 1921bbefa0ada6..fbc12d761c75ac 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -210,11 +210,11 @@ def _get_current_team(self) -> Optional[github.Team.Team]:
def get_top_values(values : dict, top : int = 3) -> list:
- return [v for v in sorted(values.items(), key = lambda x: x[1], reverse = True)][:top]
+ return [v for v in sorted(values.items(), key=lambda x: x[1], reverse = True)][:top]
def get_user_values_str(values: list) -> str:
- return ', '.join([f'@{v[0]} ({v[1]})' for v in values])
+ return ", ".join([f"@{v[0]} ({v[1]})" for v in values])
class PRGreeter:
@@ -248,6 +248,7 @@ def run(self) -> bool:
self.pr.as_issue().create_comment(comment)
return True
+
class CommitRequestGreeter:
def __init__(self, token: str, repo: str, issue_number: int):
self.repo = github.Github(token).get_repo(repo)
@@ -260,12 +261,12 @@ def run(self) -> bool:
"""
self.issue.create_comment(comment)
- #Post activity summary:
+ # Post activity summary:
total_prs = 0
merged_prs = 0
merged_by = {}
reviewed_by = {}
- for i in self.repo.get_issues(creator = self.issue.user.login, state = 'all'):
+ for i in self.repo.get_issues(creator=self.issue.user.login, state="all"):
issue_reviewed_by = set()
try:
pr = i.as_pull_request()
>From 58e169335ac4d5f9708ffc7ec88d610930203ee5 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Wed, 15 Jan 2025 16:34:08 -0800
Subject: [PATCH 3/4] Fix formatting
---
llvm/utils/git/github-automation.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index fbc12d761c75ac..8d905481675126 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -210,7 +210,7 @@ def _get_current_team(self) -> Optional[github.Team.Team]:
def get_top_values(values : dict, top : int = 3) -> list:
- return [v for v in sorted(values.items(), key=lambda x: x[1], reverse = True)][:top]
+ return [v for v in sorted(values.items(), key=lambda x: x[1], reverse=True)][:top]
def get_user_values_str(values: list) -> str:
>From 5923ee1d00c8ef84ae27512766ad9f93ddf03486 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Wed, 15 Jan 2025 16:38:32 -0800
Subject: [PATCH 4/4] Fix format
---
llvm/utils/git/github-automation.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 8d905481675126..ff50559f1daccf 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -209,7 +209,7 @@ def _get_current_team(self) -> Optional[github.Team.Team]:
return None
-def get_top_values(values : dict, top : int = 3) -> list:
+def get_top_values(values: dict, top: int = 3) -> list:
return [v for v in sorted(values.items(), key=lambda x: x[1], reverse=True)][:top]
More information about the llvm-commits
mailing list