diff --git a/miss_islington/__main__.py b/miss_islington/__main__.py index 0d2b941e..4670e38d 100644 --- a/miss_islington/__main__.py +++ b/miss_islington/__main__.py @@ -12,10 +12,10 @@ from sentry_sdk.integrations.aiohttp import AioHttpIntegration -from . import backport_pr, check_run, delete_branch, status_change +from . import backport_pr, delete_branch router = routing.Router( - backport_pr.router, delete_branch.router, status_change.router, check_run.router + backport_pr.router, delete_branch.router ) cache = cachetools.LRUCache(maxsize=500) diff --git a/miss_islington/check_run.py b/miss_islington/check_run.py deleted file mode 100644 index 400fa241..00000000 --- a/miss_islington/check_run.py +++ /dev/null @@ -1,34 +0,0 @@ -import re - -from gidgethub import routing - -from . import util -from .status_change import check_ci_status_and_approval - -router = routing.Router() - -TITLE_RE = re.compile(r"\[(?P\d+\.\d+)\].+?(?P\d+)\)") - - -@router.register("check_run", action="completed") -async def check_run_completed(event, gh, *args, **kwargs): - """ - A check run is completed event handler. - """ - sha = event.data["check_run"]["head_sha"] - - if event.data["sender"]["login"] == "miss-islington": - # Leave comment temporarily disabled when automerge not used. See #577. - await check_ci_status_and_approval(gh, sha, leave_comment=False) - else: - pr_for_commit = await util.get_pr_for_commit(gh, sha) - if pr_for_commit: - pr_labels = pr_for_commit["labels"] - if util.pr_is_automerge(pr_labels) and util.pr_is_awaiting_merge(pr_labels): - await check_ci_status_and_approval( - gh, - sha, - pr_for_commit=pr_for_commit, - leave_comment=True, - is_automerge=True, - ) diff --git a/miss_islington/status_change.py b/miss_islington/status_change.py deleted file mode 100644 index d86be3ef..00000000 --- a/miss_islington/status_change.py +++ /dev/null @@ -1,169 +0,0 @@ -import re - -import gidgethub -from gidgethub import routing - -from . import util - -router = routing.Router() - -TITLE_RE = re.compile(r"\[(?P\d+\.\d+)\].+?(?P\d+)\)") -AUTOMERGE_TRAILER = "Automerge-Triggered-By" - - -@router.register("status") -async def check_status(event, gh, *args, **kwargs): - """ - Check the state change - """ - sha = event.data["sha"] - - if ( - event.data["commit"].get("committer") - and event.data["commit"]["committer"]["login"] == "miss-islington" - ): - # Leave comment temporarily disabled when automerge not used. See #577. - await check_ci_status_and_approval(gh, sha, leave_comment=False) - else: - pr_for_commit = await util.get_pr_for_commit(gh, sha) - if pr_for_commit: - pr_labels = pr_for_commit["labels"] - if util.pr_is_automerge(pr_labels) and util.pr_is_awaiting_merge(pr_labels): - await check_ci_status_and_approval( - gh, - sha, - pr_for_commit=pr_for_commit, - leave_comment=True, - is_automerge=True, - ) - - -@router.register("pull_request", action="labeled") -async def pr_reviewed(event, gh, *args, **kwargs): - - pr_labels = event.data["pull_request"]["labels"] - sender = event.data["sender"]["login"] - label = event.data["label"]["name"] - - if label == util.AUTOMERGE_LABEL: - if await util.is_core_dev(gh, sender): - await add_automerged_by(gh, event.data["pull_request"], sender) - else: - await util.remove_automerge(gh, event.data["pull_request"]) - return - - if util.pr_is_automerge(pr_labels) and util.pr_is_awaiting_merge(pr_labels): - sha = event.data["pull_request"]["head"]["sha"] - - await check_ci_status_and_approval( - gh, sha, pr_for_commit=event.data["pull_request"], is_automerge=True - ) - elif event.data["pull_request"]["user"][ - "login" - ] == "miss-islington" and 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, pr_for_commit=event.data["pull_request"] - ) - - -async def check_ci_status_and_approval( - gh, sha, pr_for_commit=None, leave_comment=False, is_automerge=False -): - - result = await gh.getitem(f"/repos/python/cpython/commits/{sha}/status") - all_ci_status = [status["state"] for status in result["statuses"]] - - check_runs = await util.get_check_runs_for_sha(gh, sha) - - all_check_run_status = [ - check_run["status"] for check_run in check_runs["check_runs"] - ] - all_check_run_conclusions = [ - check_run["conclusion"] for check_run in check_runs["check_runs"] - ] - - if ( - "pending" not in all_ci_status - and "in_progress" not in all_check_run_status - and "queued" not in all_check_run_status - ): # wait until all status and check runs are completed - - if not pr_for_commit: - pr_for_commit = await util.get_pr_for_commit(gh, sha) - if pr_for_commit: - pr_number = pr_for_commit["number"] - normalized_pr_title = util.normalize_title( - pr_for_commit["title"], pr_for_commit["body"] - ) - - title_match = TITLE_RE.match(normalized_pr_title) - if title_match or is_automerge: - failure = any( - elem in [None, "failure", "timed_out"] - for elem in all_check_run_conclusions - ) - success = result["state"] == "success" and not failure - if leave_comment: - if failure or not success: - emoji = "❌" - status = "it's a failure or timed out" - else: - emoji = "✅" - status = "it's a success" - message = f"Status check is done, and {status} {emoji}." - if not success: - # if is_automerge: - participants = await util.get_gh_participants(gh, pr_number) - # else: - # original_pr_number = title_match.group("pr") - # participants = await util.get_gh_participants( - # gh, original_pr_number - # ) - message = f"{participants}: {message}" - await util.leave_comment( - gh, - pr_number=pr_number, - message=message, - ) - if success: - if util.pr_is_awaiting_merge(pr_for_commit["labels"]): - await merge_pr( - gh, pr_for_commit, sha, is_automerge=is_automerge - ) - - -async def merge_pr(gh, pr, sha, is_automerge=False): - pr_number = pr["number"] - async for commit in gh.getiter(f"/repos/python/cpython/pulls/{pr_number}/commits"): # pragma: no branch - if commit["sha"] == sha: # pragma: no branch - if is_automerge: - pr_commit_msg = util.normalize_message(pr["body"]) - pr_title = f"{pr['title']} (GH-{pr_number})" - else: - commit_msg = commit["commit"]["message"].split("\n") - pr_commit_msg = "\n".join(commit_msg[1:]) - pr_title = f"{commit_msg[0]}" - - data = { - "commit_title": pr_title, - "commit_message": pr_commit_msg, - "sha": sha, - "merge_method": "squash", - } - try: - await gh.put( - f"/repos/python/cpython/pulls/{pr_number}/merge", data=data - ) - except gidgethub.BadRequest as err: - await util.comment_on_pr( - gh, pr_number, f"Sorry, I can't merge this PR. Reason: `{err}`." - ) - break - - -async def add_automerged_by(gh, pr_data, username): - new_pr_body = f"{pr_data['body'].rstrip()}\n\n{AUTOMERGE_TRAILER}: GH:{username}" - await gh.patch(pr_data["url"], data={"body": new_pr_body}) diff --git a/miss_islington/util.py b/miss_islington/util.py index 57908d7b..7a60698f 100644 --- a/miss_islington/util.py +++ b/miss_islington/util.py @@ -3,9 +3,6 @@ import gidgethub -from .status_change import AUTOMERGE_TRAILER - -AUTOMERGE_LABEL = ":robot: automerge" async def comment_on_pr(gh, issue_number, message): @@ -83,93 +80,3 @@ def normalize_title(title, body): # Being paranoid in case \r\n is used. return title[:-1] + body[1:].partition("\r\n")[0] - -def normalize_message(body): - """Normalize the message body to make it commit-worthy. - - Mostly this just means removing HTML comments, but also removes unwanted - leading or trailing whitespace. - - Returns the normalized body. - """ - # Remove issue mentions added by Bedevere. - # This should catch both current gh- and legacy bpo- messages. - body = re.sub(r"(?s)", "", body) - # Remove other HTML comments - while "") + 3 :] - # Delete BPO links on their own line, probably added by an old version of Bedevere. - body = re.sub(r"\nhttps://bugs.python.org/issue(\d+)\n", "", body) - # Strip additional newlines between commit body and automerge label. - body_parts = body.split(AUTOMERGE_TRAILER) - if len(body_parts) > 1: - body, automerge_user = body_parts - body = f"{body.strip()}\n\n{AUTOMERGE_TRAILER}{automerge_user}" - return "\n\n" + body.strip() - - -# Copied over from https://github.com/python/bedevere -async def is_core_dev(gh, username): - """Check if the user is a CPython core developer.""" - org_teams = "/orgs/python/teams" - team_name = "python core" - async for team in gh.getiter(org_teams): - if team["name"].lower() == team_name: # pragma: no branch - break - else: - raise ValueError(f"{team_name!r} not found at {org_teams!r}") - # The 'teams' object only provides a URL to a deprecated endpoint, - # so manually construct the URL to the non-deprecated team membership - # endpoint. - membership_url = f"/teams/{team['id']}/memberships/{username}" - try: - await gh.getitem(membership_url) - except gidgethub.BadRequest as exc: - if exc.status_code == 404: - return False - raise - else: - return True - - -def pr_is_awaiting_merge(pr_labels): - label_names = [label["name"] for label in pr_labels] - if ( - "DO-NOT-MERGE" not in label_names - and "awaiting merge" in label_names - and "CLA not signed" not in label_names - ): - return True - return False - - -def pr_is_automerge(pr_labels): - for label in pr_labels: - if label["name"] == AUTOMERGE_LABEL: - return True - return False - - -async def get_pr_for_commit(gh, sha): - prs_for_commit = await gh.getitem( - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}" - ) - if prs_for_commit["total_count"] > 0: # there should only be one - pr_for_commit = prs_for_commit["items"][0] - return pr_for_commit - return None - - -async def remove_automerge(gh, pr_data): - """Remove the automerge label""" - await gh.delete( - f"{pr_data['issue_url']}/labels/{AUTOMERGE_LABEL}", - accept="application/vnd.github.symmetra-preview+json", - ) - - -async def get_check_runs_for_sha(gh, sha): - return await gh.getitem( - f"/repos/python/cpython/commits/{sha}/check-runs", - accept="application/vnd.github.antiope-preview+json", - ) diff --git a/tests/test_check_run.py b/tests/test_check_run.py deleted file mode 100644 index 29ff32fe..00000000 --- a/tests/test_check_run.py +++ /dev/null @@ -1,597 +0,0 @@ -import http - -import gidgethub -from gidgethub import sansio -from tests.test_status_change import FakeGH - -from miss_islington import check_run -from miss_islington.util import AUTOMERGE_LABEL - - -async def test_check_run_completed_ci_passed_with_awaiting_merge_label_pr_is_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "miss-islington"}, - } - event = sansio.Event(data, event="check_run", 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await check_run.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # assert len(gh.post_data["body"]) is not None # leaves a comment - assert gh.put_data["sha"] == sha # is merged - assert gh.put_data["merge_method"] == "squash" - assert ( - gh.put_data["commit_title"] - == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)" - ) - assert ( - gh.put_data["commit_message"] - == "\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta " - ) - - -async def test_check_run_completed_other_check_run_pending_with_awaiting_merge_label_pr_is_not_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "miss-islington"}, - } - event = sansio.Event(data, event="check_run", 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - }, - {"conclusion": None, "name": "Docs", "status": "queued"}, - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await check_run.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_check_run_completed_other_check_run_queued_with_awaiting_merge_label_pr_is_not_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "miss-islington"}, - } - event = sansio.Event(data, event="check_run", 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - }, - {"conclusion": None, "name": "Docs", "status": "queued"}, - ], - "total_count": 1, - }, - } - - gh = FakeGH(getitem=getitem) - await check_run.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_check_run_completed_failure_with_awaiting_merge_label_pr_is_not_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "miss-islington"}, - } - event = sansio.Event(data, event="check_run", 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - }, - {"conclusion": "failure", "name": "Docs", "status": "completed"}, - ], - "total_count": 1, - }, - } - - gh = FakeGH(getitem=getitem) - await check_run.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # assert len(gh.post_data["body"]) is not None # leaves a comment - assert not hasattr(gh, "put_data") # is not merged - - -async def test_check_run_completed_timed_out_with_awaiting_merge_label_pr_is_not_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "miss-islington"}, - } - event = sansio.Event(data, event="check_run", 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - }, - {"conclusion": "timed_out", "name": "Docs", "status": "completed"}, - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await check_run.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # assert len(gh.post_data["body"]) is not None # leaves a comment - assert not hasattr(gh, "put_data") # is not merged - - -async def test_check_run_created_with_awaiting_merge_label_pr_is_not_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "created", - "check_run": {"head_sha": sha}, - "sender": {"login": "miss-islington"}, - } - event = sansio.Event(data, event="check_run", delivery_id="1") - - gh = FakeGH() - await check_run.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_check_run_completed_with_awaiting_merge_label_not_miss_islington_is_not_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "Mariatta"}, - } - event = sansio.Event(data, event="check_run", 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"}]}, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 1, - "items": [ - { - "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 ", - "labels": [{"name": "awaiting merge"}], - } - ], - }, - } - - gh = FakeGH(getitem=getitem) - await check_run.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_not_found_for_commit(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "Mariatta"}, - } - event = sansio.Event(data, event="check_run", delivery_id="1") - - getitem = { - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 0, - "items": [], - } - } - - gh = FakeGH(getitem=getitem) - await check_run.router.dispatch(event, gh) - assert not hasattr(gh, "post_data") # does not leave a comment - assert not hasattr(gh, "put_data") # does not leave a comment - - -async def test_ci_passed_automerge(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "Mariatta"}, - } - event = sansio.Event(data, event="check_run", 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/5547": { - "user": {"login": "bedevere-bot"}, - "merged_by": None, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - }, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 1, - "items": [ - { - "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 ", - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [ - { - "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", - "commit": { - "message": "bpo-32720: Fixed the replacement field grammar documentation." - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await check_run.router.dispatch(event, gh) - assert len(gh.post_data["body"]) is not None # leaves a comment - assert gh.put_data["sha"] == sha # is merged - assert gh.put_data["merge_method"] == "squash" - assert ( - gh.put_data["commit_title"] - == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5547)" - ) - - -async def test_ci_passed_not_automerge(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "completed", - "check_run": {"head_sha": sha}, - "sender": {"login": "Mariatta"}, - } - event = sansio.Event(data, event="check_run", 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/5547": { - "user": {"login": "bedevere-bot"}, - "merged_by": None, - "labels": [{"name": "awaiting merge"}], - }, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 1, - "items": [ - { - "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 ", - "labels": [{"name": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [ - { - "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", - "commit": { - "message": "bpo-32720: Fixed the replacement field grammar documentation." - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await check_run.router.dispatch(event, gh) - assert not hasattr(gh, "post_data") # does not leave a comment - assert not hasattr(gh, "put_data") # does not leave a comment diff --git a/tests/test_status_change.py b/tests/test_status_change.py deleted file mode 100644 index d7fbfec4..00000000 --- a/tests/test_status_change.py +++ /dev/null @@ -1,1927 +0,0 @@ -import http - -import gidgethub -from gidgethub import sansio - -from miss_islington import status_change -from miss_islington.util import AUTOMERGE_LABEL - - -class FakeGH: - def __init__( - self, - *, - getitem=None, - getiter=None, - put=None, - post=None, - patch=None, - delete=None, - ): - self._getitem_return = getitem - self._getiter_return = getiter - self.getitem_url = None - self.getiter_url = None - self._put_return = put - self._delete_return = put - self._post_return = post - self._patch_return = patch - self.patch_url = self.patch_data = None - - async def getitem(self, url, accept=None): - self.getitem_url = url - to_return = self._getitem_return[self.getitem_url] - if isinstance(to_return, Exception): - raise to_return - else: - return to_return - - async def getiter(self, url): - self.getiter_url = url - to_iterate = self._getiter_return[url] - for item in to_iterate: - yield item - - async def patch(self, url, *, data): - self.patch_url = url - self.patch_data = data - return self._patch_return - - async def delete(self, url, *, data=b"", accept=None): - self.delete_url = url - return self._delete_return - - async def put(self, url, *, data): - self.put_url = url - self.put_data = data - to_return = self._put_return - if isinstance(to_return, Exception): - raise to_return - else: - return to_return - - async def post(self, url, *, data): - self.post_url = url - self.post_data = data - return self._post_return - - -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") - - 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await status_change.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # expected_body = "Status check is done, and it's a success ✅." - # assert gh.post_data["body"] == expected_body - assert gh.put_data["sha"] == sha # is merged - assert gh.put_data["merge_method"] == "squash" - assert ( - gh.put_data["commit_title"] - == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)" - ) - assert ( - gh.put_data["commit_message"] - == "\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta " - ) - - -async def test_ci_and_check_run_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") - - 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"}] - }, - f"/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": "awaiting core review"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - gh = FakeGH(getitem=getitem) - await status_change.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # expected_body = "Status check is done, and it's a success ✅." - # assert gh.post_data["body"] == expected_body - assert not hasattr(gh, "put_data") # 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") - - getitem = { - f"/repos/python/cpython/commits/{sha}/status": { - "state": "failure", - "statuses": [ - { - "state": "success", - "description": "Issue report skipped", - "context": "bedevere/issue-number", - }, - { - "state": "failure", - "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", - }, - ], - }, - "/repos/python/cpython/pulls/5544": { - "user": {"login": "miss-islington"}, - "merged_by": {"login": "Mariatta"}, - }, - "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - gh = FakeGH(getitem=getitem) - await status_change.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # expected_body = "@miss-islington and @Mariatta: Status check is done, and it's a failure ❌." - # assert gh.post_data["body"] == expected_body - assert not hasattr(gh, "put_data") # is not merged - - -async def test_ci_passed_and_check_run_failure_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") - - 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "failure", - "name": "Travis CI - Pull Request", - "status": "completed", - }, - {"conclusion": "success", "name": "Docs", "status": "completed"}, - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await status_change.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # expected_body = "@miss-islington and @Mariatta: Status check is done, and it's a failure or timed out ❌." - # assert gh.post_data["body"] == expected_body - assert not hasattr(gh, "put_data") # is not merged - - -async def test_automerge_with_check_run_failure(): - 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"}, - }, - "/repos/python/cpython/pulls/5547": { - "user": {"login": "Mariatta"}, - "merged_by": None, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - }, - f"/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": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "failure", - "name": "Travis CI - Pull Request", - "status": "completed", - }, - {"conclusion": "success", "name": "Docs", "status": "completed"}, - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await status_change.router.dispatch(event, gh) - expected_body = "@Mariatta: Status check is done, and it's a failure or timed out ❌." - assert gh.post_data["body"] == expected_body - assert not hasattr(gh, "put_data") # is not merged - - -async def test_ci_passed_and_check_run_pending_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") - - 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": None, - "name": "Travis CI - Pull Request", - "status": "pending", - }, - {"conclusion": "success", "name": "Docs", "status": "completed"}, - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await status_change.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # expected_body = "@miss-islington and @Mariatta: Status check is done, and it's a failure or timed out ❌." - # assert gh.post_data["body"] == expected_body - assert not hasattr(gh, "put_data") # is not merged - - -async def test_ci_passed_and_check_run_timed_out_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") - - 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "timed_out", - "name": "Travis CI - Pull Request", - "status": "completed", - }, - {"conclusion": "success", "name": "Docs", "status": "completed"}, - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await status_change.router.dispatch(event, gh) - # Leave comment temporarily disabled when automerge not used. See #577. - # expected_body = ("@miss-islington and @Mariatta: Status check is done, " - # "and it's a failure or timed out ❌.") - # assert gh.post_data["body"] == expected_body - assert not hasattr(gh, "put_data") # is not merged - - -async def test_awaiting_merge_label_added_and_ci_passed_pr_is_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "miss-islington"}, - "labels": [{"name": "awaiting merge"}], - "head": {"sha": sha}, - "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 ", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": "awaiting merge"}, - } - - 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", - }, - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [], - "total_count": 0, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - 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 gh.put_data["sha"] == sha # is merged - assert gh.put_data["merge_method"] == "squash" - assert ( - gh.put_data["commit_title"] - == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)" - ) - assert ( - gh.put_data["commit_message"] - == "\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta " - ) - - -async def test_awaiting_merge_webhook_ci_failure_pr_is_not_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "miss-islington"}, - "labels": [{"name": "awaiting merge"}], - "head": {"sha": sha}, - "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 ", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": "awaiting merge"}, - } - - event = sansio.Event(data, event="pull_request", delivery_id="1") - - getitem = { - f"/repos/python/cpython/commits/{sha}/status": { - "state": "failure", - "statuses": [ - { - "state": "success", - "description": "Issue report skipped", - "context": "bedevere/issue-number", - }, - { - "state": "failure", - "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", - }, - ], - }, - "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "failure", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - gh = FakeGH(getitem=getitem) - 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_awaiting_core_review_label_added_is_not_merged(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "miss-islington"}, - "labels": [{"name": "awaiting core review"}], - "head": {"sha": sha}, - }, - "sender": {"login": "bedevere-bot"}, - "label": {"name": "awaiting core review"}, - } - - event = sansio.Event(data, event="pull_request", delivery_id="1") - - getitem = { - f"/repos/python/cpython/commits/{sha}/status": { - "state": "failure", - "statuses": [ - { - "state": "success", - "description": "Issue report skipped", - "context": "bedevere/issue-number", - }, - { - "state": "failure", - "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", - }, - ], - }, - f"/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": "awaiting core review"}], - } - ], - }, - } - - gh = FakeGH(getitem=getitem) - 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_awaiting_merge_label_ignore_non_miss_islingtons_pr(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "Mariatta"}, - "labels": [{"name": "awaiting merge"}], - "head": {"sha": sha}, - "body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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 failed", - "target_url": "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification", - "context": "continuous-integration/travis-ci/pr", - }, - ], - }, - "/teams/42/memberships/Mariatta": True, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - 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_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") - - 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"}]}, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 1, - "items": [ - { - "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 ", - "labels": [{"name": "awaiting merge"}], - } - ], - }, - } - - gh = FakeGH(getitem=getitem) - 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"}, - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - 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"}, - }, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 1, - "items": [ - { - "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 ", - "labels": [{"name": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/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 " - }, - } - ] - } - - 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_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") - - 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"}] - }, - f"/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": "awaiting core review"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - gh = FakeGH(getitem=getitem) - 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"}]}, - f"/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": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/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_merge_label_added_not_miss_islingtons_pr(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "Mariatta"}, - "labels": [{"name": "awaiting merge"}], - "head": {"sha": sha}, - "body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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 merge"}]}, - "/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/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 - - -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}, - "body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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"}] - }, - "/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/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 - - -async def test_no_pr_containing_sha(): - 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": "failure", - "statuses": [ - { - "state": "success", - "description": "Issue report skipped", - "context": "bedevere/issue-number", - }, - { - "state": "failure", - "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", - }, - ], - }, - "/repos/python/cpython/pulls/5544": { - "user": {"login": "miss-islington"}, - "merged_by": {"login": "Mariatta"}, - }, - "/repos/python/cpython/pulls/5547": {"labels": [{"name": "awaiting merge"}]}, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 0, - "items": [], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - gh = FakeGH(getitem=getitem) - await status_change.router.dispatch(event, gh) - assert not hasattr(gh, "post_data") # does not leave any comment - assert not hasattr(gh, "put_data") # is not merged - - -async def test_ci_passed_automerge(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = {"sha": sha, "commit": {"committer": None, "author": None}} - 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/5547": { - "user": {"login": "bedevere-bot"}, - "merged_by": None, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - }, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 1, - "items": [ - { - "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 ", - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [ - { - "sha": "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9", - "commit": { - "message": "bpo-32720: Fixed the replacement field grammar documentation." - }, - } - ] - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await status_change.router.dispatch(event, gh) - expected_body = "Status check is done, and it's a success ✅." - assert gh.post_data["body"] == expected_body - assert gh.put_data["sha"] == sha # is merged - assert gh.put_data["merge_method"] == "squash" - assert ( - gh.put_data["commit_title"] - == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5547)" - ) - - -async def test_ci_passed_not_automerge(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = {"sha": sha, "commit": {"committer": None, "author": None}} - 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/5547": { - "user": {"login": "bedevere-bot"}, - "merged_by": None, - "labels": [{"name": "awaiting merge"}], - }, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 1, - "items": [ - { - "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`.", - "labels": [{"name": "awaiting merge"}], - } - ], - }, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - gh = FakeGH(getitem=getitem) - 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_awaiting_merge_label_and_automerge_label_added_not_miss_islingtons_pr(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "Mariatta"}, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - "head": {"sha": sha}, - "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`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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", - }, - ], - }, - "/teams/42/memberships/Mariatta": True, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [{"sha": sha}], - "/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 gh.put_data["sha"] == sha # is merged - assert gh.put_data["merge_method"] == "squash" - assert ( - gh.put_data["commit_title"] - == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5547)" - ) - assert ( - gh.put_data["commit_message"] - == "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`." - ) - - -async def test_automerge_but_not_awaiting_merge(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "Mariatta"}, - "labels": [{"name": "awaiting review"}, {"name": AUTOMERGE_LABEL}], - "head": {"sha": sha}, - "body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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/5547": { - "user": {"login": "Mariatta"}, - "merged_by": None, - "labels": [{"name": "awaiting review"}, {"name": AUTOMERGE_LABEL}], - }, - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 1, - "items": [ - { - "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`.", - "labels": [{"name": "awaiting merge"}, {"name": AUTOMERGE_LABEL}], - } - ], - }, - "/teams/42/memberships/Mariatta": True, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [{"sha": sha}], - "/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") # does not leave a comment - - -async def test_pr_not_found_for_commit(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = {"sha": sha, "commit": {"committer": None, "author": None}} - - event = sansio.Event(data, event="status", delivery_id="1") - - getitem = { - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 0, - "items": [], - } - } - - gh = FakeGH(getitem=getitem) - await status_change.router.dispatch(event, gh) - assert not hasattr(gh, "post_data") # does not leave a comment - assert not hasattr(gh, "put_data") # does not leave a comment - - -async def test_automerge_multi_commits_in_pr(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "Mariatta"}, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - "head": {"sha": sha}, - "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`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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", - }, - ], - }, - "/teams/42/memberships/Mariatta": True, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [ - {"sha": "5f007046b5d4766f971272a0cc99f8461215c1ec"}, - {"sha": sha}, - ], - "/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 gh.put_data["sha"] == sha # is merged - assert gh.put_data["merge_method"] == "squash" - assert ( - gh.put_data["commit_title"] - == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5547)" - ) - assert ( - gh.put_data["commit_message"] - == "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`." - ) - - -async def test_automerge_commit_not_found(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "Mariatta"}, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - "head": {"sha": sha}, - "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`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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", - }, - ], - }, - "/teams/42/memberships/Mariatta": True, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [], - "/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") # does not merge - - -async def test_automerge_failed(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "Mariatta"}, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - "head": {"sha": sha}, - "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`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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", - }, - ], - }, - "/teams/42/memberships/Mariatta": True, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [ - {"sha": "5f007046b5d4766f971272a0cc99f8461215c1ec"}, - {"sha": sha}, - ], - "/orgs/python/teams": [{"name": "python core", "id": 42}], - } - - gh = FakeGH( - getitem=getitem, - getiter=getiter, - put=gidgethub.BadRequest(status_code=http.HTTPStatus(400)), - post={ - "html_url": f"https://github.com/python/cpython/pull/5547#issuecomment-401309376" - }, - ) - - await status_change.router.dispatch(event, gh) - - assert gh.put_data["sha"] == sha - assert gh.put_data["merge_method"] == "squash" - assert ( - gh.put_data["commit_title"] - == "bpo-32720: Fixed the replacement field grammar documentation. (GH-5547)" - ) - assert ( - gh.put_data["commit_message"] - == "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`." - ) - - assert "Sorry, I can't merge this PR" in gh.post_data["body"] - - -async def test_automerge_label_added_by_non_core_dev(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "miss-islington"}, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - "head": {"sha": sha}, - "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`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - "issue_url": "https://api.github.com/repos/python/cpython/issues/5547", - }, - "sender": {"login": "miss-islington"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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", - }, - ], - }, - "/teams/42/memberships/miss-islington": gidgethub.BadRequest( - status_code=http.HTTPStatus(404) - ), - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [{"sha": sha}], - "/orgs/python/teams": [{"name": "python core", "id": 42}], - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await status_change.router.dispatch(event, gh) - assert ( - gh.delete_url == f'{data["pull_request"]["issue_url"]}/labels/{AUTOMERGE_LABEL}' - ) - assert not hasattr(gh, "post_data") # does not leave a comment - - assert not hasattr(gh, "post_data") # does not leave a comment - assert not hasattr(gh, "put_data") # does not merge - - -async def test_automerge_label_triggered_by_added_to_pr(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - data = { - "action": "labeled", - "pull_request": { - "user": {"login": "miss-islington"}, - "labels": [ - {"name": "awaiting merge"}, - {"name": AUTOMERGE_LABEL}, - ], - "head": {"sha": sha}, - "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`.", - "url": "https://api.github.com/repos/python/cpython/pulls/5547", - "issue_url": "https://api.github.com/repos/python/cpython/issues/5547", - }, - "sender": {"login": "Mariatta"}, - "label": {"name": AUTOMERGE_LABEL}, - } - - 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", - }, - ], - }, - "/teams/42/memberships/Mariatta": True, - f"/repos/python/cpython/commits/{sha}/check-runs": { - "check_runs": [ - { - "conclusion": "success", - "name": "Travis CI - Pull Request", - "status": "completed", - } - ], - "total_count": 1, - }, - } - - getiter = { - "/repos/python/cpython/pulls/5547/commits": [{"sha": sha}], - "/orgs/python/teams": [{"name": "python core", "id": 42}], - } - - gh = FakeGH(getitem=getitem, getiter=getiter) - await status_change.router.dispatch(event, gh) - assert gh.patch_url == f'{data["pull_request"]["url"]}' - assert gh.patch_data == { - "body": f"{data['pull_request']['body']}\n\nAutomerge-Triggered-By: GH:Mariatta" - } diff --git a/tests/test_util.py b/tests/test_util.py index b6af74b0..281a2cda 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -11,29 +11,17 @@ class FakeGH: - def __init__(self, *, getiter=None, getitem=None, post=None, patch=None): + def __init__(self, *, getitem=None, post=None, patch=None): self._getitem_return = getitem - self._getiter_return = getiter self._post_return = post self._patch_return = patch self.getitem_url = None - self.getiter_url = None self.patch_url = self.patch_data = None self.post_url = self.post_data = 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 - - async def getiter(self, url): - self.getiter_url = url - to_iterate = self._getiter_return[url] - for item in to_iterate: - yield item + return self._getitem_return[self.getitem_url] async def patch(self, url, *, data): self.patch_url = url @@ -74,62 +62,6 @@ def test_title_normalization(): assert util.normalize_title(title, body) == expected -def test_message_normalization(): - message = "And this is the part we want" - assert util.normalize_message(message) == "\n\nAnd this is the part we want" - - message = "Part we want" - assert util.normalize_message(message) == "\n\nPart we want" - - message = "\r\nParts we want\r\nincluded" - assert util.normalize_message(message) == "\n\nParts we want\r\nincluded" - - message = textwrap.dedent( - """ - The truncate() method of io.BufferedReader() should raise - UnsupportedOperation when it is called on a read-only - io.BufferedReader() instance. - - - - - - https://bugs.python.org/issue35950 - - - - Automerge-Triggered-By: @methane - """ - ) - - expected_message = textwrap.dedent( - """ - - The truncate() method of io.BufferedReader() should raise - UnsupportedOperation when it is called on a read-only - io.BufferedReader() instance. - - Automerge-Triggered-By: @methane""" - ) - assert util.normalize_message(message) == expected_message - - message = textwrap.dedent( - """ - Some commit message. - - - - * Issue: gh-93516 - Exact content between comments shouldn't matter, it should all go away. - - - - https://bugs.python.org/issue24766 - - """ - ) - assert util.normalize_message(message) == "\n\nSome commit message." - async def test_get_gh_participants_different_creator_and_committer(): gh = FakeGH( @@ -209,80 +141,6 @@ def test_is_not_cpython_repo(): assert util.is_cpython_repo() == False -async def test_is_core_dev(): - teams = [{"name": "not Python core"}] - gh = FakeGH(getiter={"/orgs/python/teams": teams}) - with pytest.raises(ValueError): - await util.is_core_dev(gh, "mariatta") - - teams = [{"name": "python core", "id": 42}] - getitem = {"/teams/42/memberships/mariatta": True} - gh = FakeGH(getiter={"/orgs/python/teams": teams}, getitem=getitem) - assert await util.is_core_dev(gh, "mariatta") - assert gh.getiter_url == "/orgs/python/teams" - - teams = [{"name": "python core", "id": 42}] - getitem = { - "/teams/42/memberships/miss-islington": gidgethub.BadRequest( - status_code=http.HTTPStatus(404) - ) - } - gh = FakeGH(getiter={"/orgs/python/teams": teams}, getitem=getitem) - assert not await util.is_core_dev(gh, "miss-islington") - - teams = [{"name": "python core", "id": 42}] - getitem = { - "/teams/42/memberships/miss-islington": gidgethub.BadRequest( - status_code=http.HTTPStatus(400) - ) - } - 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": "awaiting merge"}] - assert util.pr_is_awaiting_merge(labels) is True - - -def test_pr_is_do_not_merge(): - labels = [ - {"name": "awaiting merge"}, - {"name": "DO-NOT-MERGE"}, - ] - assert util.pr_is_awaiting_merge(labels) is False - - labels = [{"name": "CLA not signed"}, {"name": "awaiting merge"}] - assert util.pr_is_awaiting_merge(labels) is False - - labels = [ - {"name": "CLA not signed"}, - {"name": "awaiting merge"}, - {"name": "DO-NOT-MERGE"}, - ] - assert util.pr_is_awaiting_merge(labels) is False - - -def test_pr_is_automerge(): - labels = [ - {"name": util.AUTOMERGE_LABEL}, - {"name": "awaiting review"}, - ] - assert util.pr_is_automerge(labels) is True - - -def test_pr_is_not_awaiting_merge(): - labels = [ - {"name": "skip issue"}, - {"name": "awaiting review"}, - ] - assert util.pr_is_awaiting_merge(labels) is False - - -def test_pr_is_not_automerge(): - labels = [{"name": "awaiting merge"}] - assert util.pr_is_automerge(labels) is False async def test_comment_on_pr_success(): @@ -318,41 +176,3 @@ async def test_assign_pr_to_coredev(): await util.assign_pr_to_core_dev(gh, issue_number, coredev_login) assert gh.patch_url == f"/repos/python/cpython/issues/{issue_number}" - -async def test_get_pr_for_commit(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - gh = FakeGH( - getitem={ - f"/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 ", - } - ], - } - } - ) - result = await util.get_pr_for_commit(gh, sha) - assert result == { - "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 ", - } - - -async def test_get_pr_for_commit_not_found(): - sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9" - gh = FakeGH( - getitem={ - f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": { - "total_count": 0, - "items": [], - } - } - ) - result = await util.get_pr_for_commit(gh, sha) - - assert result is None