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

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 23:59:39 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
----------------
boomanaiden154 wrote:

I prefer the last changes page (https://lab.llvm.org/buildbot/#/changes) over the console, but it does have the same issue (limited to the last 50 changes). The current rendition for this LGTM though.

I think you can get the buildbot ID by checking the CI status on Github on the commit in `main` as the buildbot statuses get reported there and link to the individual builders. Not super trivial though and having directions on copying around IDs just doesn't seem helpful.

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


More information about the llvm-commits mailing list