From 3877a8afa6466122c3c4f96af7649b9024f674e9 Mon Sep 17 00:00:00 2001 From: Christopher Dignam Date: Wed, 19 Jun 2024 20:17:56 -0400 Subject: [PATCH] fmt and fix test --- bot/kodiak/queries/__init__.py | 9 +- .../fixtures/api/get_event/no_author.json | 40 -------- bot/kodiak/test_queries.py | 96 +++++++++++++------ 3 files changed, 69 insertions(+), 76 deletions(-) diff --git a/bot/kodiak/queries/__init__.py b/bot/kodiak/queries/__init__.py index 5c042b4e3..894d4423a 100644 --- a/bot/kodiak/queries/__init__.py +++ b/bot/kodiak/queries/__init__.py @@ -630,13 +630,13 @@ def get_sha(*, pr: Dict[str, Any]) -> Optional[str]: return None - - def get_branch_protection( *, config_response: Dict[str, Any], ref_name: str ) -> Optional[BranchProtectionRule]: try: - branchProtectionRule = config_response['repository']['refs']['edges'][0]['node']['branchProtectionRule'] + branchProtectionRule = config_response["repository"]["refs"]["edges"][0][ + "node" + ]["branchProtectionRule"] try: return BranchProtectionRule.parse_obj(branchProtectionRule) except ValueError: @@ -1007,9 +1007,8 @@ async def get_config_for_ref( if data is None: self.log.error("could not fetch default branch name", res=res) return None - - branch_protection = get_branch_protection(config_response=data,ref_name=ref) + branch_protection = get_branch_protection(config_response=data, ref_name=ref) parsed_config = parse_config(data) if parsed_config is None: diff --git a/bot/kodiak/test/fixtures/api/get_event/no_author.json b/bot/kodiak/test/fixtures/api/get_event/no_author.json index 273c1e018..4273f8e89 100644 --- a/bot/kodiak/test/fixtures/api/get_event/no_author.json +++ b/bot/kodiak/test/fixtures/api/get_event/no_author.json @@ -1,46 +1,6 @@ { "data": { "repository": { - "branchProtectionRules": { - "nodes": [ - { - "matchingRefs": { - "nodes": [ - { - "name": "master" - } - ] - }, - "requiresApprovingReviews": true, - "requiredApprovingReviewCount": 2, - "requiresStatusChecks": true, - "requiredStatusCheckContexts": [ - "ci/circleci: backend_lint", - "ci/circleci: backend_test", - "ci/circleci: frontend_lint", - "ci/circleci: frontend_test", - "WIP (beta)" - ], - "requiresStrictStatusChecks": true, - "requiresCodeOwnerReviews": false, - "requiresCommitSignatures": false, - "requiresConversationResolution": false, - "restrictsPushes": true, - "pushAllowances": { - "nodes": [ - { - "actor": {} - }, - { - "actor": { - "databaseId": 53453 - } - } - ] - } - } - ] - }, "mergeCommitAllowed": false, "rebaseMergeAllowed": false, "squashMergeAllowed": true, diff --git a/bot/kodiak/test_queries.py b/bot/kodiak/test_queries.py index 639990249..dfc26274d 100644 --- a/bot/kodiak/test_queries.py +++ b/bot/kodiak/test_queries.py @@ -88,22 +88,76 @@ async def test_get_config_for_ref_dot_github( api_client, "send_query", return_value=wrap_future( - dict( - data=dict( - repository=dict( - rootConfigFile=None, - githubConfigFile=dict( - text="# .github/.kodiak.toml\nversion = 1\nmerge.method = 'rebase'" - ), - ) - ) - ) + { + "data": { + "repository": { + "rootConfigFile": None, + "githubConfigFile": { + "text": "# .github/.kodiak.toml\nversion = 1\nmerge.method = 'rebase'" + }, + "refs": { + "edges": [ + { + "node": { + "branchProtectionRule": { + "matchingRefs": { + "nodes": [{"name": "master"}] + }, + "requiresApprovingReviews": True, + "requiredApprovingReviewCount": 2, + "requiresStatusChecks": True, + "requiredStatusCheckContexts": [ + "ci/circleci: backend_lint", + "ci/circleci: backend_test", + "ci/circleci: frontend_lint", + "ci/circleci: frontend_test", + "WIP (beta)", + ], + "requiresStrictStatusChecks": True, + "requiresCodeOwnerReviews": False, + "requiresCommitSignatures": False, + "requiresConversationResolution": False, + "restrictsPushes": True, + "pushAllowances": { + "nodes": [ + {"actor": {}}, + {"actor": {"databaseId": 53453}}, + ] + }, + } + } + } + ] + }, + } + } + } ), ) res = await api_client.get_config_for_ref(ref="main", org_repo_default_branch=None) assert res is not None assert isinstance(res.parsed, V1) and res.parsed.merge.method == MergeMethod.rebase + assert res.branch_protection == BranchProtectionRule( + requiresStatusChecks=True, + requiredStatusCheckContexts=[ + "ci/circleci: backend_lint", + "ci/circleci: backend_test", + "ci/circleci: frontend_lint", + "ci/circleci: frontend_test", + "WIP (beta)", + ], + requiresStrictStatusChecks=True, + requiresCommitSignatures=False, + requiresConversationResolution=False, + restrictsPushes=True, + pushAllowances=NodeListPushAllowance( + nodes=[ + PushAllowance(actor=PushAllowanceActor(databaseId=None)), + PushAllowance(actor=PushAllowanceActor(databaseId=53453)), + ] + ), + ) @pytest.fixture @@ -157,26 +211,6 @@ def block_event() -> EventInfoResponse: delete_branch_on_merge=True, is_private=True, ) - branch_protection = BranchProtectionRule( - requiresStatusChecks=True, - requiredStatusCheckContexts=[ - "ci/circleci: backend_lint", - "ci/circleci: backend_test", - "ci/circleci: frontend_lint", - "ci/circleci: frontend_test", - "WIP (beta)", - ], - requiresStrictStatusChecks=True, - requiresCommitSignatures=False, - requiresConversationResolution=False, - restrictsPushes=True, - pushAllowances=NodeListPushAllowance( - nodes=[ - PushAllowance(actor=PushAllowanceActor(databaseId=None)), - PushAllowance(actor=PushAllowanceActor(databaseId=53453)), - ] - ), - ) return EventInfoResponse( config=config, @@ -192,7 +226,7 @@ def block_event() -> EventInfoResponse: subscription=Subscription( account_id="D1606A79-A1A1-4550-BA7B-C9ED0D792B1E", subscription_blocker=None ), - branch_protection=branch_protection, + branch_protection=None, review_requests=[ PRReviewRequest(name="ghost"), PRReviewRequest(name="ghost-team"),