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

Only comment about new commits if the PR is still open. #583

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions bedevere/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Comment on lines +152 to +153
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be replaced by an if 'awaiting merge' in utils.labels(pr):, and possibly combined with the previous if?

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):
Expand Down
38 changes: 38 additions & 0 deletions tests/test_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
],
},
Expand Down Expand Up @@ -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",
}
],
},
Expand All @@ -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 <[email protected]>",
"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