From 15179550e639dd89ad35e6076e37877c8379d498 Mon Sep 17 00:00:00 2001 From: Mariatta Date: Fri, 8 Sep 2023 13:29:28 -0700 Subject: [PATCH] Only comment about new commits if the PR is still open. --- bedevere/stage.py | 18 ++++++++++-------- tests/test_stage.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/bedevere/stage.py b/bedevere/stage.py index f3914d9b..a1afda2a 100644 --- a/bedevere/stage.py +++ b/bedevere/stage.py @@ -147,14 +147,16 @@ async def new_commit_pushed(event, gh, *arg, **kwargs): # get the latest commit hash commit_hash = commits[-1]["id"] pr = await util.get_pr_for_commit(gh, commit_hash) - for label in util.labels(pr): - if label == "awaiting merge": - issue = await util.issue_for_PR(gh, pr) - greeting = "There's a new commit after the PR has been approved." - await request_core_review( - gh, issue, blocker=Blocker.core_review, greeting=greeting - ) - break + if pr["state"] != "closed": + # only process the event if PR is still open + for label in util.labels(pr): + if label == "awaiting merge": + issue = await util.issue_for_PR(gh, pr) + greeting = "There's a new commit after the PR has been approved." + await request_core_review( + gh, issue, blocker=Blocker.core_review, greeting=greeting + ) + break async def core_dev_reviewers(gh, pull_request_url): diff --git a/tests/test_stage.py b/tests/test_stage.py index 39cc449d..e8b770c0 100644 --- a/tests/test_stage.py +++ b/tests/test_stage.py @@ -1123,6 +1123,7 @@ async def test_new_commit_pushed_to_approved_pr(issue_url_key): ], # the key could be 'url' or 'issue_url' issue_url_key: "/repos/python/cpython/issues/5547", + "state": "open", } ], }, @@ -1193,6 +1194,7 @@ async def test_new_commit_pushed_to_not_approved_pr(issue_url_key): ], # issue_url_key: "/repos/python/cpython/issues/5547", + "state": "open", } ], }, @@ -1214,3 +1216,39 @@ async def test_pushed_without_commits(): # no posts assert len(gh.post_) == 0 + + +@pytest.mark.parametrize("issue_url_key", ["url", "issue_url"]) +async def test_new_commit_pushed_to_closed_pr(issue_url_key): + # There is new commit on approved PR + sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" + data = {"commits": [{"id": sha}]} + event = sansio.Event(data, event="push", delivery_id="12345") + items = { + f"https://api.github.com/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { + "total_count": 1, + "items": [ + { + "number": 5547, + "title": "[3.6] bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)", + "body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta ", + "labels": [ + { + "name": "CLA signed", + }, + { + "name": "awaiting review", + }, + ], + # + issue_url_key: "/repos/python/cpython/issues/5547", + "state": "closed", + } + ], + }, + } + gh = FakeGH(getitem=items) + await awaiting.router.dispatch(event, gh) + + # no posts + assert len(gh.post_) == 0 \ No newline at end of file