[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
Wed Jan 17 03:27:28 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:

There's no great way to do that unfortunately.

The console view (https://lab.llvm.org/buildbot/#/console) is the least bad, if your change has been merged recently. Recently meaning in the last hour, right now that's the oldest change I see. Might be even shorter of a window in peak times like the US working day.

Most new contributors won't have commit access also, so it's more likely that their change gets merged while they are busy with other things.  But it's the least bad option, and if we make them aware of it they can use it later when they are able to do their own merges.

So I've added a note about the console view to the text.

The other option is the changes page e.g. https://lab.llvm.org/buildbot/#/changes/120892 however that requires you to know the Buildbot change ID for the commit, I couldn't find a way to get that from a git hash. Also, that lists all builds it's been included in, including builds that were already red (for example https://lab.llvm.org/buildbot/#/builders/272/builds/5779). Which would be more confusing than useful, even if we had a way to get from git hash to buildbot change ID.

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


More information about the llvm-commits mailing list