diff --git a/.github/workflows/pr-subscriber.yml b/.github/workflows/pr-subscriber.yml index 3b18c8b35e97d..60c884cb172c2 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 f732b13d97b8a..0517cac286a30 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 @@ -97,6 +98,13 @@ def __init__(self, token: str, repo: str, pr_number: int, label_name: str): self._team_name = "pr-subscribers-{}".format( label_name.replace("+", "x") ).lower() + self.COMMENT_TAG = "\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 @@ -121,7 +129,7 @@ def run(self) -> bool: # Get the diff try: - patch = requests.get(self.pr.diff_url).text + patch = html.escape(requests.get(self.pr.diff_url).text) except: patch = "" diff_stats += "\n
\n" + patch @@ -131,22 +139,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" + team_mention = "@llvm/{}".format(team.slug) body = self.pr.body - comment = ( - "@llvm/{}".format(team.slug) - + "\n\n\n" + diff_stats = html.escape(diff_stats[0:DIFF_LIMIT]) + "...\n \n" diff_stats += "