Skip to content

Commit

Permalink
fmt and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
chdsbd committed Jun 20, 2024
1 parent 20f3809 commit 3877a8a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 76 deletions.
9 changes: 4 additions & 5 deletions bot/kodiak/queries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
40 changes: 0 additions & 40 deletions bot/kodiak/test/fixtures/api/get_event/no_author.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
96 changes: 65 additions & 31 deletions bot/kodiak/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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"),
Expand Down

0 comments on commit 3877a8a

Please sign in to comment.