Skip to content

Commit

Permalink
fix: don't comment twice when a pr is closed with comment. #277
Browse files Browse the repository at this point in the history
This check (that the comment create date and the pull request closed
date are the same) might not be 100% fool-proof. If they are off by one
second, the bot will still comment twice, but that should be unlikely.
  • Loading branch information
Ned Batchelder authored and nedbat committed Nov 15, 2023
1 parent 7038484 commit f38cd66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20231114_044217_nedbat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. A new scriv changelog fragment.
- Fix: we no longer comment twice on a pull request closed with a comment. #277
13 changes: 10 additions & 3 deletions openedx_webhooks/github_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ def handle_comment_event(event):
# for our own comment events.
pass

case {
"issue": {"closed_at": closed},
"comment": {"created_at": commented},
} if closed == commented:

# This is a "Close with comment" comment. Don't do anything for the
# comment, because we'll also get a "pull request closed" event at
# the same time, and it will do whatever we need.
pass

case {"issue": {"pull_request": _}}:
# The comment is on a pull request. Re-shape the data to conform to
# a pull request reported by a pull request event, and fire
Expand All @@ -132,9 +142,6 @@ def handle_comment_event(event):
pr["hook_action"] = event["action"]
return queue_task(pull_request_changed_task, pr)

case _:
pass

return "No thanks", 202


Expand Down

0 comments on commit f38cd66

Please sign in to comment.