Merge ~emmabrostrom/ols-jenkaas:pre-merge-bot-comment into ols-jenkaas:main

Proposed by Emma Brostrom
Status: Merged
Merged at revision: e4af68030bff5e64c5ed652e719681e248ce7321
Proposed branch: ~emmabrostrom/ols-jenkaas:pre-merge-bot-comment
Merge into: ols-jenkaas:main
Diff against target: 43 lines (+14/-7)
1 file modified
olsjenkaas/commands.py (+14/-7)
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini Approve
Review via email: mp+464341@code.launchpad.net

Commit message

Re-introduce pre-merge refactor to exclude certain bot comments

The command was only looking at the most recent bot comment, regardless
of if it had to do with pre-merge CI, which this update fixes. Additionally,
refactored the function a bit to enhance readability and ease of list
comprehension. Update here to fix the issue with spamming bot comments when
tests failing also made - swapped out indexing for a more rigorous regex approach
when getting most recent bot comment commit hash.

Description of the change

Nearly identical to MP: https://code.launchpad.net/~emmabrostrom/ols-jenkaas/+git/ols-jenkaas/+merge/464033
Which was reverted here: https://code.launchpad.net/~emmabrostrom/ols-jenkaas/+git/ols-jenkaas/+merge/464146

Tested in ols-jenkaas VM on both failing and succeeding comments.

To post a comment you must log in.
Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/olsjenkaas/commands.py b/olsjenkaas/commands.py
2index 9db0a23..971843a 100644
3--- a/olsjenkaas/commands.py
4+++ b/olsjenkaas/commands.py
5@@ -814,24 +814,31 @@ class PreMergeGitProposals(Command):
6 last_diffs_collection_index
7 ].source_revision_id
8 return most_recent_commit
9+
10+ @staticmethod
11+ def is_pre_merge_ci_comment_match(comment_body):
12+ matches = re.findall(
13+ r".*[pre-merge ci\w].*revision [0-9a-z]{40}",
14+ comment_body,
15+ )
16+ return bool(matches)
17
18 @staticmethod
19 def get_most_recent_commit_seen_by_bot(proposal):
20 comment_collection = proposal.all_comments
21 bot_author_link = "https://api.launchpad.net/devel/~otto-copilot"
22 bot_comments = [
23- comment
24+ comment.message_body
25 for comment in comment_collection
26 if comment.author_link == bot_author_link
27+ and PreMergeGitProposals.is_pre_merge_ci_comment_match(comment.message_body)
28 ]
29 try:
30 most_recent_bot_comment = bot_comments[-1]
31- # Find revision number in last bot comment
32- matches = re.findall(
33- r".*[pre-merge ci\w].*revision [0-9a-z]{40}",
34- most_recent_bot_comment.message_body,
35- )
36- commit_hash = str(matches[0]).split()[-1]
37+ commit_hash = re.findall(
38+ r"[0-9a-z]{40}",
39+ most_recent_bot_comment,
40+ )[0]
41 return commit_hash
42 # If no bot comment or revision number found
43 except IndexError:

Subscribers

People subscribed via source and target branches