[llvm] [GitHub][workflows] Add buildbot information comment to first merged PR from a new contributor (PR #78292)

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 03:14:44 PST 2024


================
@@ -240,6 +244,64 @@ def run(self) -> bool:
         return True
 
 
+class PRBuildbotInformation:
+    COMMENT_TAG = "<!--LLVM BUILDBOT 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 should_comment(self) -> bool:
+        # As soon as a new contributor has a PR merged, they are no longer a new contributor.
+        # We can tell that they were a new contributor previously because we would have
+        # added a new contributor greeting comment when they opened the PR.
+        found_greeting = False
+        for comment in self.pr.as_issue().get_comments():
+            if PRGreeter.COMMENT_TAG in comment.body:
+                found_greeting = True
+            elif PRBuildbotInformation.COMMENT_TAG in comment.body:
+                # When an issue is reopened, then closed as merged again, we should not
+                # add a second comment. This event will be rare in practice as it seems
+                # like it's only possible when the main branch is still at the exact
+                # revision that the PR was merged on to, beyond that it's closed forever.
+                return False
+        return found_greeting
+
+    def run(self) -> bool:
+        if not self.should_comment():
+            return
+
+        # This text is using Markdown formatting.
+        comment = f"""\
+{PRBuildbotInformation.COMMENT_TAG}
+@{self.author} Congratulations on having your first Pull Request (PR) merged into the LLVM Project!
+
+Your changes will be combined with recent changes from other authors, then tested
+by our [build bots](https://lab.llvm.org/buildbot/#/console).
+
+If there is a problem with the build, all the change authors will receive an email
----------------
DavidSpickett wrote:

This runs on merged PRs, so it might be possible to go from git hash -> GitHub -> buildbot statuses -> change ID and make a customised link to go in the comment. I'll look into that for a future change.

https://github.com/llvm/llvm-project/pull/78292


More information about the llvm-commits mailing list