コード例 #1
0
def test_dist_git_push_release_handle(github_release_webhook):
    packit_yaml = (
        "{'specfile_path': 'hello-world.spec', 'synced_files': []"
        ", jobs: [{trigger: release, job: propose_downstream, metadata: {targets:[]}}]}"
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
        get_web_url=lambda: "https://github.com/packit-service/hello-world",
        is_private=lambda: False,
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="0.3.0"
    ).once()

    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release)
    )

    results = SteveJobs().process_message(github_release_webhook)
    assert first_dict_value(results["jobs"])["success"]
    assert results["event"]["trigger"] == "release"
コード例 #2
0
def test_process_message(event):
    packit_yaml = {
        "specfile_path": "bar.spec",
        "synced_files": [],
        "jobs": [{"trigger": "release", "job": "propose_downstream"}],
    }

    flexmock(Github, get_repo=lambda full_name_or_id: None)
    flexmock(
        GithubProject,
        get_file_content=lambda path, ref: dumps(packit_yaml),
        full_repo_name="foo/bar",
        get_files=lambda filter_regex: [],
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="1.2.3"
    ).once()
    flexmock(Whitelist, check_and_report=True)
    flexmock(SteveJobs, _is_private=False)

    results = SteveJobs().process_message(event)
    assert "propose_downstream" in results["jobs"]
    assert results["event"]["trigger"] == "release"
コード例 #3
0
def test_dist_git_push_release_handle_multiple_branches(release_event):
    packit_yaml = ("{'specfile_path': 'hello-world.spec', 'synced_files': []"
                   ", jobs: [{trigger: release, job: propose_downstream, "
                   "metadata: {targets:[], dist-git-branch: fedora-all}}]}")
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    flexmock(
        GithubProject,
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        get_files=lambda filter_regex: [],
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    flexmock(SteveJobs, _is_private=False)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="0.3.0").once()

    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f32", version="0.3.0").once()
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f31", version="0.3.0").once()
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f30", version="0.3.0").once()

    flexmock(FedPKG).should_receive("clone").and_return(None)

    results = SteveJobs().process_message(release_event)
    assert results["jobs"]["propose_downstream"]["success"]
    assert results["event"]["trigger"] == "release"
コード例 #4
0
def mock_pr_comment_functionality(request):
    packit_yaml = (
        "{'specfile_path': 'the-specfile.spec', 'synced_files': [], 'jobs': "
        + str(request.param)
        + "}"
    )

    flexmock(
        GithubProject,
        full_repo_name="packit-service/hello-world",
        get_file_content=lambda path, ref: packit_yaml,
        get_files=lambda ref, filter_regex: ["the-specfile.spec"],
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)

    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    trigger = flexmock(
        job_config_trigger_type=JobConfigTriggerType.pull_request, id=123
    )
    flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
    flexmock(PullRequestModel).should_receive("get_by_id").with_args(123).and_return(
        trigger
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Allowlist, check_and_report=True)
コード例 #5
0
def mock_issue_comment_functionality():
    packit_yaml = (
        "{'specfile_path': 'packit.spec', 'synced_files': [],"
        "'jobs': [{'trigger': 'release', 'job': 'propose_downstream',"
        "'metadata': {'dist-git-branch': 'master'}}],"
        "'downstream_package_name': 'packit'}")
    flexmock(
        GithubProject,
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/packit",
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    (flexmock(GithubProject).should_receive("can_merge_pr").with_args(
        "phracek").and_return(True))
    flexmock(GithubProject).should_receive("issue_comment").and_return(None)
    flexmock(GithubProject).should_receive("issue_close").and_return(None)
    gr = GithubRelease(
        tag_name="0.5.1",
        url="packit-service/packit",
        created_at="",
        tarball_url="https://foo/bar",
        git_tag=flexmock(GitTag),
        project=flexmock(GithubProject),
        raw_release=flexmock(PyGithubRelease),
    )
    flexmock(GithubProject).should_receive("get_releases").and_return([gr])
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
コード例 #6
0
def test_handler_cleanup(tmp_path, trick_p_s_with_k8s):
    tmp_path.joinpath("a").mkdir()
    tmp_path.joinpath("b").write_text("a")
    tmp_path.joinpath("c").symlink_to("b")
    tmp_path.joinpath("d").symlink_to("a", target_is_directory=True)
    tmp_path.joinpath("e").symlink_to("nope", target_is_directory=False)
    tmp_path.joinpath("f").symlink_to("nopez", target_is_directory=True)
    tmp_path.joinpath(".g").write_text("g")
    tmp_path.joinpath(".h").symlink_to(".g", target_is_directory=False)

    c = ServiceConfig()
    pc = flexmock(PackageConfig)
    c.command_handler_work_dir = tmp_path
    jc = JobConfig(
        type=JobType.copr_build,
        trigger=JobConfigTriggerType.pull_request,
        metadata=JobMetadataConfig(),
    )
    j = JobHandler(
        package_config=pc,
        job_config=jc,
        event={},
    )

    flexmock(j).should_receive("service_config").and_return(c)

    j._clean_workplace()

    assert len(list(tmp_path.iterdir())) == 0
コード例 #7
0
def test_installation():
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)

    flexmock(InstallationModel).should_receive("create").once()
    flexmock(Allowlist).should_receive("add_namespace").with_args(
        "github.com/packit-service", "jpopelka").and_return(False)
    flexmock(GithubProject).should_receive("create_issue").once()

    flexmock(Signature).should_receive("apply_async").once()
    flexmock(Pushgateway).should_receive("push").once().and_return()
    processing_results = SteveJobs().process_message(installation_event())
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results)
    assert json.dumps(event_dict)

    results = run_installation_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job_config,
    )

    assert first_dict_value(results["job"])["success"]
コード例 #8
0
def test_process_message(event):
    packit_yaml = {
        "specfile_path": "bar.spec",
        "synced_files": [],
        "jobs": [{
            "trigger": "release",
            "job": "propose_downstream"
        }],
    }

    flexmock(Github, get_repo=lambda full_name_or_id: None)
    flexmock(
        GithubProject,
        get_file_content=lambda path, ref: dumps(packit_yaml),
        full_repo_name="foo/bar",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "12345",
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
        is_private=lambda: False,
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="1.2.3").once()
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release))
    flexmock(Whitelist, check_and_report=True)
    results = SteveJobs().process_message(event)
    j = first_dict_value(results["jobs"])
    assert "propose_downstream" in next(iter(results["jobs"]))
    assert j["success"]
    assert results["event"]["trigger"] == "release"
コード例 #9
0
def test_pr_test_command_handler(pr_embedded_command_comment_event):
    jobs = [{
        "trigger": "pull_request",
        "job": "tests",
        "metadata": {
            "targets": "fedora-rawhide-x86_64"
        },
    }]
    packit_yaml = (
        "{'specfile_path': 'the-specfile.spec', 'synced_files': [], 'jobs': " +
        str(jobs) + "}")
    flexmock(
        GithubProject,
        full_repo_name="packit-service/hello-world",
        get_file_content=lambda path, ref: packit_yaml,
        get_files=lambda ref, filter_regex: ["the-specfile.spec"],
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
        get_pr=lambda pr_id: flexmock(head_commit="12345"),
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)

    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    trigger = flexmock(
        job_config_trigger_type=JobConfigTriggerType.pull_request, id=123)
    flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(
        trigger)
    flexmock(PullRequestModel).should_receive("get_by_id").with_args(
        123).and_return(trigger)
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Allowlist, check_and_report=True)
    flexmock(PullRequestModel).should_receive("get_or_create").with_args(
        pr_id=9,
        namespace="packit-service",
        repo_name="hello-world",
        project_url="https://github.com/packit-service/hello-world",
    ).and_return(
        flexmock(id=9,
                 job_config_trigger_type=JobConfigTriggerType.pull_request))
    pr_embedded_command_comment_event["comment"]["body"] = "/packit test"
    flexmock(GithubProject, get_files="foo.spec")
    flexmock(GithubProject).should_receive("is_private").and_return(False)
    flexmock(Signature).should_receive("apply_async").once()
    flexmock(TestingFarmJobHelper).should_receive(
        "run_testing_farm_on_all").and_return(
            TaskResults(success=True, details={}))

    processing_results = SteveJobs().process_message(
        pr_embedded_command_comment_event)
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results)

    run_testing_farm_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job_config,
    )
コード例 #10
0
def test_dist_git_push_release_handle_one_failed(
    github_release_webhook, fedora_branches
):
    packit_yaml = (
        "{'specfile_path': 'hello-world.spec', 'synced_files': []"
        ", jobs: [{trigger: release, job: propose_downstream, "
        "metadata: {targets:[], dist-git-branch: fedora-all}}]}"
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = (
        flexmock(
            get_file_content=lambda path, ref: packit_yaml,
            full_repo_name="packit-service/hello-world",
            repo="hello-world",
            get_files=lambda ref, filter_regex: [],
            get_sha_from_tag=lambda tag_name: "123456",
            get_web_url=lambda: "https://github.com/packit/hello-world",
            is_private=lambda: False,
        )
        .should_receive("create_issue")
        .once()
        .mock()
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    # it would make sense to make LocalProject offline
    for i, branch in enumerate(fedora_branches):
        sync_release = (
            flexmock(PackitAPI)
            .should_receive("sync_release")
            .with_args(dist_git_branch=branch, version="0.3.0")
            .once()
        )
        if i == 1:
            sync_release.and_raise(Exception, f"Failed {branch}").once()

    flexmock(FedPKG).should_receive("clone").and_return(None)

    flexmock(sentry_integration).should_receive("send_to_sentry").and_return().once()
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=123)
    )

    flexmock(Signature).should_receive("apply_async").once()
    processing_results = SteveJobs().process_message(github_release_webhook)
    assert processing_results["details"]["event"]["trigger"] == "release"
    event_dict, package_config, job = get_parameters_from_results(processing_results)

    results = run_propose_downstream_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job,
    )
    assert not first_dict_value(results["job"])["success"]
コード例 #11
0
def test_dist_git_push_release_handle_all_failed(github_release_webhook,
                                                 fedora_branches):
    packit_yaml = ("{'specfile_path': 'hello-world.spec', 'synced_files': []"
                   ", jobs: [{trigger: release, job: propose_downstream, "
                   "metadata: {targets:[], dist-git-branch: fedora-all}}]}")
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    table_content = ""
    for branch in fedora_branches:
        table_content += f"| `{branch}` | `Failed` |\n"
    project = (flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
        get_web_url=lambda: "https://github.com/packit/hello-world",
        is_private=lambda: False,
        default_branch="main",
    ).should_receive("create_issue").with_args(
        title="[packit] Propose downstream failed for release 0.3.0",
        body="Packit failed on creating pull-requests in dist-git:\n\n"
        "| dist-git branch | error |\n"
        "| --------------- | ----- |\n"
        f"{table_content}\n\n"
        "You can retrigger the update by adding a comment (`/packit propose-downstream`)"
        " into this issue.\n",
    ).once().mock())
    lp = flexmock(LocalProject, refresh_the_arguments=lambda: None)
    lp.git_project = project
    flexmock(DistGit).should_receive("local_project").and_return(lp)

    flexmock(Allowlist, check_and_report=True)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").and_raise(
        Exception, "Failed").times(len(fedora_branches))
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=123))

    flexmock(sentry_integration).should_receive(
        "send_to_sentry").and_return().times(len(fedora_branches))
    flexmock(Signature).should_receive("apply_async").once()

    processing_results = SteveJobs().process_message(github_release_webhook)
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results)

    results = run_propose_downstream_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job_config,
    )
    assert not first_dict_value(results["job"])["success"]
コード例 #12
0
def test_process_message(event, private, enabled_private_namespaces, success):
    packit_yaml = {
        "specfile_path": "bar.spec",
        "synced_files": [],
        "jobs": [{
            "trigger": "release",
            "job": "propose_downstream"
        }],
    }
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    gh_project = flexmock(
        GithubProject,
        get_file_content=lambda path, ref: dumps(packit_yaml),
        full_repo_name="the-namespace/the-repo",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "12345",
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
        is_private=lambda: private,
    )
    gh_project.default_branch = "main"

    lp = flexmock(LocalProject, refresh_the_arguments=lambda: None)
    lp.git_project = gh_project
    flexmock(DistGit).should_receive("local_project").and_return(lp)

    config = ServiceConfig(
        enabled_private_namespaces=enabled_private_namespaces)
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)

    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="main", tag="1.2.3").times(1 if success else 0)

    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=1))
    flexmock(Allowlist, check_and_report=True)
    flexmock(Signature).should_receive("apply_async").times(
        1 if success else 0)

    processing_results = SteveJobs().process_message(event)
    if not success:
        assert processing_results == []
        return

    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results)

    results = run_propose_downstream_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job_config,
    )
    assert "propose_downstream" in next(iter(results["job"]))
    assert first_dict_value(results["job"])["success"]
コード例 #13
0
def test_dont_retry_propose_downstream_task(github_release_webhook):
    packit_yaml = (
        "{'specfile_path': 'hello-world.spec', 'synced_files': []"
        ", jobs: [{trigger: release, job: propose_downstream, metadata: {targets:[]}}]}"
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
        get_web_url=lambda: "https://github.com/packit/hello-world",
        is_private=lambda: False,
        default_branch="main",
    )

    lp = flexmock(LocalProject, refresh_the_arguments=lambda: None)
    lp.git_project = project
    flexmock(DistGit).should_receive("local_project").and_return(lp)

    flexmock(Allowlist, check_and_report=True)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline

    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=123))
    flexmock(Signature).should_receive("apply_async").once()

    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="main", tag="0.3.0").and_raise(
            RebaseHelperError,
            "Failed to download file from URL example.com").once()
    flexmock(Context, retries=2)
    flexmock(Task).should_receive("retry").never()
    flexmock(project).should_receive("create_issue").once()

    processing_results = SteveJobs().process_message(github_release_webhook)
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results)

    results = run_propose_downstream_handler(event_dict, package_config,
                                             job_config)

    assert not first_dict_value(results["job"])["success"]
コード例 #14
0
def mock_comment(request):
    project_class, release_class, forge, author = request.param

    packit_yaml = (
        "{'specfile_path': 'packit.spec', 'synced_files': [],"
        "'jobs': [{'trigger': 'release', 'job': 'propose_downstream',"
        "'metadata': {'dist-git-branch': 'main'}}],"
        "'downstream_package_name': 'packit'}"
    )
    flexmock(
        project_class,
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/packit",
        get_web_url=lambda: f"https://{forge}.com/packit-service/packit",
        default_branch="main",
    )
    (
        flexmock(project_class)
        .should_receive("can_merge_pr")
        .with_args(author)
        .and_return(True)
    )
    issue = flexmock()
    flexmock(project_class).should_receive("get_issue").and_return(issue)
    comment = flexmock()
    flexmock(issue).should_receive("get_comment").and_return(comment)
    flexmock(comment).should_receive("add_reaction").with_args("+1").once()
    flexmock(issue).should_receive("close").and_return(issue)
    gr = release_class(
        tag_name="0.5.1",
        url="packit-service/packit",
        created_at="",
        tarball_url="https://foo/bar",
        git_tag=flexmock(GitTag),
        project=flexmock(project_class),
        raw_release=flexmock(),
    )
    flexmock(project_class).should_receive("get_latest_release").and_return(gr)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    lp = flexmock(git_project=flexmock(default_branch="main"))
    lp.working_dir = ""
    flexmock(DistGit).should_receive("local_project").and_return(lp)
    flexmock(Allowlist, check_and_report=True)

    yield project_class, issue_comment_propose_downstream_event(forge)
コード例 #15
0
def mock_pr_comment_functionality(request):
    packit_yaml = ("{'specfile_path': '', 'synced_files': [], 'jobs': " +
                   str(request.param) + "}")
    flexmock(
        GithubProject,
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)

    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)

    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
コード例 #16
0
def test_dist_git_push_release_handle_all_failed(release_event):
    packit_yaml = ("{'specfile_path': 'hello-world.spec', 'synced_files': []"
                   ", jobs: [{trigger: release, job: propose_downstream, "
                   "metadata: {targets:[], dist-git-branch: fedora-all}}]}")
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = (flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
    ).should_receive("create_issue").with_args(
        title="[packit] Propose update failed for release 0.3.0",
        body="Packit failed on creating pull-requests in dist-git:\n\n"
        "| dist-git branch | error |\n"
        "| --------------- | ----- |\n"
        "| `f30` | `Failed` |\n"
        "| `f31` | `Failed` |\n"
        "| `f32` | `Failed` |\n"
        "| `master` | `Failed` |\n\n\n"
        "You can re-trigger the update by adding `/packit propose-update`"
        " to the issue comment.\n",
    ).once().mock())
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    flexmock(SteveJobs, _is_private=False)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").and_raise(
        Exception, "Failed").times(4)
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release))

    # 4 = master, f32, 31, 30
    flexmock(sentry_integration).should_receive(
        "send_to_sentry").and_return().times(4)

    results = SteveJobs().process_message(release_event)
    assert not results["jobs"]["propose_downstream"]["success"]
    assert results["event"]["trigger"] == "release"
コード例 #17
0
def test_handler_cleanup(tmpdir):
    t = Path(tmpdir)
    t.joinpath("a").mkdir()
    t.joinpath("b").write_text("a")
    t.joinpath("c").symlink_to("b")
    t.joinpath("d").symlink_to("a", target_is_directory=True)
    t.joinpath("e").symlink_to("nope", target_is_directory=False)
    t.joinpath("f").symlink_to("nopez", target_is_directory=True)
    t.joinpath(".g").write_text("g")
    t.joinpath(".h").symlink_to(".g", target_is_directory=False)

    c = ServiceConfig()
    c.command_handler_work_dir = t
    jc = JobConfig(JobType.copr_build, JobTriggerType.pull_request, {})
    j = JobHandler(c, jc, Event(JobTriggerType.pull_request))

    j._clean_workplace()

    assert len(list(t.iterdir())) == 0
コード例 #18
0
def test_dist_git_push_release_handle_one_failed(release_event):
    packit_yaml = ("{'specfile_path': 'hello-world.spec', 'synced_files': []"
                   ", jobs: [{trigger: release, job: propose_downstream, "
                   "metadata: {targets:[], dist-git-branch: fedora-all}}]}")
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = (flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
    ).should_receive("create_issue").once().mock())
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    flexmock(SteveJobs, _is_private=False)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="0.3.0").once()

    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f32",
        version="0.3.0").and_raise(Exception, "Failed f30").once()
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f31", version="0.3.0").once()
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f30", version="0.3.0").once()

    flexmock(FedPKG).should_receive("clone").and_return(None)

    flexmock(sentry_integration).should_receive(
        "send_to_sentry").and_return().once()
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release))

    results = SteveJobs().process_message(release_event)
    assert not results["jobs"]["propose_downstream"]["success"]
    assert results["event"]["trigger"] == "release"
コード例 #19
0
def mock_pr_comment_functionality(request):
    packit_yaml = ("{'specfile_path': '', 'synced_files': [], 'jobs': " +
                   str(request.param) + "}")
    flexmock(
        GithubProject,
        full_repo_name="packit-service/hello-world",
        get_file_content=lambda path, ref: packit_yaml,
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
        get_pr=lambda pr_id: flexmock(head_commit="12345"),
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)

    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.pull_request))
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
コード例 #20
0
def mock_release_functionality(request):
    packit_yaml = (
        "{'specfile_path': 'the-specfile.spec', 'synced_files': [], 'jobs':"
        + str(request.param)
        + "}"
    )
    flexmock(
        GithubProject,
        full_repo_name="packit/hello-world",
        get_file_content=lambda path, ref: packit_yaml,
        get_files=lambda ref, filter_regex: ["the-specfile.spec"],
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
        get_pr=lambda pr_id: flexmock(head_commit="12345"),
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)

    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    trigger = JobTriggerModel(type=JobConfigTriggerType.release, id=123)
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(trigger)
    flexmock(ProjectReleaseModel).should_receive("get_by_id").with_args(123).and_return(
        trigger
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(JobTriggerModel).should_receive("get_by_id").with_args(123456).and_return(
        trigger
    )
    flexmock(trigger).should_receive("get_trigger_object").and_return(
        ProjectReleaseModel(tag_name="0.1.0")
    )
    flexmock(ProjectReleaseModel).should_receive("get_or_create").with_args(
        tag_name="0.1.0",
        namespace="packit",
        repo_name="hello-world",
        project_url="https://github.com/packit/hello-world",
        commit_hash="0e5d8b51fd5dfa460605e1497d22a76d65c6d7fd",
    ).and_return(flexmock(id=12, job_config_trigger_type=JobConfigTriggerType.release))
    flexmock(JobTriggerModel).should_receive("get_or_create").and_return(
        flexmock(id=123456)
    )
コード例 #21
0
def test_handler_cleanup(tmpdir, trick_p_s_with_k8s):
    t = Path(tmpdir)
    t.joinpath("a").mkdir()
    t.joinpath("b").write_text("a")
    t.joinpath("c").symlink_to("b")
    t.joinpath("d").symlink_to("a", target_is_directory=True)
    t.joinpath("e").symlink_to("nope", target_is_directory=False)
    t.joinpath("f").symlink_to("nopez", target_is_directory=True)
    t.joinpath(".g").write_text("g")
    t.joinpath(".h").symlink_to(".g", target_is_directory=False)

    c = ServiceConfig()
    c.command_handler_work_dir = t
    jc = JobConfig(type=JobType.copr_build,
                   trigger=JobConfigTriggerType.pull_request,
                   metadata={})
    j = JobHandler(config=c,
                   job_config=jc,
                   event=Event(trigger=TheJobTriggerType.pull_request))

    j._clean_workplace()

    assert len(list(t.iterdir())) == 0
コード例 #22
0
def test_pr_test_command_handler_missing_build(pr_embedded_command_comment_event):
    jobs = [
        {
            "trigger": "pull_request",
            "job": "tests",
            "metadata": {"targets": "fedora-rawhide-x86_64"},
        }
    ]
    packit_yaml = (
        "{'specfile_path': 'the-specfile.spec', 'synced_files': [], 'jobs': "
        + str(jobs)
        + "}"
    )
    pr = flexmock(head_commit="12345")
    flexmock(GithubProject).should_receive("get_pr").and_return(pr)
    comment = flexmock()
    flexmock(pr).should_receive("get_comment").and_return(comment)
    flexmock(comment).should_receive("add_reaction").with_args("+1").once()
    flexmock(
        GithubProject,
        full_repo_name="packit-service/hello-world",
        get_file_content=lambda path, ref: packit_yaml,
        get_files=lambda ref, filter_regex: ["the-specfile.spec"],
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)

    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    trigger = flexmock(
        job_config_trigger_type=JobConfigTriggerType.pull_request, id=123
    )
    flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
    flexmock(PullRequestModel).should_receive("get_by_id").with_args(123).and_return(
        trigger
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Allowlist, check_and_report=True)
    flexmock(PullRequestModel).should_receive("get_or_create").with_args(
        pr_id=9,
        namespace="packit-service",
        repo_name="hello-world",
        project_url="https://github.com/packit-service/hello-world",
    ).and_return(
        flexmock(
            id=9,
            job_config_trigger_type=JobConfigTriggerType.pull_request,
            job_trigger_model_type=JobTriggerModelType.pull_request,
        )
    )
    flexmock(JobTriggerModel).should_receive("get_or_create").with_args(
        type=JobTriggerModelType.pull_request, trigger_id=9
    ).and_return(trigger)

    pr_embedded_command_comment_event["comment"]["body"] = "/packit test"
    flexmock(GithubProject, get_files="foo.spec")
    flexmock(GithubProject).should_receive("is_private").and_return(False)
    flexmock(Signature).should_receive("apply_async").twice()
    flexmock(copr_build).should_receive("get_valid_build_targets").and_return(
        {"test-target", "test-target-without-build"}
    )
    flexmock(TestingFarmJobHelper).should_receive("get_latest_copr_build").and_return(
        flexmock(status=PG_BUILD_STATUS_SUCCESS)
    ).and_return()

    flexmock(TestingFarmJobHelper).should_receive("job_owner").and_return("owner")
    flexmock(TestingFarmJobHelper).should_receive("job_project").and_return("project")
    flexmock(CoprBuildJobHelper).should_receive("report_status_to_tests").once()
    flexmock(CoprBuildJobHelper).should_receive(
        "report_status_to_test_for_chroot"
    ).once()
    flexmock(TestingFarmJobHelper).should_receive("run_testing_farm").once().and_return(
        TaskResults(success=False, details={})
    )
    flexmock(Pushgateway).should_receive("push").twice().and_return()

    processing_results = SteveJobs().process_message(pr_embedded_command_comment_event)
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results
    )
    assert json.dumps(event_dict)

    run_testing_farm_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job_config,
    )
コード例 #23
0
def test_pr_comment_production_build_handler(pr_production_build_comment_event):
    packit_yaml = str(
        {
            "specfile_path": "the-specfile.spec",
            "synced_files": [],
            "jobs": [
                {
                    "trigger": "pull_request",
                    "job": "production_build",
                    "metadata": {"targets": "fedora-rawhide-x86_64", "scratch": "true"},
                }
            ],
        }
    )
    comment = flexmock(add_reaction=lambda reaction: None)
    flexmock(
        GithubProject,
        full_repo_name="packit-service/hello-world",
        get_file_content=lambda path, ref: packit_yaml,
        get_files=lambda ref, filter_regex: ["the-specfile.spec"],
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
        get_pr=lambda pr_id: flexmock(
            head_commit="12345", get_comment=lambda comment_id: comment
        ),
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)

    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    trigger = flexmock(
        job_config_trigger_type=JobConfigTriggerType.pull_request, id=123
    )
    flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
    flexmock(PullRequestModel).should_receive("get_by_id").with_args(123).and_return(
        trigger
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Allowlist, check_and_report=True)

    flexmock(PullRequestModel).should_receive("get_or_create").with_args(
        pr_id=9,
        namespace="packit-service",
        repo_name="hello-world",
        project_url="https://github.com/packit-service/hello-world",
    ).and_return(
        flexmock(id=9, job_config_trigger_type=JobConfigTriggerType.pull_request)
    )
    flexmock(KojiBuildJobHelper).should_receive("run_koji_build").and_return(
        TaskResults(success=True, details={})
    )
    flexmock(GithubProject, get_files="foo.spec")
    flexmock(GithubProject).should_receive("is_private").and_return(False)
    flexmock(KojiBuildJobHelper).should_receive("report_status_to_build").with_args(
        description=TASK_ACCEPTED,
        state=BaseCommitStatus.pending,
        url="",
    ).once()
    flexmock(Signature).should_receive("apply_async").once()
    flexmock(Pushgateway).should_receive("push").twice().and_return()
    pr = flexmock(head_commit="12345")
    flexmock(GithubProject).should_receive("get_pr").and_return(pr)
    comment = flexmock()
    flexmock(pr).should_receive("get_comment").and_return(comment)
    flexmock(comment).should_receive("add_reaction").with_args("+1").once()

    processing_results = SteveJobs().process_message(pr_production_build_comment_event)
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results
    )
    assert json.dumps(event_dict)

    results = run_koji_build_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job_config,
    )
    assert first_dict_value(results["job"])["success"]
コード例 #24
0
def test_pr_test_command_handler_not_allowed_external_contributor_on_internal_TF(
    pr_embedded_command_comment_event,
):
    jobs = [
        {
            "trigger": "pull_request",
            "job": "tests",
            "metadata": {"targets": "fedora-rawhide-x86_64", "use_internal_tf": True},
        }
    ]
    packit_yaml = (
        "{'specfile_path': 'the-specfile.spec', 'synced_files': [], 'jobs': "
        + str(jobs)
        + "}"
    )
    pr = flexmock(head_commit="12345")
    flexmock(GithubProject).should_receive("get_pr").and_return(pr)
    comment = flexmock()
    flexmock(pr).should_receive("get_comment").and_return(comment)
    flexmock(comment).should_receive("add_reaction").with_args("+1").once()
    gh_project = flexmock(
        GithubProject,
        full_repo_name="packit-service/hello-world",
        get_file_content=lambda path, ref: packit_yaml,
        get_files=lambda ref, filter_regex: ["the-specfile.spec"],
        get_web_url=lambda: "https://github.com/the-namespace/the-repo",
    )
    gh_project.should_receive("can_merge_pr").with_args("phracek").and_return(False)
    flexmock(Github, get_repo=lambda full_name_or_id: None)

    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    trigger = flexmock(
        job_config_trigger_type=JobConfigTriggerType.pull_request, id=123
    )
    flexmock(AddPullRequestDbTrigger).should_receive("db_trigger").and_return(trigger)
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Allowlist, check_and_report=True)
    flexmock(PullRequestModel).should_receive("get_or_create").with_args(
        pr_id=9,
        namespace="packit-service",
        repo_name="hello-world",
        project_url="https://github.com/packit-service/hello-world",
    ).and_return(
        flexmock(id=9, job_config_trigger_type=JobConfigTriggerType.pull_request)
    ).once()
    pr_embedded_command_comment_event["comment"]["body"] = "/packit test"
    flexmock(GithubProject, get_files="foo.spec")
    flexmock(GithubProject).should_receive("is_private").and_return(False).once()
    flexmock(Signature).should_receive("apply_async").times(0)
    flexmock(TestingFarmJobHelper).should_receive("run_testing_farm").times(0)
    flexmock(CoprBuildJobHelper).should_receive("report_status_to_tests").with_args(
        description="phracek can't run tests internally",
        state=BaseCommitStatus.neutral,
        markdown_content="*As a project maintainer, "
        "you can trigger the test job manually via `/packit test` comment.*",
    ).once()

    processing_results = SteveJobs().process_message(pr_embedded_command_comment_event)
    assert not processing_results