diff --git a/miss_islington/status_change.py b/miss_islington/status_change.py index 42b9464456844b7..21d966fe9c9a680 100644 --- a/miss_islington/status_change.py +++ b/miss_islington/status_change.py @@ -22,13 +22,11 @@ async def check_status(event, gh, *args, **kwargs): await check_ci_status_and_approval(gh, sha, leave_comment=True) -@router.register("pull_request_review", action="submitted") +@router.register("pull_request", action="labeled") async def pr_reviewed(event, gh, *args, **kwargs): if event.data["pull_request"]["user"]["login"] == "miss-islington": - reviewer = event.data["review"]["user"]["login"] - approved = event.data["review"]["state"] == "approved" - if approved and await util.is_core_dev(gh, reviewer): - sha = event.data["review"]["commit_id"] + if util.pr_is_awaiting_merge(event.data["pull_request"]["labels"]): + sha = event.data["pull_request"]["head"]["sha"] await check_ci_status_and_approval(gh, sha) @@ -75,14 +73,12 @@ async def check_ci_status_and_approval(gh, sha, leave_comment=False): ) if result["state"] == "success": - async for review in gh.getiter( - f"/repos/python/cpython/pulls/{pr_number}/reviews" - ): - reviewer = review["user"]["login"] - approved = review["state"].lower() == "approved" - if approved and await util.is_core_dev(gh, reviewer): - await merge_pr(gh, pr_number, sha) - break + pr = await gh.getitem( + f"/repos/python/cpython/pulls/{pr_number}" + ) + if util.pr_is_awaiting_merge(pr["labels"]): + await merge_pr(gh, pr_number, sha) + break async def merge_pr(gh, pr_number, sha): diff --git a/miss_islington/util.py b/miss_islington/util.py index 70275cc66cc93cd..6fd07c6f1eb1733 100644 --- a/miss_islington/util.py +++ b/miss_islington/util.py @@ -104,3 +104,10 @@ async def is_core_dev(gh, username): raise else: return True + + +def pr_is_awaiting_merge(pr_labels): + for label in pr_labels: + if label["name"] == "awaiting merge": + return True + return False diff --git a/tests/test_delete_branch.py b/tests/test_delete_branch.py index c55f91ddb99354e..7b7a48936553619 100644 --- a/tests/test_delete_branch.py +++ b/tests/test_delete_branch.py @@ -7,10 +7,6 @@ class FakeGH: def __init__(self): self.post_data = None - async def post(self, url, *, data): - self.post_url = url - self.post_data = data - async def delete(self, url): self.delete_url = url diff --git a/tests/test_status_change.py b/tests/test_status_change.py index 4493f9dd170ccba..7b80afa43b22f08 100644 --- a/tests/test_status_change.py +++ b/tests/test_status_change.py @@ -18,10 +18,7 @@ def __init__(self, *, getitem=None, getiter=None, put=None): async def getitem(self, url): self.getitem_url = url to_return = self._getitem_return[self.getitem_url] - if isinstance(to_return, Exception): - raise to_return - else: - return to_return + return to_return async def getiter(self, url): self.getiter_url = url @@ -40,7 +37,7 @@ async def post(self, url, *, data): return self._post_return -async def test_ci_passed_with_one_core_dev_review_pr_is_merged(): +async def test_ci_passed_with_awaiting_merge_label_pr_is_merged(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = {"sha": sha, "commit": {"committer": {"login": "miss-islington"}}} event = sansio.Event(data, event="status", delivery_id="1") @@ -66,7 +63,7 @@ async def test_ci_passed_with_one_core_dev_review_pr_is_merged(): "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": True, + "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, } getiter = { @@ -88,9 +85,6 @@ async def test_ci_passed_with_one_core_dev_review_pr_is_merged(): "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 ", } ], - "/repos/python/cpython/pulls/5547/reviews": [ - {"user": {"login": "Mariatta"}, "state": "APPROVED"} - ], "/repos/python/cpython/pulls/5547/commits": [ { "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", @@ -99,7 +93,6 @@ async def test_ci_passed_with_one_core_dev_review_pr_is_merged(): }, } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -113,7 +106,7 @@ async def test_ci_passed_with_one_core_dev_review_pr_is_merged(): ) -async def test_ci_passed_with_no_core_dev_review_pr_is_not_merged(): +async def test_ci_passed_with_no_awaiting_merge_label_pr_is_not_merged(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = {"sha": sha, "commit": {"committer": {"login": "miss-islington"}}} event = sansio.Event(data, event="status", delivery_id="1") @@ -139,7 +132,9 @@ async def test_ci_passed_with_no_core_dev_review_pr_is_not_merged(): "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": True, + "/repos/python/cpython/pulls/5547": { + "labels": [{"name": "awaiting core review"}] + }, } getiter = { @@ -161,7 +156,6 @@ async def test_ci_passed_with_no_core_dev_review_pr_is_not_merged(): "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 ", } ], - "/repos/python/cpython/pulls/5547/reviews": [], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -170,7 +164,7 @@ async def test_ci_passed_with_no_core_dev_review_pr_is_not_merged(): assert not hasattr(gh, "put_data") # is not merged -async def test_ci_not_passed_with_core_dev_review_pr_is_not_merged(): +async def test_ci_not_passed_awaiting_merge_label_pr_is_not_merged(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = {"sha": sha, "commit": {"committer": {"login": "miss-islington"}}} event = sansio.Event(data, event="status", delivery_id="1") @@ -196,7 +190,7 @@ async def test_ci_not_passed_with_core_dev_review_pr_is_not_merged(): "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": True, + "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, } getiter = { @@ -218,7 +212,6 @@ async def test_ci_not_passed_with_core_dev_review_pr_is_not_merged(): "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 ", } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -227,19 +220,18 @@ async def test_ci_not_passed_with_core_dev_review_pr_is_not_merged(): assert not hasattr(gh, "put_data") # is not merged -async def test_pr_reviewed_webhook_ci_passed_pr_is_merged(): +async def test_awaiting_merge_label_added_and_ci_passed_pr_is_merged(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = { - "action": "submitted", - "pull_request": {"user": {"login": "miss-islington"}}, - "review": { - "commit_id": sha, - "user": {"login": "Mariatta"}, - "state": "approved", + "action": "labeled", + "pull_request": { + "user": {"login": "miss-islington"}, + "labels": [{"name": "awaiting merge"}], + "head": {"sha": sha}, }, } - event = sansio.Event(data, event="pull_request_review", delivery_id="1") + event = sansio.Event(data, event="pull_request", delivery_id="1") getitem = { f"/repos/python/cpython/commits/{sha}/status": { @@ -258,7 +250,7 @@ async def test_pr_reviewed_webhook_ci_passed_pr_is_merged(): }, ], }, - "/teams/42/memberships/Mariatta": True, + "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, } getiter = { @@ -280,10 +272,6 @@ async def test_pr_reviewed_webhook_ci_passed_pr_is_merged(): "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 ", } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], - "/repos/python/cpython/pulls/5547/reviews": [ - {"user": {"login": "Mariatta"}, "state": "APPROVED"} - ], "/repos/python/cpython/pulls/5547/commits": [ { "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", @@ -305,19 +293,18 @@ async def test_pr_reviewed_webhook_ci_passed_pr_is_merged(): ) -async def test_pr_reviewed_webhook_ci_failure_pr_is_not_merged(): +async def test_awaiting_merge_webhook_ci_failure_pr_is_not_merged(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = { - "action": "submitted", - "pull_request": {"user": {"login": "miss-islington"}}, - "review": { - "commit_id": sha, - "user": {"login": "Mariatta"}, - "state": "approved", + "action": "labeled", + "pull_request": { + "user": {"login": "miss-islington"}, + "labels": [{"name": "awaiting merge"}], + "head": {"sha": sha}, }, } - event = sansio.Event(data, event="pull_request_review", delivery_id="1") + event = sansio.Event(data, event="pull_request", delivery_id="1") getitem = { f"/repos/python/cpython/commits/{sha}/status": { @@ -336,7 +323,7 @@ async def test_pr_reviewed_webhook_ci_failure_pr_is_not_merged(): }, ], }, - "/teams/42/memberships/Mariatta": True, + "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, } getiter = { @@ -358,7 +345,6 @@ async def test_pr_reviewed_webhook_ci_failure_pr_is_not_merged(): "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 ", } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -367,19 +353,18 @@ async def test_pr_reviewed_webhook_ci_failure_pr_is_not_merged(): assert not hasattr(gh, "put_data") # is not merged -async def test_pr_reviewed_changes_requested_pr_is_not_merged(): +async def test_awaiting_core_review_label_added_is_not_merged(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = { - "action": "submitted", - "pull_request": {"user": {"login": "miss-islington"}}, - "review": { - "commit_id": sha, - "user": {"login": "Mariatta"}, - "state": "changes_requested", + "action": "labeled", + "pull_request": { + "user": {"login": "miss-islington"}, + "labels": [{"name": "awaiting merge"}], + "head": {"sha": sha}, }, } - event = sansio.Event(data, event="pull_request_review", delivery_id="1") + event = sansio.Event(data, event="pull_request", delivery_id="1") getitem = { f"/repos/python/cpython/commits/{sha}/status": { @@ -400,7 +385,26 @@ async def test_pr_reviewed_changes_requested_pr_is_not_merged(): } } - getiter = {"/orgs/python/teams": [{"name": "Python core", "id": 42}]} + getiter = { + "/repos/miss-islington/cpython/git/refs/heads/": [ + {"ref": f"refs/heads/backport-{sha[0:7]}-3.6", "object": {"sha": sha}}, + { + "ref": "refs/heads/backport-63ae044-3.6", + "object": { + "sha": "67a2b0b7713e40dea7762b7d7764ae18fe967561", + "type": "commit", + "url": "https://api.github.com/repos/miss-islington/cpython/git/commits/67a2b0b7713e40dea7762b7d7764ae18fe967561", + }, + }, + ], + f"/repos/python/cpython/pulls?state=open&head=miss-islington:backport-{sha[0:7]}-3.6": [ + { + "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 ", + } + ], + } gh = FakeGH(getitem=getitem, getiter=getiter) await status_change.router.dispatch(event, gh) @@ -408,19 +412,18 @@ async def test_pr_reviewed_changes_requested_pr_is_not_merged(): assert not hasattr(gh, "put_data") # is not merged -async def test_pr_reviewed_ignore_non_miss_islingtons_pr(): +async def test_awaiting_merge_label_ignore_non_miss_islingtons_pr(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = { - "action": "submitted", - "pull_request": {"user": {"login": "Mariatta"}}, - "review": { - "commit_id": sha, + "action": "labeled", + "pull_request": { "user": {"login": "Mariatta"}, - "state": "approved", + "labels": [{"name": "awaiting merge"}], + "head": {"sha": sha}, }, } - event = sansio.Event(data, event="pull_request_review", delivery_id="1") + event = sansio.Event(data, event="pull_request", delivery_id="1") getitem = { f"/repos/python/cpython/commits/{sha}/status": { @@ -441,15 +444,13 @@ async def test_pr_reviewed_ignore_non_miss_islingtons_pr(): } } - getiter = {"/orgs/python/teams": [{"name": "Python core", "id": 42}]} - - gh = FakeGH(getitem=getitem, getiter=getiter) + gh = FakeGH(getitem=getitem) # , getiter=getiter) await status_change.router.dispatch(event, gh) assert not hasattr(gh, "post_data") # does not leave a comment assert not hasattr(gh, "put_data") # is not merged -async def test_ci_passed_with_one_core_dev_review_pr_is_merged_not_miss_islington(): +async def test_ci_passed_with_awaiting_merge_label_not_miss_islington_is_not_merged(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = {"sha": sha, "commit": {"committer": {"login": "Mariatta"}}} event = sansio.Event(data, event="status", delivery_id="1") @@ -475,7 +476,7 @@ async def test_ci_passed_with_one_core_dev_review_pr_is_merged_not_miss_islingto "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": True, + "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, } getiter = { @@ -497,9 +498,6 @@ async def test_ci_passed_with_one_core_dev_review_pr_is_merged_not_miss_islingto "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 ", } ], - "/repos/python/cpython/pulls/5547/reviews": [ - {"user": {"login": "Mariatta"}, "state": "APPROVED"} - ], "/repos/python/cpython/pulls/5547/commits": [ { "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", @@ -508,7 +506,6 @@ async def test_ci_passed_with_one_core_dev_review_pr_is_merged_not_miss_islingto }, } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -543,7 +540,6 @@ async def test_ci_pending(): "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": True, } getiter = { @@ -565,9 +561,6 @@ async def test_ci_pending(): "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 ", } ], - "/repos/python/cpython/pulls/5547/reviews": [ - {"user": {"login": "Mariatta"}, "state": "APPROVED"} - ], "/repos/python/cpython/pulls/5547/commits": [ { "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", @@ -576,7 +569,6 @@ async def test_ci_pending(): }, } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -605,7 +597,6 @@ async def test_travis_not_done(): "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": True, } getiter = { @@ -627,9 +618,6 @@ async def test_travis_not_done(): "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 ", } ], - "/repos/python/cpython/pulls/5547/reviews": [ - {"user": {"login": "Mariatta"}, "state": "APPROVED"} - ], "/repos/python/cpython/pulls/5547/commits": [ { "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", @@ -638,7 +626,6 @@ async def test_travis_not_done(): }, } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -673,7 +660,6 @@ async def test_pr_title_does_not_match(): "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": True, } getiter = { @@ -695,9 +681,6 @@ async def test_pr_title_does_not_match(): "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 ", } ], - "/repos/python/cpython/pulls/5547/reviews": [ - {"user": {"login": "Mariatta"}, "state": "APPROVED"} - ], "/repos/python/cpython/pulls/5547/commits": [ { "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", @@ -706,7 +689,6 @@ async def test_pr_title_does_not_match(): }, } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -715,7 +697,7 @@ async def test_pr_title_does_not_match(): assert not hasattr(gh, "put_data") # is not merged -async def test_ci_passed_approved_by_non_core_dev_review_pr_is_not_merged(): +async def test_ci_passed_awaiting_core_review_is_not_merged(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" data = {"sha": sha, "commit": {"committer": {"login": "miss-islington"}}} event = sansio.Event(data, event="status", delivery_id="1") @@ -741,11 +723,10 @@ async def test_ci_passed_approved_by_non_core_dev_review_pr_is_not_merged(): "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": gidgethub.BadRequest( - status_code=http.HTTPStatus(404) - ), + "/repos/python/cpython/pulls/5547": { + "labels": [{"name": "awaiting core review"}] + }, } - getiter = { "/repos/miss-islington/cpython/git/refs/heads/": [ {"ref": f"refs/heads/backport-{sha[0:7]}-3.6", "object": {"sha": sha}}, @@ -765,18 +746,69 @@ async def test_ci_passed_approved_by_non_core_dev_review_pr_is_not_merged(): "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 ", } ], - "/repos/python/cpython/pulls/5547/reviews": [ - {"user": {"login": "Mariatta"}, "state": "APPROVED"} + } + + gh = FakeGH(getitem=getitem, getiter=getiter) + await status_change.router.dispatch(event, gh) + assert not hasattr(gh, "put_data") # is not merged + + +async def test_branch_sha_not_matched_pr_not_merged(): + sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" + data = {"sha": sha, "commit": {"committer": {"login": "miss-islington"}}} + event = sansio.Event(data, event="status", delivery_id="1") + + getitem = { + f"/repos/python/cpython/commits/{sha}/status": { + "state": "success", + "statuses": [ + { + "state": "success", + "description": "Issue report skipped", + "context": "bedevere/issue-number", + }, + { + "state": "success", + "description": "The Travis CI build passed", + "target_url": "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification", + "context": "continuous-integration/travis-ci/pr", + }, + ], + }, + "/repos/python/cpython/pulls/5544": { + "user": {"login": "miss-islington"}, + "merged_by": {"login": "Mariatta"}, + }, + "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, + } + + getiter = { + "/repos/miss-islington/cpython/git/refs/heads/": [ + {"ref": f"refs/heads/backport-{sha[0:7]}-3.6", "object": {"sha": sha}}, + { + "ref": "refs/heads/backport-63ae044-3.6", + "object": { + "sha": "67a2b0b7713e40dea7762b7d7764ae18fe967561", + "type": "commit", + "url": "https://api.github.com/repos/miss-islington/cpython/git/commits/67a2b0b7713e40dea7762b7d7764ae18fe967561", + }, + }, + ], + f"/repos/python/cpython/pulls?state=open&head=miss-islington:backport-{sha[0:7]}-3.6": [ + { + "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 ", + } ], "/repos/python/cpython/pulls/5547/commits": [ { - "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "sha": "f2393593c99dd2d3", "commit": { "message": "bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)\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 " }, } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) @@ -784,10 +816,18 @@ async def test_ci_passed_approved_by_non_core_dev_review_pr_is_not_merged(): assert not hasattr(gh, "put_data") # is not merged -async def test_branch_sha_not_matched_pr_not_merged(): +async def test_awaiting_merge_label_added_not_miss_islingtons_pr(): sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = {"sha": sha, "commit": {"committer": {"login": "miss-islington"}}} - event = sansio.Event(data, event="status", delivery_id="1") + data = { + "action": "labeled", + "pull_request": { + "user": {"login": "Mariatta"}, + "labels": [{"name": "awaiting merge"}], + "head": {"sha": sha}, + }, + } + + event = sansio.Event(data, event="pull_request", delivery_id="1") getitem = { f"/repos/python/cpython/commits/{sha}/status": { @@ -810,7 +850,7 @@ async def test_branch_sha_not_matched_pr_not_merged(): "user": {"login": "miss-islington"}, "merged_by": {"login": "Mariatta"}, }, - "/teams/42/memberships/Mariatta": True, + "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, } getiter = { @@ -832,8 +872,78 @@ async def test_branch_sha_not_matched_pr_not_merged(): "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 ", } ], - "/repos/python/cpython/pulls/5547/reviews": [ - {"user": {"login": "Mariatta"}, "state": "APPROVED"} + "/repos/python/cpython/pulls/5547/commits": [ + { + "sha": "f2393593c99dd2d3", + "commit": { + "message": "bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)\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 " + }, + } + ], + } + + gh = FakeGH(getitem=getitem, getiter=getiter) + await status_change.router.dispatch(event, gh) + assert not hasattr(gh, "put_data") # is not merged + + +async def test_awaiting_core_review_label_added_miss_islingtons_pr(): + sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" + data = { + "action": "labeled", + "pull_request": { + "user": {"login": "miss-islington"}, + "labels": [{"name": "awaiting core review"}], + "head": {"sha": sha}, + }, + } + + event = sansio.Event(data, event="pull_request", delivery_id="1") + + getitem = { + f"/repos/python/cpython/commits/{sha}/status": { + "state": "success", + "statuses": [ + { + "state": "success", + "description": "Issue report skipped", + "context": "bedevere/issue-number", + }, + { + "state": "success", + "description": "The Travis CI build passed", + "target_url": "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification", + "context": "continuous-integration/travis-ci/pr", + }, + ], + }, + "/repos/python/cpython/pulls/5544": { + "user": {"login": "miss-islington"}, + "merged_by": {"login": "Mariatta"}, + }, + "/repos/python/cpython/pulls/5547": { + "labels": [{"name": "awaiting core review"}] + }, + } + + getiter = { + "/repos/miss-islington/cpython/git/refs/heads/": [ + {"ref": f"refs/heads/backport-{sha[0:7]}-3.6", "object": {"sha": sha}}, + { + "ref": "refs/heads/backport-63ae044-3.6", + "object": { + "sha": "67a2b0b7713e40dea7762b7d7764ae18fe967561", + "type": "commit", + "url": "https://api.github.com/repos/miss-islington/cpython/git/commits/67a2b0b7713e40dea7762b7d7764ae18fe967561", + }, + }, + ], + f"/repos/python/cpython/pulls?state=open&head=miss-islington:backport-{sha[0:7]}-3.6": [ + { + "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 ", + } ], "/repos/python/cpython/pulls/5547/commits": [ { @@ -843,7 +953,6 @@ async def test_branch_sha_not_matched_pr_not_merged(): }, } ], - "/orgs/python/teams": [{"name": "Python core", "id": 42}], } gh = FakeGH(getitem=getitem, getiter=getiter) diff --git a/tests/test_util.py b/tests/test_util.py index 933dc533368b9aa..3e4df30b5f4cb9a 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -31,11 +31,6 @@ async def getiter(self, url): for item in to_iterate: yield item - async def post(self, url, *, data): - self.post_url = url - self.post_data = data - return self._post_return - def test_title_normalization(): title = "abcd" @@ -118,3 +113,13 @@ async def test_is_core_dev(): gh = FakeGH(getiter={"/orgs/python/teams": teams}, getitem=getitem) with pytest.raises(gidgethub.BadRequest): await util.is_core_dev(gh, "miss-islington") + + +def test_pr_is_awaiting_merge(): + labels = [{"name": "CLA Signed"}, {"name": "awaiting merge"}] + assert util.pr_is_awaiting_merge(labels) is True + + +def test_pr_is_not_awaiting_merge(): + labels = [{"name": "CLA Signed", "name": "skip issue", "name": "awaiting review"}] + assert util.pr_is_awaiting_merge(labels) is False