-
Notifications
You must be signed in to change notification settings - Fork 13.5k
github-automation: Use a single comment for team mentions on pull requests #66037
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
Conversation
@llvm/pr-subscribers-github-workflow Changes…uests 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.Full diff: https://github.com/llvm/llvm-project/pull/66037.diff 2 Files Affected:
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 7df20ea8457155b..a7b88ed383a1238 100755 --- a/llvm/utils/git/github-automation.py +++ b/llvm/utils/git/github-automation.py @@ -83,6 +83,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 = "\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 @@ -119,10 +128,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\n" diff_stats += ""
@@ -132,7 +143,13 @@ def run(self) -> bool: )
|
Please fix the title wrapping |
7e08d10
to
e483769
Compare
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.
LGTM modulo a minor suggestion
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.
LGTM, except the black formatter failing.
Could we replace |
Quite often it's not helpful. On Clang side it's not helpful at all. |
Test @Endilll |
This is the only way that I know of to subscribe someone to a pull request. However, I've tested this out and people only get notifications for the first edit that mentions a team they are on. So if you have already been mentioned and another team gets mentioned, you won't see a notification for that. |
@tstellar the issue is that people get mentioned twice because of the content of details, not because of the intentional @llvm/ mention. I'm working on fixing that |
diff_stats += "</pre>" | ||
team_mention = "@llvm/{}".format(team.slug) | ||
|
||
body = self.pr.body |
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.
body = self.pr.body | |
body = self.pr.body.replace('@', '@<!-- -->') |
From github/markup#1168
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.
As discussed on Discord, I don't think this is an issue for pull requests.
@llvm/pr-subscribers-github-workflow ChangesThis 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. -- Full diff: https://github.com//pull/66037.diff2 Files Affected:
diff --git a/.github/workflows/pr-subscriber.yml b/.github/workflows/pr-subscriber.yml index 3b18c8b35e97d1a..60c884cb172c2a2 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 potential 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..cbad9bd829beffb 100755 --- a/llvm/utils/git/github-automation.py +++ b/llvm/utils/git/github-automation.py @@ -10,6 +10,7 @@ import argparse from git import Repo # type: ignore +import html import github import os import re @@ -95,6 +96,13 @@ 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 self.COMMENT_TAG in comment.body: + return comment + return None def run(self) -> bool: patch = None @@ -129,22 +137,35 @@ def run(self) -> bool: patch_link = f"Full diff: {self.pr.diff_url}\n" if len(patch) > DIFF_LIMIT: 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 = html.escape(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) - + "\n\n<details>\n" - + f"<summary>Changes</summary>\n\n" - + f"{body}\n--\n" - + patch_link - + "\n" - + f"{diff_stats}\n\n" - + "</details>" - ) + comment = f""" +{self.COMMENT_TAG} +{team_mention} + +<details> +<summary>Changes</summary> +{body} +-- +{patch_link} +{diff_stats} +</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]: |
@cor3ntin Thanks for the feedback, this looks really good now. I'll push this later today if there are no other comments. |
Thanks, lgtm! |
…uests 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.
b6a7841
to
512a646
Compare
…uests (llvm#66037) 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.
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.