Skip to content

Commit

Permalink
Add better handling of comments and fix issue #123
Browse files Browse the repository at this point in the history
  • Loading branch information
Scriptkiddi committed Dec 28, 2024
1 parent a958d58 commit a74584c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
8 changes: 5 additions & 3 deletions nixpkgs_merge_bot/commands/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ def merge_command(issue_comment: IssueComment, settings: Settings) -> HttpRespon
issue_comment.issue_number,
pull_request.head_sha,
)
log.info(f"{issue_comment.issue_number }: Merge completed (#306934)") # Link Issue to track merges
log.info(
f"{issue_comment.issue_number }: Merge completed (#306934)"
) # Link Issue to track merges
client.create_issue_comment(
issue_comment.repo_owner,
issue_comment.repo_name,
issue_comment.issue_number,
"Merge completed (#306934)", # Link Issue to track merges
"Merge completed (#306934)", # Link Issue to track merges
)
return issue_response("merged")
except GithubClientError as e:
Expand Down Expand Up @@ -194,7 +196,7 @@ def merge_command(issue_comment: IssueComment, settings: Settings) -> HttpRespon
log.info(
f"{issue_comment.issue_number}: No merge stratgey passed, we let the user know"
)
msg = f"@{issue_comment.commenter_login} merge not permitted (#305350): \n" # Link Issue to track failed merges
msg = f"@{issue_comment.commenter_login} merge not permitted (#305350): \n" # Link Issue to track failed merges
for reason in decline_reasons:
msg += f"{reason}\n"

Expand Down
2 changes: 1 addition & 1 deletion nixpkgs_merge_bot/merging_strategies/maintainer_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def run(
allowed_users = ["r-ryantm"]
if pull_request.user_login not in allowed_users:
result = False
message = f"pr author is not r-ryantm"
message = "pr author is not r-ryantm"
decline_reasons.append(message)
log.info(f"{pull_request.number}: {message}")
else:
Expand Down
17 changes: 11 additions & 6 deletions nixpkgs_merge_bot/webhook/issue_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ def process_comment(issue: IssueComment, settings: Settings) -> HttpResponse:
)
return issue_response("ignore-action")

stripped = re.sub("(<!--.*?-->)", "", issue.text, flags=re.DOTALL)
bot_name = re.escape(settings.bot_name)
for line in stripped.split("\n"):
if re.match(rf"^@{bot_name}\s+merge$", line.strip()):
return merge_command(issue, settings)
if issue.text is not None:
stripped = re.sub("(<!--.*?-->)", "", issue.text, flags=re.DOTALL)
stripped = re.sub("(```.*?```)", "", stripped, flags=re.DOTALL)
bot_name = re.escape(settings.bot_name)
for line in stripped.split("\n"):
if re.match(rf"^@{bot_name}\s+merge$", line.strip()):
return merge_command(issue, settings)
else:
log.debug(f"{issue.issue_number}: no command was found in comment")
return issue_response("no-command")
else:
log.debug(f"{issue.issue_number}: no command was found in comment")
log.debug(f"{issue.issue_number}: comment was empty")
return issue_response("no-command")


Expand Down

0 comments on commit a74584c

Please sign in to comment.