[llvm] github-automation: Use a single comment for team mentions on pull requests (PR #66037)
Tom Stellard via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 12 10:17:12 PDT 2023
https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/66037:
>From 3ed30fcc16fee058be0903a5ba70750fa3d048af Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 11 Sep 2023 18:57:42 -0700
Subject: [PATCH 1/6] github-automation: Use a single comment for team mentions
on pull requests
This will reduce the number of notifications created when a pull request
label is added. Each team will only get a notification when their
team's label is added and not when other teams' labels are added.
---
.github/workflows/pr-subscriber.yml | 8 ++++++++
llvm/utils/git/github-automation.py | 21 +++++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/pr-subscriber.yml b/.github/workflows/pr-subscriber.yml
index 3b18c8b35e97d1a..14e6cb33c57f9f6 100644
--- a/.github/workflows/pr-subscriber.yml
+++ b/.github/workflows/pr-subscriber.yml
@@ -9,6 +9,14 @@ on:
permissions:
contents: read
+concurrency:
+ # Ideally, we would use the PR number in the concurrency group, but we don't
+ # have access to it here. We need to ensure only one job is running for
+ # each PR at a time, because there is a potentaill race condition when
+ # updating the issue comment.
+ group: "PR Subscriber"
+ cancel-in-progress: false
+
jobs:
auto-subscribe:
runs-on: ubuntu-latest
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index c4c4848fbc5f8bc..1cf0faa57d1ec15 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -95,6 +95,15 @@ def __init__(self, token: str, repo: str, pr_number: int, label_name: str):
self.org = github.Github(token).get_organization(self.repo.organization.login)
self.pr = self.repo.get_issue(pr_number).as_pull_request()
self._team_name = "pr-subscribers-{}".format(label_name).lower()
+ self.COMMENT_TAG = "<!--LLVM PR SUMMARY COMMENT-->\n"
+
+ def get_summary_comment(self) -> github.IssueComment.IssueComment:
+ for comment in self.pr.as_issue().get_comments():
+ if not self.COMMENT_TAG in comment.body:
+ continue
+ return comment
+ return None
+
def run(self) -> bool:
patch = None
@@ -131,10 +140,12 @@ def run(self) -> bool:
patch_link = f"\nPatch is {human_readable_size(len(patch))}, truncated to {human_readable_size(DIFF_LIMIT)} below, full version: {self.pr.diff_url}\n"
diff_stats = diff_stats[0:DIFF_LIMIT] + "...\n<truncated>\n"
diff_stats += "</pre>"
+ team_mention = "@llvm/{}".format(team.slug)
body = self.pr.body
comment = (
- "@llvm/{}".format(team.slug)
+ self.COMMENT_TAG
+ + team_mention
+ "\n\n<details>\n"
+ f"<summary>Changes</summary>\n\n"
+ f"{body}\n--\n"
@@ -144,7 +155,13 @@ def run(self) -> bool:
+ "</details>"
)
- self.pr.as_issue().create_comment(comment)
+ summary_comment = self.get_summary_comment()
+ if not summary_comment:
+ self.pr.as_issue().create_comment(comment)
+ elif team_mention + "\n" in summary_comment.body:
+ print("Team {} already mentioned.".format(team.slug))
+ else:
+ summary_comment.edit(summary_comment.body.replace(self.COMMENT_TAG, self.COMMENT_TAG + team_mention + "\n"))
return True
def _get_curent_team(self) -> Optional[github.Team.Team]:
>From f0c8979d5b49683666dcd9448eb5e1f306fb60d2 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 11 Sep 2023 20:56:33 -0700
Subject: [PATCH 2/6] Update .github/workflows/pr-subscriber.yml
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
---
.github/workflows/pr-subscriber.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/pr-subscriber.yml b/.github/workflows/pr-subscriber.yml
index 14e6cb33c57f9f6..60c884cb172c2a2 100644
--- a/.github/workflows/pr-subscriber.yml
+++ b/.github/workflows/pr-subscriber.yml
@@ -12,7 +12,7 @@ permissions:
concurrency:
# Ideally, we would use the PR number in the concurrency group, but we don't
# have access to it here. We need to ensure only one job is running for
- # each PR at a time, because there is a potentaill race condition when
+ # each PR at a time, because there is a potential race condition when
# updating the issue comment.
group: "PR Subscriber"
cancel-in-progress: false
>From 5a6a2d1351e3e0575395623d467fad9f7ec91c10 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 11 Sep 2023 20:58:28 -0700
Subject: [PATCH 3/6] Update llvm/utils/git/github-automation.py
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
---
llvm/utils/git/github-automation.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 1cf0faa57d1ec15..79f936047f52ed8 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -99,9 +99,8 @@ def __init__(self, token: str, repo: str, pr_number: int, label_name: str):
def get_summary_comment(self) -> github.IssueComment.IssueComment:
for comment in self.pr.as_issue().get_comments():
- if not self.COMMENT_TAG in comment.body:
- continue
- return comment
+ if self.COMMENT_TAG in comment.body:
+ return comment
return None
>From e48376938bcc0ec80984e474dd5e2721f701b774 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 11 Sep 2023 21:41:36 -0700
Subject: [PATCH 4/6] Fix formatting issues
---
llvm/utils/git/github-automation.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 79f936047f52ed8..66d2b9fa400fa4a 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -160,7 +160,9 @@ def run(self) -> bool:
elif team_mention + "\n" in summary_comment.body:
print("Team {} already mentioned.".format(team.slug))
else:
- summary_comment.edit(summary_comment.body.replace(self.COMMENT_TAG, self.COMMENT_TAG + team_mention + "\n"))
+ summary_comment.edit(
+ summary_comment.body.replace(
+ self.COMMENT_TAG, self.COMMENT_TAG + team_mention + "\n"))
return True
def _get_curent_team(self) -> Optional[github.Team.Team]:
>From b26a78dd9a670eba46900e027f30372bf9016ad4 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Tue, 12 Sep 2023 10:02:01 -0700
Subject: [PATCH 5/6] Update llvm/utils/git/github-automation.py
Co-authored-by: cor3ntin <corentinjabot at gmail.com>
---
llvm/utils/git/github-automation.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 66d2b9fa400fa4a..b2a9c85c2e677d3 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -142,7 +142,18 @@ def run(self) -> bool:
team_mention = "@llvm/{}".format(team.slug)
body = self.pr.body
- comment = (
+ comment = f"""
+ {self.COMMENT_TAG}
+ {team_mention}
+
+ <details>
+ <summary>Changes</summary>
+ {body}
+ --
+ {patch_link}
+ {diff_stats}
+ </details>
+ """
self.COMMENT_TAG
+ team_mention
+ "\n\n<details>\n"
>From aa7fadd70545b7036fd67d276ccec6bc0766de4c Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Tue, 12 Sep 2023 10:16:43 -0700
Subject: [PATCH 6/6] Fix syntax
---
llvm/utils/git/github-automation.py | 30 ++++++++++-------------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index b2a9c85c2e677d3..de131b5ffb40528 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -143,27 +143,17 @@ def run(self) -> bool:
body = self.pr.body
comment = f"""
- {self.COMMENT_TAG}
- {team_mention}
+{self.COMMENT_TAG}
+{team_mention}
- <details>
- <summary>Changes</summary>
- {body}
- --
- {patch_link}
- {diff_stats}
- </details>
- """
- self.COMMENT_TAG
- + team_mention
- + "\n\n<details>\n"
- + f"<summary>Changes</summary>\n\n"
- + f"{body}\n--\n"
- + patch_link
- + "\n"
- + f"{diff_stats}\n\n"
- + "</details>"
- )
+<details>
+<summary>Changes</summary>
+{body}
+--
+{patch_link}
+{diff_stats}
+</details>
+"""
summary_comment = self.get_summary_comment()
if not summary_comment:
More information about the llvm-commits
mailing list