Ejemplo n.º 1
0
def a_pull_request() -> github_types.GitHubPullRequest:
    gh_owner = github_types.GitHubAccount(
        {
            "login": github_types.GitHubLogin("user"),
            "id": github_types.GitHubAccountIdType(0),
            "type": "User",
            "avatar_url": "",
        }
    )

    gh_repo = github_types.GitHubRepository(
        {
            "archived": False,
            "url": "",
            "html_url": "",
            "default_branch": github_types.GitHubRefType(""),
            "id": github_types.GitHubRepositoryIdType(456),
            "full_name": "user/repo",
            "name": github_types.GitHubRepositoryName("repo"),
            "private": False,
            "owner": gh_owner,
        }
    )

    return github_types.GitHubPullRequest(
        {
            "node_id": "42",
            "locked": False,
            "assignees": [],
            "requested_reviewers": [],
            "requested_teams": [],
            "milestone": None,
            "title": "",
            "updated_at": github_types.ISODateTimeType("2021-06-01T18:41:39Z"),
            "created_at": github_types.ISODateTimeType("2021-06-01T18:41:39Z"),
            "closed_at": None,
            "id": github_types.GitHubPullRequestId(0),
            "maintainer_can_modify": False,
            "rebaseable": False,
            "draft": False,
            "merge_commit_sha": None,
            "labels": [],
            "number": github_types.GitHubPullRequestNumber(6),
            "commits": 1,
            "merged": True,
            "state": "closed",
            "changed_files": 1,
            "html_url": "<html_url>",
            "base": {
                "label": "",
                "sha": github_types.SHAType("sha"),
                "user": {
                    "login": github_types.GitHubLogin("user"),
                    "id": github_types.GitHubAccountIdType(0),
                    "type": "User",
                    "avatar_url": "",
                },
                "ref": github_types.GitHubRefType("ref"),
                "repo": gh_repo,
            },
            "head": {
                "label": "",
                "sha": github_types.SHAType("old-sha-one"),
                "ref": github_types.GitHubRefType("fork"),
                "user": {
                    "login": github_types.GitHubLogin("user"),
                    "id": github_types.GitHubAccountIdType(0),
                    "type": "User",
                    "avatar_url": "",
                },
                "repo": {
                    "archived": False,
                    "url": "",
                    "html_url": "",
                    "default_branch": github_types.GitHubRefType(""),
                    "id": github_types.GitHubRepositoryIdType(123),
                    "full_name": "fork/other",
                    "name": github_types.GitHubRepositoryName("other"),
                    "private": False,
                    "owner": {
                        "login": github_types.GitHubLogin("user"),
                        "id": github_types.GitHubAccountIdType(0),
                        "type": "User",
                        "avatar_url": "",
                    },
                },
            },
            "user": {
                "login": github_types.GitHubLogin("user"),
                "id": github_types.GitHubAccountIdType(0),
                "type": "User",
                "avatar_url": "",
            },
            "merged_by": None,
            "merged_at": None,
            "mergeable_state": "clean",
            "mergeable": True,
            "body": None,
        }
    )
Ejemplo n.º 2
0
        "name": github_types.GitHubRepositoryName("name"),
        "private": False,
        "owner": GH_OWNER,
    }
)
GH_PULL = github_types.GitHubPullRequest(
    {
        "node_id": "42",
        "locked": False,
        "assignees": [],
        "requested_reviewers": [],
        "requested_teams": [],
        "milestone": None,
        "title": "",
        "body": "",
        "updated_at": github_types.ISODateTimeType("2021-06-01T18:41:39Z"),
        "created_at": github_types.ISODateTimeType("2021-06-01T18:41:39Z"),
        "closed_at": None,
        "id": github_types.GitHubPullRequestId(0),
        "maintainer_can_modify": False,
        "rebaseable": False,
        "draft": False,
        "merge_commit_sha": github_types.SHAType("base-sha"),
        "labels": [],
        "number": github_types.GitHubPullRequestNumber(6),
        "merged": False,
        "commits": 1,
        "state": "open",
        "html_url": "<html_url>",
        "base": {
            "label": "",
Ejemplo n.º 3
0
async def test_cleanup_pending_actions_with_no_associated_rules(
    context_getter: conftest.ContextGetterFixture,
) -> None:

    ctxt = await context_getter(42)

    previous_conclusions = {
        "Rule: title contains cleanup (label)": check_api.Conclusion.CANCELLED,
        "Rule: ask to resolve conflict (comment)": check_api.Conclusion.NEUTRAL,
        "Rule: title contains Helm (label)": check_api.Conclusion.CANCELLED,
        "Rule: remove outdated approvals (queue)": check_api.Conclusion.PENDING,
        "Rule: title contains build (label)": check_api.Conclusion.CANCELLED,
        "Rule: automatic merge (queue)": check_api.Conclusion.NEUTRAL,
        "Rule: title contains rebase (label)": check_api.Conclusion.CANCELLED,
        "Rule: title contains CI, testing or e2e (label)": check_api.Conclusion.CANCELLED,
        "Rule: automatic merge (delete_head_branch)": check_api.Conclusion.NEUTRAL,
        "Rule: title contains DNM (label)": check_api.Conclusion.CANCELLED,
        "Rule: title contains CephFS (label)": check_api.Conclusion.CANCELLED,
        "Rule: title contains doc (label)": check_api.Conclusion.SUCCESS,
        "Rule: automatic merge PR having ready-to-merge label (delete_head_branch)": check_api.Conclusion.NEUTRAL,
        "Rule: automatic merge PR having ready-to-merge label (dismiss_reviews)": check_api.Conclusion.CANCELLED,
        "Rule: title indicates a bug fix (label)": check_api.Conclusion.CANCELLED,
        "Rule: backport patches to release-v3.4 branch (backport)": check_api.Conclusion.NEUTRAL,
        "Rule: title contains RBD (label)": check_api.Conclusion.CANCELLED,
        "Rule: ask to resolve conflict (queue)": check_api.Conclusion.NEUTRAL,
        "Rule: automatic merge PR having ready-to-merge label (queue)": check_api.Conclusion.NEUTRAL,
        "Rule: title contains Mergify (label)": check_api.Conclusion.CANCELLED,
        "Rule: automatic merge (dismiss_reviews)": check_api.Conclusion.CANCELLED,
        "Rule: remove outdated approvals (dismiss_reviews)": check_api.Conclusion.SUCCESS,
    }
    current_conclusions = {
        "Rule: title indicates a bug fix (label)": check_api.Conclusion.CANCELLED,
        "Rule: title contains doc (label)": check_api.Conclusion.SUCCESS,
        "Rule: backport patches to release-v3.4 branch (backport)": check_api.Conclusion.NEUTRAL,
        "Rule: title contains rebase (label)": check_api.Conclusion.CANCELLED,
        "Rule: title contains build (label)": check_api.Conclusion.CANCELLED,
        "Rule: title contains RBD (label)": check_api.Conclusion.CANCELLED,
        "Rule: automatic merge (queue)": check_api.Conclusion.NEUTRAL,
        "Rule: title contains Mergify (label)": check_api.Conclusion.CANCELLED,
        "Rule: title contains cleanup (label)": check_api.Conclusion.CANCELLED,
        "Rule: automatic merge PR having ready-to-merge label (delete_head_branch)": check_api.Conclusion.NEUTRAL,
        "Rule: automatic merge PR having ready-to-merge label (queue)": check_api.Conclusion.NEUTRAL,
        "Rule: automatic merge PR having ready-to-merge label (dismiss_reviews)": check_api.Conclusion.CANCELLED,
        "Rule: ask to resolve conflict (comment)": check_api.Conclusion.NEUTRAL,
        "Rule: automatic merge (dismiss_reviews)": check_api.Conclusion.CANCELLED,
        "Rule: title contains CephFS (label)": check_api.Conclusion.CANCELLED,
        "Rule: automatic merge (delete_head_branch)": check_api.Conclusion.NEUTRAL,
        "Rule: title contains DNM (label)": check_api.Conclusion.CANCELLED,
        "Rule: title contains CI, testing or e2e (label)": check_api.Conclusion.CANCELLED,
        "Rule: remove outdated approvals (dismiss_reviews)": check_api.Conclusion.SUCCESS,
        "Rule: title contains Helm (label)": check_api.Conclusion.CANCELLED,
    }
    checks = [
        github_types.CachedGitHubCheckRun(
            name=check,
            id=1,
            app_id=config.INTEGRATION_ID,
            app_name="mergify",
            app_avatar_url="",
            external_id="",
            head_sha=github_types.SHAType("azertyio"),
            status="in_progress",
            output={
                "title": "",
                "summary": "",
                "text": None,
                "annotations_count": 0,
                "annotations": [],
                "annotations_url": "",
            },
            conclusion=None,
            completed_at=github_types.ISODateTimeType(""),
            html_url="",
        )
        for check, state in previous_conclusions.items()
        if state == check_api.Conclusion.PENDING
    ]
    ctxt._caches.pull_check_runs.set(checks)
    with (
        mock.patch.object(merge_train.Train, "force_remove_pull") as force_remove_pull,
        mock.patch.object(check_api, "set_check_run") as set_check_run,
    ):
        await actions_runner.cleanup_pending_actions_with_no_associated_rules(
            ctxt, current_conclusions, previous_conclusions
        )
        assert set_check_run.called
        assert force_remove_pull.called
Ejemplo n.º 4
0
 "title":
 "",
 "body":
 "",
 "number":
 github_types.GitHubPullRequestNumber(0),
 "html_url":
 "",
 "id":
 github_types.GitHubPullRequestId(0),
 "maintainer_can_modify":
 False,
 "state":
 "open",
 "created_at":
 github_types.ISODateTimeType("2021-06-01T18:41:39Z"),
 "updated_at":
 github_types.ISODateTimeType("2021-06-01T18:41:39Z"),
 "merged":
 False,
 "merged_by":
 None,
 "merged_at":
 None,
 "closed_at":
 None,
 "draft":
 False,
 "merge_commit_sha":
 None,
 "commits":
Ejemplo n.º 5
0
async def build_fake_context(
    number: github_types.GitHubPullRequestNumber,
    *,
    repository: context.Repository,
    **kwargs: typing.Dict[str, typing.Any],
) -> context.Context:
    pull_request_author = github_types.GitHubAccount(
        {
            "id": github_types.GitHubAccountIdType(123),
            "type": "User",
            "login": github_types.GitHubLogin("contributor"),
            "avatar_url": "",
        }
    )

    pull: github_types.GitHubPullRequest = {
        "node_id": "42",
        "locked": False,
        "assignees": [],
        "requested_reviewers": [
            {
                "id": github_types.GitHubAccountIdType(123),
                "type": "User",
                "login": github_types.GitHubLogin("jd"),
                "avatar_url": "",
            },
            {
                "id": github_types.GitHubAccountIdType(456),
                "type": "User",
                "login": github_types.GitHubLogin("sileht"),
                "avatar_url": "",
            },
        ],
        "requested_teams": [
            {"slug": github_types.GitHubTeamSlug("foobar")},
            {"slug": github_types.GitHubTeamSlug("foobaz")},
        ],
        "milestone": None,
        "title": "awesome",
        "body": "",
        "created_at": github_types.ISODateTimeType("2021-06-01T18:41:39Z"),
        "closed_at": None,
        "updated_at": github_types.ISODateTimeType("2021-06-01T18:41:39Z"),
        "id": github_types.GitHubPullRequestId(123),
        "maintainer_can_modify": True,
        "user": pull_request_author,
        "labels": [],
        "rebaseable": True,
        "draft": False,
        "merge_commit_sha": None,
        "number": number,
        "commits": 1,
        "mergeable_state": "clean",
        "mergeable": True,
        "state": "open",
        "changed_files": 1,
        "head": {
            "sha": github_types.SHAType("the-head-sha"),
            "label": f"{pull_request_author['login']}:feature-branch",
            "ref": github_types.GitHubRefType("feature-branch"),
            "repo": {
                "id": github_types.GitHubRepositoryIdType(123),
                "default_branch": github_types.GitHubRefType("main"),
                "name": github_types.GitHubRepositoryName("mergify-engine"),
                "full_name": "contributor/mergify-engine",
                "archived": False,
                "private": False,
                "owner": pull_request_author,
                "url": "https://api.github.com/repos/contributor/mergify-engine",
                "html_url": "https://github.com/contributor/mergify-engine",
            },
            "user": pull_request_author,
        },
        "merged": False,
        "merged_by": None,
        "merged_at": None,
        "html_url": "https://...",
        "base": {
            "label": "mergify_engine:main",
            "ref": github_types.GitHubRefType("main"),
            "repo": repository.repo,
            "sha": github_types.SHAType("the-base-sha"),
            "user": repository.repo["owner"],
        },
    }
    pull.update(kwargs)  # type: ignore
    return await context.Context.create(repository, pull)