Beispiel #1
0
    def test_does_not_add_warning_if_no_label(self, add_pr_comment_mock,
                                              edit_pr_title_mock):
        pull_request = build(builder.pull_request())

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        add_pr_comment_mock.assert_not_called()
Beispiel #2
0
    def test_noop_if_feature_not_enabled(self, add_pr_comment_mock,
                                         edit_pr_title_mock):
        pull_request = build(builder.pull_request().label(builder.label().name(
            github_logic.AutomergeLabel.AFTER_TESTS_AND_APPROVAL.value)))

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        add_pr_comment_mock.assert_not_called()
Beispiel #3
0
    def test_does_not_add_warning_comment_if_label_does_not_require_approval(
            self, add_pr_comment_mock, edit_pr_title_mock):
        pull_request = build(builder.pull_request().title(
            self.SAMPLE_PR_TITLE).label(builder.label().name(
                github_logic.AutomergeLabel.AFTER_TESTS.value)))

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        add_pr_comment_mock.assert_not_called()
Beispiel #4
0
def _handle_pull_request_webhook(payload: dict) -> HttpResponse:
    pull_request_id = payload["pull_request"]["node_id"]
    with dynamodb_lock(pull_request_id):
        pull_request = graphql_client.get_pull_request(pull_request_id)
        # a label change will trigger this webhook, so it may trigger automerge
        github_logic.maybe_automerge_pull_request(pull_request)
        github_logic.maybe_add_automerge_warning_comment(pull_request)
        github_controller.upsert_pull_request(pull_request)
        return HttpResponse("200")
Beispiel #5
0
    def test_does_not_add_warning_comment_if_pr_is_approved(
            self, add_pr_comment_mock, edit_pr_title_mock):
        pull_request = build(builder.pull_request().title(
            self.SAMPLE_PR_TITLE).label(builder.label().name(
                github_logic.AutomergeLabel.AFTER_TESTS_AND_APPROVAL.value
            )).review(
                builder.review().submitted_at("2020-01-13T14:59:58Z").state(
                    ReviewState.APPROVED)))

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        add_pr_comment_mock.assert_not_called()
Beispiel #6
0
    def test_does_not_add_warning_if_has_label_and_already_has_warning_in_comments(
            self, add_pr_comment_mock, edit_pr_title_mock):
        pull_request = build(builder.pull_request().comments([
            builder.comment().author(
                builder.user("github_unknown_user_login")).body(
                    github_logic.AUTOMERGE_COMMENT_WARNING)
        ]).label(builder.label().name(
            github_logic.AutomergeLabel.AFTER_TESTS_AND_APPROVAL.value)))

        github_logic.maybe_add_automerge_warning_comment(pull_request)

        edit_pr_title_mock.assert_not_called()
        add_pr_comment_mock.assert_not_called()
Beispiel #7
0
    def test_adds_warnings_if_label_and_no_warning_in_comments(
            self, add_pr_comment_mock, edit_pr_title_mock):
        for label in [
                github_logic.AutomergeLabel.AFTER_TESTS_AND_APPROVAL.value,
                github_logic.AutomergeLabel.AFTER_APPROVAL.value,
        ]:
            pull_request = build(builder.pull_request().title(
                self.SAMPLE_PR_TITLE).label(builder.label().name(label)))

            github_logic.maybe_add_automerge_warning_comment(pull_request)

            add_pr_comment_mock.assert_called_with(
                pull_request.repository_owner_handle(),
                pull_request.repository_name(),
                pull_request.number(),
                github_logic.AUTOMERGE_COMMENT_WARNING,
            )