From bb13588260189046d3b44bc30435ed05e14c3bdb Mon Sep 17 00:00:00 2001 From: Mariatta Date: Sat, 17 Feb 2018 19:29:45 -0800 Subject: [PATCH] Write more tests and improve coverage (GH-59) --- .travis.yml | 7 +- {backport => miss_islington}/__main__.py | 0 {backport => miss_islington}/backport_pr.py | 2 +- {backport => miss_islington}/delete_branch.py | 7 +- {backport => miss_islington}/status_change.py | 12 +- {backport => miss_islington}/tasks.py | 0 {backport => miss_islington}/util.py | 27 +- tests/test_delete_branch.py | 145 +++++ tests/test_status_change.py | 499 +++++++++++++++++- tests/test_util.py | 3 +- 10 files changed, 667 insertions(+), 35 deletions(-) rename {backport => miss_islington}/__main__.py (100%) rename {backport => miss_islington}/backport_pr.py (97%) rename {backport => miss_islington}/delete_branch.py (72%) rename {backport => miss_islington}/status_change.py (92%) rename {backport => miss_islington}/tasks.py (100%) rename {backport => miss_islington}/util.py (81%) create mode 100644 tests/test_delete_branch.py diff --git a/.travis.yml b/.travis.yml index 02f4b325087d66a..380b764e87519c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,11 @@ python: # - 3.7-dev # - nightly +before_install: + - python3 -m pip install coverage install: - python3 -m pip install -U -r dev-requirements.txt script: - - python3 -m pytest tests/ - + - python3 -m coverage run --branch -m pytest tests/ +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/backport/__main__.py b/miss_islington/__main__.py similarity index 100% rename from backport/__main__.py rename to miss_islington/__main__.py diff --git a/backport/backport_pr.py b/miss_islington/backport_pr.py similarity index 97% rename from backport/backport_pr.py rename to miss_islington/backport_pr.py index ed1ca5cead39441..e8bfee87c1112b4 100644 --- a/backport/backport_pr.py +++ b/miss_islington/backport_pr.py @@ -44,7 +44,7 @@ async def backport_pr(event, gh, *args, **kwargs): message = f"{thanks_to}. I'm working now to backport this PR to: {', '.join(branches)}."\ f"\nšŸšŸ’ā›šŸ¤– {easter_egg}" - util.comment_on_pr(issue_number, message) + await util.leave_comment(gh, issue_number, message) sorted_branches = sorted(branches, reverse=True, diff --git a/backport/delete_branch.py b/miss_islington/delete_branch.py similarity index 72% rename from backport/delete_branch.py rename to miss_islington/delete_branch.py index ac168ea34a33f77..2bc523aa4458f32 100644 --- a/backport/delete_branch.py +++ b/miss_islington/delete_branch.py @@ -16,10 +16,11 @@ async def delete_branch(event, gh, *args, **kwargs): issue_number = event.data['pull_request']['number'] merged_by = event.data['pull_request']['merged_by']['login'] if merged_by != "miss-islington": - util.comment_on_pr(issue_number, f"Thanks, @{merged_by}!") + await util.leave_comment(gh, issue_number, f"Thanks, @{merged_by}!") else: - util.comment_on_pr(issue_number, "Thanks!") + await util.leave_comment(gh, issue_number, "Thanks!") branch_name = event.data['pull_request']['head']['ref'] - util.delete_branch(branch_name) + url = f"/repos/miss-islington/cpython/git/refs/heads/{branch_name}" + await gh.delete(url) diff --git a/backport/status_change.py b/miss_islington/status_change.py similarity index 92% rename from backport/status_change.py rename to miss_islington/status_change.py index 99cdd66172c8993..ffef405b6c4f60a 100644 --- a/backport/status_change.py +++ b/miss_islington/status_change.py @@ -61,7 +61,7 @@ async def check_ci_status_and_approval(gh, sha, leave_comment=False): pr_author, committer) emoji = "āœ…" if result['state'] == "success" else "āŒ" - await comment_on_pr(gh, + await util.leave_comment(gh, pr_number=pr_number, message=f"{participants}: Backport status check is done, and it's a {result['state']} {emoji} .") @@ -91,12 +91,4 @@ async def merge_pr(gh, pr_number, sha): break -async def comment_on_pr(gh, pr_number, message): - """ - Leave a comment on a PR/Issue - """ - issue_comment_url = f"/repos/python/cpython/issues/{pr_number}/comments" - data = { - "body": message, - } - await gh.post(issue_comment_url, data=data) + diff --git a/backport/tasks.py b/miss_islington/tasks.py similarity index 100% rename from backport/tasks.py rename to miss_islington/tasks.py diff --git a/backport/util.py b/miss_islington/util.py similarity index 81% rename from backport/util.py rename to miss_islington/util.py index 299feb12fc7a0bc..edb47623eada548 100644 --- a/backport/util.py +++ b/miss_islington/util.py @@ -28,8 +28,15 @@ def comment_on_pr(issue_number, message): print(response.text) -def user_login(item): - return item["user"]["login"] +async def leave_comment(gh, pr_number, message): + """ + Leave a comment on a PR/Issue + """ + issue_comment_url = f"/repos/python/cpython/issues/{pr_number}/comments" + data = { + "body": message, + } + await gh.post(issue_comment_url, data=data) def is_cpython_repo(): @@ -50,21 +57,6 @@ def get_participants(created_by, merged_by): return participants -def delete_branch(branch_name): - """ - Delete the branch on GitHub - """ - request_headers = sansio.create_headers( - "miss-islington", - oauth_token=os.environ.get('GH_AUTH')) - url = f"https://api.github.com/repos/miss-islington/cpython/git/refs/heads/{branch_name}" - response = requests.delete(url, headers=request_headers) - if response.status_code == 204: - print(f"{branch_name} branch deleted.") - else: - print(f"Couldn't delete the branch {branch_name}") - - def normalize_title(title, body): """Normalize the title if it spills over into the PR's body.""" if not (title.endswith('ā€¦') and body.startswith('ā€¦')): @@ -73,6 +65,7 @@ def normalize_title(title, body): # Being paranoid in case \r\n is used. return title[:-1] + body[1:].partition('\r\n')[0] + # Copied over from https://github.com/python/bedevere async def is_core_dev(gh, username): """Check if the user is a CPython core developer.""" diff --git a/tests/test_delete_branch.py b/tests/test_delete_branch.py new file mode 100644 index 000000000000000..eeba737b612429a --- /dev/null +++ b/tests/test_delete_branch.py @@ -0,0 +1,145 @@ +from gidgethub import sansio + +from miss_islington import delete_branch + + +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 + + +async def test_branch_deleted_when_pr_merged(): + data = { + "action": "closed", + "pull_request": { + "number": 5722, + "user": { + "login": "miss-islington", + }, + "merged": True, + "merged_by": { + "login": "miss-islington", + }, + "head": { + "ref": "backport-17ab8f0-3.7", + } + } + } + event = sansio.Event(data, event='pull_request', + delivery_id='1') + + gh = FakeGH() + await delete_branch.router.dispatch(event, gh) + assert len(gh.post_data["body"]) is not None # leaves a comment + assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}" + + +async def test_branch_deleted_and_thank_committer(): + data = { + "action": "closed", + "pull_request": { + "number": 5722, + "user": { + "login": "miss-islington", + }, + "merged": True, + "merged_by": { + "login": "Mariatta", + }, + "head": { + "ref": "backport-17ab8f0-3.7", + } + } + } + event = sansio.Event(data, event='pull_request', + delivery_id='1') + + gh = FakeGH() + await delete_branch.router.dispatch(event, gh) + assert gh.post_data["body"] == 'Thanks, @Mariatta!' # leaves a comment + assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}" + + +async def test_branch_deleted_and_thanks(): + data = { + "action": "closed", + "pull_request": { + "number": 5722, + "user": { + "login": "miss-islington", + }, + "merged": True, + "merged_by": { + "login": "miss-islington", + }, + "head": { + "ref": "backport-17ab8f0-3.7", + } + } + } + event = sansio.Event(data, event='pull_request', + delivery_id='1') + + gh = FakeGH() + await delete_branch.router.dispatch(event, gh) + assert gh.post_data["body"] == "Thanks!" # leaves a comment + assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}" + + +async def test_branch_deleted_when_pr_closed(): + data = { + "action": "closed", + "pull_request": { + "number": 5722, + "user": { + "login": "miss-islington", + }, + "merged": False, + "merged_by": { + "login": None, + }, + "head": { + "ref": "backport-17ab8f0-3.7", + } + } + } + event = sansio.Event(data, event='pull_request', + delivery_id='1') + + gh = FakeGH() + await delete_branch.router.dispatch(event, gh) + assert gh.post_data is None # does not leave a comment + assert gh.delete_url == f"/repos/miss-islington/cpython/git/refs/heads/{data['pull_request']['head']['ref']}" + + +async def test_ignore_non_miss_islingtons_prs(): + data = { + "action": "closed", + "pull_request": { + "number": 5722, + "user": { + "login": "Mariatta", + }, + "merged": True, + "merged_by": { + "login": "Mariatta", + }, + "head": { + "ref": "backport-17ab8f0-3.7", + } + } + } + event = sansio.Event(data, event='pull_request', + delivery_id='1') + gh = FakeGH() + await delete_branch.router.dispatch(event, gh) + assert gh.post_data is None # does not leave a comment + assert not hasattr(gh, 'delete_url') \ No newline at end of file diff --git a/tests/test_status_change.py b/tests/test_status_change.py index e0a4bb749f96655..a9c386ddddf3257 100644 --- a/tests/test_status_change.py +++ b/tests/test_status_change.py @@ -1,6 +1,9 @@ +import http +import gidgethub + from gidgethub import sansio -from backport import status_change +from miss_islington import status_change class FakeGH: @@ -431,3 +434,497 @@ async def test_pr_reviewed_changes_requested_pr_is_not_merged(): 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_pr_reviewed_ignore_non_miss_islingtons_pr(): + sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" + data = { + "action": "submitted", + "pull_request": { + "user": {"login": "Mariatta"}}, + "review": {"commit_id": sha, + "user": {"login": "Mariatta"}, + "state": "approved" + } + } + + event = sansio.Event(data, event='pull_request_review', + 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 failed", + "target_url": "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification", + "context": "continuous-integration/travis-ci/pr", + } + ] + }, + } + + getiter = { + "/orgs/python/teams": [{"name": "Python core", "id": 42}], + } + + 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(): + sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" + data = { + "sha": sha, + "commit": { + "committer": {"login": "Mariatta",}, + } + } + 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"} + }, + "/teams/42/memberships/Mariatta": True + } + + 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/reviews': [ + {"user": {"login": "Mariatta"}, + "state": "APPROVED" + }], + '/repos/python/cpython/pulls/5547/commits': [ + {"sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "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) + 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_pending(): + 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": "pending", + "statuses": [ + { + "state": "pending", + "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"} + }, + "/teams/42/memberships/Mariatta": True + } + + 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/reviews': [ + {"user": {"login": "Mariatta"}, + "state": "APPROVED" + }], + '/repos/python/cpython/pulls/5547/commits': [ + {"sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "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) + 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_travis_not_done(): + 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", + } + ] + }, + "/repos/python/cpython/pulls/5544": { + "user": {"login": "miss-islington"}, + "merged_by": {"login": "Mariatta"} + }, + "/teams/42/memberships/Mariatta": True + } + + 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/reviews': [ + {"user": {"login": "Mariatta"}, + "state": "APPROVED" + }], + '/repos/python/cpython/pulls/5547/commits': [ + {"sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "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) + 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_pr_title_does_not_match(): + 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"} + }, + "/teams/42/memberships/Mariatta": True + } + + 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": "bpo-32720: Fixed the replacement field grammar documentation.", + "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", + "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) + 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_approved_by_non_core_dev_review_pr_is_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"} + }, + "/teams/42/memberships/Mariatta": gidgethub.BadRequest(status_code=http.HTTPStatus(404)) + } + + 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/reviews': [ + {"user": {"login": "Mariatta"}, + "state": "APPROVED" + }], + '/repos/python/cpython/pulls/5547/commits': [ + {"sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", + "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) + 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"} + }, + "/teams/42/memberships/Mariatta": True + } + + 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/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 " + }}], + "/orgs/python/teams": [{"name": "Python core", "id": 42}], + + + } + + gh = FakeGH(getitem=getitem, + getiter=getiter) + await status_change.router.dispatch(event, gh) + assert not hasattr(gh, 'put_data') # is not merged \ No newline at end of file diff --git a/tests/test_util.py b/tests/test_util.py index 9385af79a38425d..9d7145e44bf936e 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -5,7 +5,7 @@ from unittest import mock -from backport import util +from miss_islington import util class FakeGH: @@ -36,6 +36,7 @@ async def post(self, url, *, data): self.post_data = data return self._post_return + def test_title_normalization(): title = "abcd" body = "1234"