From d730ead6753dec7fedf9679fda62375dc314fd1d Mon Sep 17 00:00:00 2001 From: Ivan Razumov Date: Mon, 19 Aug 2024 13:54:16 +0200 Subject: [PATCH] Add cms-bot command to add metadata to issues and PRs --- jenkins-jobs/es-link-issue.py | 18 ++++++++++++++++++ process_pr.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 jenkins-jobs/es-link-issue.py diff --git a/jenkins-jobs/es-link-issue.py b/jenkins-jobs/es-link-issue.py new file mode 100644 index 00000000000..d7db3a4e50e --- /dev/null +++ b/jenkins-jobs/es-link-issue.py @@ -0,0 +1,18 @@ +import os + +import es_utils +import base64 + + +def main(): + data = os.getenv("DATA", None) + data = base64.b64decode(data.replace("@", "\n").encode()).decode() + doc = json.loads(data) + index = doc.pop("index") + doc["@timestamp"] = int(time() * 1000) + payload = json.dumps(doc) + es_utils.send_payload(index + "-failures", index, None, payload) + + +if __name__ == "__main__": + main() diff --git a/process_pr.py b/process_pr.py index bccecdddea1..09a64e4e024 100644 --- a/process_pr.py +++ b/process_pr.py @@ -135,6 +135,10 @@ def format(s, **kwds): r"^\s*(?:(?:@|)cmsbuild\s*[,]*\s+|)(?:please\s*[,]*\s+|)ignore\s+tests-rejected\s+(?:with|)([a-z -]+)$", re.I, ) +REGEX_FAILURE_METADATA = re.compile( + r"^\s*(?:(?:@|)cmsbuild\s*[,]*\s+|)(?:please\s*[,]*\s+|)(?:attach\s+|)failure-metadata\s+(.+)$", + re.I, +) REGEX_COMMITS_CACHE = re.compile(r"", re.DOTALL) REGEX_IGNORE_COMMIT_COUNT = "\+commit-count" REGEX_IGNORE_FILE_COUNT = "\+file-count" @@ -1381,6 +1385,16 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F code_check_apply_patch = True set_comment_emoji_cache(dryRun, bot_cache, comment, repository, emoji="+1") + m = REGEX_FAILURE_DATA.match(first_line) + if m and commenter in CMSSW_ISSUES_TRACKERS: + if not has_user_emoji(bot_cache, comment, repository, "+1", cmsbuild_user): + data = m[1].strip() + # b64-encode data to safely pass it as enviroment variable; replace new-lines with @ + data = base64.b64encode(data.encode()).decode().replace("\n", "@") + with open("failure-metadata.prop", "w") as f: + f.write("DATA=" + data) + set_comment_emoji_cache(dryRun, bot_cache, comment, repository, "+1", True) + selected_cats = [] if re.match("^([+]1|approve[d]?|sign|signed)$", first_line, re.I):