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

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

Commit message

Refactor pre-merge command 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.

Description of the change

This update was due to an issue realized in this MP: https://code.launchpad.net/~gravi1984/golem/+git/golem/+merge/463784
The bot recognized a previous bot comment that did not have to do with pre-merge CI
as a pre-merge CI command to search for the commit hash. There was no commit hash to be found
(as expected), but pre-merge CI was ran again as a result.

This update makes sure that only bot comments related to pre-merge CI
are parsed for their commit hash.

Tested in ols-jenkaas VM

To post a comment you must log in.
Revision history for this message
Emma Brostrom (emmabrostrom) wrote :

Particularly looking for feedback if anyone has an idea of what to do
with is_pre_merge_ci_comment_match() instead of having it be a staticmethod.
get_most_recent_commit_seen_by_bot() should be kept static, so not sure if
there is a better way to call a function within that.

Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

> Particularly looking for feedback if anyone has an idea of what to do
> with is_pre_merge_ci_comment_match() instead of having it be a staticmethod.
> get_most_recent_commit_seen_by_bot() should be kept static, so not sure if
> there is a better way to call a function within that.

LGTM +1

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..8cace19 100644
3--- a/olsjenkaas/commands.py
4+++ b/olsjenkaas/commands.py
5@@ -816,22 +816,26 @@ class PreMergeGitProposals(Command):
6 return most_recent_commit
7
8 @staticmethod
9+ def is_pre_merge_ci_comment_match(comment_body):
10+ matches = re.findall(
11+ r".*[pre-merge ci\w].*revision [0-9a-z]{40}",
12+ comment_body,
13+ )
14+ return bool(matches)
15+
16+ @staticmethod
17 def get_most_recent_commit_seen_by_bot(proposal):
18 comment_collection = proposal.all_comments
19 bot_author_link = "https://api.launchpad.net/devel/~otto-copilot"
20 bot_comments = [
21- comment
22+ comment.message_body
23 for comment in comment_collection
24 if comment.author_link == bot_author_link
25+ and PreMergeGitProposals.is_pre_merge_ci_comment_match(comment.message_body)
26 ]
27 try:
28 most_recent_bot_comment = bot_comments[-1]
29- # Find revision number in last bot comment
30- matches = re.findall(
31- r".*[pre-merge ci\w].*revision [0-9a-z]{40}",
32- most_recent_bot_comment.message_body,
33- )
34- commit_hash = str(matches[0]).split()[-1]
35+ commit_hash = most_recent_bot_comment.split()[-1]
36 return commit_hash
37 # If no bot comment or revision number found
38 except IndexError:

Subscribers

People subscribed via source and target branches