From d308b8268b3b6a8136b066a8d1f1497750402153 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 14 Nov 2023 04:41:09 -0500 Subject: [PATCH] fix: don't comment twice when a pr is closed with comment. #277 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. --- changelog.d/20231114_044217_nedbat.rst | 3 +++ openedx_webhooks/github_views.py | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelog.d/20231114_044217_nedbat.rst diff --git a/changelog.d/20231114_044217_nedbat.rst b/changelog.d/20231114_044217_nedbat.rst new file mode 100644 index 00000000..33659c69 --- /dev/null +++ b/changelog.d/20231114_044217_nedbat.rst @@ -0,0 +1,3 @@ +.. A new scriv changelog fragment. + +- Fix: we no longer comment twice on a pull request closed with a comment. #277 diff --git a/openedx_webhooks/github_views.py b/openedx_webhooks/github_views.py index 8f6c29cf..f33042de 100644 --- a/openedx_webhooks/github_views.py +++ b/openedx_webhooks/github_views.py @@ -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 @@ -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