Пример #1
0
async def test_mergeable_missing_push_allowance_correct() -> None:
    """
    When restrictsPushes is enabled, but Kodiak is added as a push allowance, we
    should not raise a configuration error. We should let the merge continue
    unimpeded.
    """
    api = create_api()
    mergeable = create_mergeable()
    branch_protection = create_branch_protection()
    branch_protection.restrictsPushes = True
    branch_protection.pushAllowances = NodeListPushAllowance(
        nodes=[PushAllowance(actor=PushAllowanceActor(databaseId=534524))])
    await mergeable(api=api, branch_protection=branch_protection)
    assert api.queue_for_merge.called is True

    assert api.dequeue.call_count == 0
    assert api.update_branch.called is False
    assert api.merge.called is False
Пример #2
0
async def test_mergeable_missing_push_allowance_correct_null_database_id(
) -> None:
    """
    Verify we can handle a null databaseId for the PushAllowanceActor
    """
    api = create_api()
    mergeable = create_mergeable()
    branch_protection = create_branch_protection()
    branch_protection.restrictsPushes = True
    branch_protection.pushAllowances = NodeListPushAllowance(nodes=[
        PushAllowance(actor=PushAllowanceActor(databaseId=None)),
        PushAllowance(actor=PushAllowanceActor(databaseId=534524)),
    ])
    await mergeable(api=api, branch_protection=branch_protection)
    assert api.queue_for_merge.called is True

    assert api.dequeue.call_count == 0
    assert api.update_branch.called is False
    assert api.merge.called is False
Пример #3
0
async def test_mergeable_missing_push_allowance() -> None:
    """
    We should warn when user is missing a push allowance with restrictsPushes
    enabled. If Kodiak isn't given an allowance it won't be able to merge pull
    requests and will get a mysterious "merge blocked by GitHub requirements".
    """
    api = create_api()
    mergeable = create_mergeable()
    branch_protection = create_branch_protection()
    branch_protection.restrictsPushes = True
    branch_protection.pushAllowances = NodeListPushAllowance(nodes=[])
    await mergeable(api=api, branch_protection=branch_protection)
    assert api.set_status.call_count == 1
    assert api.dequeue.call_count == 1
    assert "config error" in api.set_status.calls[0]["msg"]
    assert "missing push allowance for Kodiak" in api.set_status.calls[0][
        "msg"]

    # verify we haven't tried to update/merge the PR
    assert api.update_branch.called is False
    assert api.merge.called is False
    assert api.queue_for_merge.called is False
Пример #4
0
async def test_mergeable_missing_push_allowance_merge_do_not_merge() -> None:
    """
    When merge.do_not_merge is enabled, we should ignore any issues with restrictPushes because Kodiak isn't pushing.
    """
    api = create_api()
    mergeable = create_mergeable()
    branch_protection = create_branch_protection()
    config = create_config()

    branch_protection.restrictsPushes = True
    config.merge.do_not_merge = True
    branch_protection.pushAllowances = NodeListPushAllowance(nodes=[])
    await mergeable(api=api,
                    config=config,
                    branch_protection=branch_protection)

    assert api.set_status.call_count == 1
    assert api.set_status.calls[0]["msg"] == "✅ okay to merge"

    assert api.queue_for_merge.called is False
    assert api.dequeue.call_count == 0
    assert api.update_branch.called is False
    assert api.merge.called is False
Пример #5
0
def create_event() -> EventInfoResponse:
    config = V1(version=1,
                merge=Merge(automerge_label="automerge",
                            method=MergeMethod.squash))
    pr = PullRequest(
        id="e14ff7599399478fb9dbc2dacb87da72",
        number=100,
        author=PullRequestAuthor(login="******", databaseId=49118, type="Bot"),
        mergeStateStatus=MergeStateStatus.BEHIND,
        state=PullRequestState.OPEN,
        isDraft=False,
        mergeable=MergeableState.MERGEABLE,
        isCrossRepository=False,
        labels=["automerge"],
        latest_sha="8d728d017cac4f5ba37533debe65730abe65730a",
        baseRefName="master",
        headRefName="df825f90-9825-424c-a97e-733522027e4c",
        title="Update README.md",
        body="",
        bodyText="",
        bodyHTML="",
        url="https://github.com/delos-corp/hive-mind/pull/324",
    )
    rep_info = RepoInfo(
        merge_commit_allowed=False,
        rebase_merge_allowed=False,
        squash_merge_allowed=True,
        is_private=True,
        delete_branch_on_merge=False,
    )
    branch_protection = BranchProtectionRule(
        requiresApprovingReviews=True,
        requiredApprovingReviewCount=2,
        requiresStatusChecks=True,
        requiredStatusCheckContexts=[
            "ci/circleci: frontend_lint",
            "ci/circleci: frontend_test",
        ],
        requiresStrictStatusChecks=True,
        requiresCodeOwnerReviews=False,
        requiresCommitSignatures=False,
        restrictsPushes=False,
        pushAllowances=NodeListPushAllowance(nodes=[]),
    )

    return EventInfoResponse(
        config=config,
        config_str="""\
version = 1
[merge]
method = "squash"
""",
        config_file_expression="master:.kodiak.toml",
        head_exists=True,
        pull_request=pr,
        repository=rep_info,
        branch_protection=branch_protection,
        review_requests=[],
        reviews=[],
        status_contexts=[],
        check_runs=[],
        valid_signature=True,
        valid_merge_methods=[MergeMethod.squash],
        subscription=None,
    )
Пример #6
0
def block_event() -> EventInfoResponse:
    config = V1(version=1,
                merge=Merge(automerge_label="automerge",
                            method=MergeMethod.squash))
    pr = PullRequest(
        id="e14ff7599399478fb9dbc2dacb87da72",
        number=100,
        author=PullRequestAuthor(login="******", databaseId=49118, type="Bot"),
        mergeStateStatus=MergeStateStatus.BEHIND,
        state=PullRequestState.OPEN,
        mergeable=MergeableState.MERGEABLE,
        isCrossRepository=False,
        labels=["automerge"],
        latest_sha="8d728d017cac4f5ba37533debe65730abe65730a",
        baseRefName="master",
        headRefName="df825f90-9825-424c-a97e-733522027e4c",
        title="Update README.md",
        body="",
        bodyText="",
        bodyHTML="",
        url="https://github.com/delos-corp/hive-mind/pull/324",
    )
    rep_info = RepoInfo(
        merge_commit_allowed=False,
        rebase_merge_allowed=False,
        squash_merge_allowed=True,
        delete_branch_on_merge=True,
        is_private=True,
    )
    branch_protection = BranchProtectionRule(
        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,
        requiresCommitSignatures=False,
        restrictsPushes=True,
        pushAllowances=NodeListPushAllowance(nodes=[
            PushAllowance(actor=PushAllowanceActor(databaseId=None)),
            PushAllowance(actor=PushAllowanceActor(databaseId=53453)),
        ]),
    )

    return EventInfoResponse(
        config=config,
        config_str="""\
version = 1
[merge]
method = "squash"
""",
        config_file_expression="master:.kodiak.toml",
        head_exists=True,
        pull_request=pr,
        repository=rep_info,
        subscription=Subscription(
            account_id="D1606A79-A1A1-4550-BA7B-C9ED0D792B1E",
            subscription_blocker=None),
        branch_protection=branch_protection,
        review_requests=[
            PRReviewRequest(name="ghost"),
            PRReviewRequest(name="ghost-team"),
            PRReviewRequest(name="ghost-mannequin"),
        ],
        reviews=[
            PRReview(
                createdAt=arrow.get("2019-05-22T15:29:34Z").datetime,
                state=PRReviewState.COMMENTED,
                author=PRReviewAuthor(login="******",
                                      permission=Permission.WRITE),
            ),
            PRReview(
                createdAt=arrow.get("2019-05-22T15:29:52Z").datetime,
                state=PRReviewState.CHANGES_REQUESTED,
                author=PRReviewAuthor(login="******",
                                      permission=Permission.WRITE),
            ),
            PRReview(
                createdAt=arrow.get("2019-05-22T15:30:52Z").datetime,
                state=PRReviewState.COMMENTED,
                author=PRReviewAuthor(login="******",
                                      permission=Permission.ADMIN),
            ),
            PRReview(
                createdAt=arrow.get("2019-05-22T15:43:17Z").datetime,
                state=PRReviewState.APPROVED,
                author=PRReviewAuthor(login="******",
                                      permission=Permission.WRITE),
            ),
            PRReview(
                createdAt=arrow.get("2019-05-23T15:13:29Z").datetime,
                state=PRReviewState.APPROVED,
                author=PRReviewAuthor(login="******",
                                      permission=Permission.WRITE),
            ),
            PRReview(
                createdAt=arrow.get("2019-05-24T10:21:32Z").datetime,
                state=PRReviewState.APPROVED,
                author=PRReviewAuthor(login="******",
                                      permission=Permission.WRITE),
            ),
        ],
        status_contexts=[
            StatusContext(context="ci/circleci: backend_lint",
                          state=StatusState.SUCCESS),
            StatusContext(context="ci/circleci: backend_test",
                          state=StatusState.SUCCESS),
            StatusContext(context="ci/circleci: frontend_lint",
                          state=StatusState.SUCCESS),
            StatusContext(context="ci/circleci: frontend_test",
                          state=StatusState.SUCCESS),
        ],
        check_runs=[
            CheckRun(name="WIP (beta)",
                     conclusion=CheckConclusionState.SUCCESS)
        ],
        valid_signature=True,
        valid_merge_methods=[MergeMethod.squash],
    )