Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notifications): missing branch protection notifications #78

Merged
merged 9 commits into from
Jul 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion kodiak/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import typing
from collections import defaultdict
from typing import Optional

import structlog

Expand Down Expand Up @@ -100,7 +101,7 @@ def review_status(reviews: typing.List[PRReview]) -> PRReviewState:
def mergeable(
config: config.V1,
pull_request: PullRequest,
branch_protection: BranchProtectionRule,
branch_protection: Optional[BranchProtectionRule],
review_requests_count: int,
reviews: typing.List[PRReview],
contexts: typing.List[StatusContext],
Expand All @@ -125,6 +126,11 @@ def mergeable(
if config.app_id is not None and config.app_id != app_id:
raise MissingAppID("missing required app_id")

if branch_protection is None:
raise NotQueueable(
f"missing branch protection for baseRef: {pull_request.baseRefName!r}"
)

if config.merge.automerge_label not in pull_request.labels:
raise NotQueueable(
f"missing automerge_label: {repr(config.merge.automerge_label)}"
Expand Down
6 changes: 2 additions & 4 deletions kodiak/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dataclasses import dataclass, field
from datetime import datetime, timedelta, timezone
from enum import Enum
from typing import Optional

import arrow
import jwt
Expand Down Expand Up @@ -219,7 +220,7 @@ class EventInfoResponse:
config: V1
pull_request: PullRequest
repo: RepoInfo
branch_protection: BranchProtectionRule
branch_protection: Optional[BranchProtectionRule]
review_requests_count: int
head_exists: bool
reviews: typing.List[PRReview] = field(default_factory=list)
Expand Down Expand Up @@ -603,9 +604,6 @@ async def get_event_info(
branch_protection = get_branch_protection(
repo=repository, ref_name=pr.baseRefName
)
if branch_protection is None:
log.warning("Could not find branch protection")
return None

return EventInfoResponse(
config=config,
Expand Down
23 changes: 22 additions & 1 deletion kodiak/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_blacklist_title_match(
context: StatusContext,
) -> None:
# a PR with a blacklisted title should not be mergeable
with pytest.raises(NotQueueable, match="blacklist_title"):
with pytest.raises(NotQueueable, match="blacklist_title") as e_info:
config.merge.blacklist_title_regex = "^WIP:.*"
pull_request.title = "WIP: add fleeb to plumbus"
mergeable(
Expand All @@ -146,6 +146,7 @@ def test_blacklist_title_match(
valid_signature=False,
valid_merge_methods=[MergeMethod.merge, MergeMethod.squash],
)
assert config.merge.blacklist_title_regex in str(e_info.value)


def test_bad_merge_method_config(
Expand Down Expand Up @@ -892,3 +893,23 @@ def test_merge_state_status_draft(
valid_signature=False,
valid_merge_methods=[MergeMethod.squash],
)


def test_missing_branch_protection(pull_request: PullRequest, config: V1) -> None:
"""
We don't want to do anything if branch protection is missing
"""

branch_protection = None
with pytest.raises(NotQueueable, match="missing branch protection"):
mergeable(
config=config,
pull_request=pull_request,
branch_protection=branch_protection,
review_requests_count=0,
reviews=[],
contexts=[],
check_runs=[],
valid_signature=False,
valid_merge_methods=[MergeMethod.squash],
)