[llvm] [CI] Make premerge_advisor_explain write comments (PR #166605)
David Spickett via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 7 02:32:08 PST 2025
================
@@ -4,20 +4,83 @@
"""Script for getting explanations from the premerge advisor."""
import argparse
-import os
import platform
import sys
+import json
import requests
+import github
+import github.PullRequest
import generate_test_report_lib
PREMERGE_ADVISOR_URL = (
"http://premerge-advisor.premerge-advisor.svc.cluster.local:5000/explain"
)
+COMMENT_TAG = "<!--PREMERGE ADVISOR COMMENT: {platform}-->"
-def main(commit_sha: str, build_log_files: list[str]):
+def get_comment_id(platform: str, pr: github.PullRequest.PullRequest) -> int | None:
+ platform_comment_tag = COMMENT_TAG.format(platform=platform)
+ for comment in pr.as_issue().get_comments():
+ if platform_comment_tag in comment.body:
+ return comment.id
+ return None
+
+
+def get_comment(
+ github_token: str,
+ pr_number: int,
+ body: str,
+) -> dict[str, str]:
+ repo = github.Github(github_token).get_repo("llvm/llvm-project")
+ pr = repo.get_issue(pr_number).as_pull_request()
+ comment = {"body": body}
+ comment_id = get_comment_id(platform.system(), pr)
+ if comment_id:
+ comment["id"] = comment_id
+
+
+def main(
+ commit_sha: str,
+ build_log_files: list[str],
+ github_token: str,
+ pr_number: int,
+ return_code: int,
+):
+ """The main entrypoint for the script.
+
+ This function parses failures from files, requests information from the
+ premerge advisor, and may write a Github comment depending upon the output.
+ There are four different scenarios:
+ 1. There has never been a previous failure and the job passes - We do not
+ create a comment. We write out an empty file to the comment path so the
+ issue-write workflow knows not to create anything.
+ 2. There has never been a previous failure and the job fails - We create a
+ new comment containing the failure information and any possible premerge
+ advisor findings.
+ 3. There has been a previous failure and the job passes - We update the
+ existing comment by passing its ID anda passed message to the
----------------
DavidSpickett wrote:
"anda" -> "and a"
https://github.com/llvm/llvm-project/pull/166605
More information about the llvm-commits
mailing list