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
diff --git a/olsjenkaas/commands.py b/olsjenkaas/commands.py
index 9db0a23..971843a 100644
--- a/olsjenkaas/commands.py
+++ b/olsjenkaas/commands.py
@@ -814,24 +814,31 @@ class PreMergeGitProposals(Command):
814 last_diffs_collection_index814 last_diffs_collection_index
815 ].source_revision_id815 ].source_revision_id
816 return most_recent_commit816 return most_recent_commit
817
818 @staticmethod
819 def is_pre_merge_ci_comment_match(comment_body):
820 matches = re.findall(
821 r".*[pre-merge ci\w].*revision [0-9a-z]{40}",
822 comment_body,
823 )
824 return bool(matches)
817825
818 @staticmethod826 @staticmethod
819 def get_most_recent_commit_seen_by_bot(proposal):827 def get_most_recent_commit_seen_by_bot(proposal):
820 comment_collection = proposal.all_comments828 comment_collection = proposal.all_comments
821 bot_author_link = "https://api.launchpad.net/devel/~otto-copilot"829 bot_author_link = "https://api.launchpad.net/devel/~otto-copilot"
822 bot_comments = [830 bot_comments = [
823 comment831 comment.message_body
824 for comment in comment_collection832 for comment in comment_collection
825 if comment.author_link == bot_author_link833 if comment.author_link == bot_author_link
834 and PreMergeGitProposals.is_pre_merge_ci_comment_match(comment.message_body)
826 ]835 ]
827 try:836 try:
828 most_recent_bot_comment = bot_comments[-1]837 most_recent_bot_comment = bot_comments[-1]
829 # Find revision number in last bot comment838 commit_hash = re.findall(
830 matches = re.findall(839 r"[0-9a-z]{40}",
831 r".*[pre-merge ci\w].*revision [0-9a-z]{40}",840 most_recent_bot_comment,
832 most_recent_bot_comment.message_body,841 )[0]
833 )
834 commit_hash = str(matches[0]).split()[-1]
835 return commit_hash842 return commit_hash
836 # If no bot comment or revision number found843 # If no bot comment or revision number found
837 except IndexError:844 except IndexError:

Subscribers

People subscribed via source and target branches