Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @mscbot commands in PR review bodies #26

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ On github:
1. Come up with and set a secret (hint: use the `uuid` terminal command)
1. Under events, select "Let me select individual events". Only the following need to be checked:
- Issue comments
- Pull request reviews
- Pull request review comments

On your server:
Expand Down
24 changes: 18 additions & 6 deletions command_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,25 @@ def __init__(self, config: Config, store: Storage, repo: Repository):
# Set up FCP timer handler, and callback functions
self.fcp_timers = FCPTimers(store, self._on_fcp_timer_fired)

def handle_comment(self, comment: Dict):
def handle_comment(self, comment: Dict) -> None:
# If this is a pull request review (not a comment or a comment in a review) then
# the field containing comment text etc. will be "review" instead of "comment"
if "comment" in comment:
comment_fields = comment["comment"]
elif "review" in comment:
comment_fields = comment["review"]
else:
log.debug("Unrecognised structure of comment. Ignoring.")
return

# Extract the comment's text
comment_text = comment_fields["body"]

# Replace any instances of \r\n with just \n
comment["comment"]["body"] = comment["comment"]["body"].replace("\r\n", "\n")
comment_text = comment_text.replace("\r\n", "\n")

# Check for any commands
commands = self.parse_commands_from_text(comment["comment"]["body"])
commands = self.parse_commands_from_text(comment_text)

# Retrieve the issue this comment is attached to
# Account for issue and pull request review comments
Expand All @@ -68,10 +81,9 @@ def handle_comment(self, comment: Dict):
original_labels = self.proposal_labels_str.copy()

self.comment = comment
self.comment_link = comment["comment"]["html_url"]
self.comment_link = comment_fields["html_url"]

# Check if this is a new comment or an edit
comment_body = self.comment["comment"]["body"]
if comment["action"] == "edited":
# Check if this is an edit of a status comment
known_status_comment = self._get_status_comment()
Expand All @@ -83,7 +95,7 @@ def handle_comment(self, comment: Dict):
return

# Process status comment update
self._process_status_comment_update_with_body(comment_body)
self._process_status_comment_update_with_body(comment_text)
else:
# Run command functions
for command in commands:
Expand Down
5 changes: 5 additions & 0 deletions webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def on_issue_comment(data):
log.debug(f"Got comment: {json.dumps(data, indent=4, sort_keys=True)}")
self._process_comment(data)

@webhook.hook("pull_request_review")
def on_pull_request_review(data):
log.debug(f"Got PR review: {json.dumps(data, indent=4, sort_keys=True)}")
self._process_comment(data)

@webhook.hook("pull_request_review_comment")
def on_pull_request_review_comment(data):
log.debug(
Expand Down