コード例 #1
0
def test_pr_id_and_ref(tmp_path: Path):
    """ p-s passes both ref and pr_id, we want to check out PR """
    remote = tmp_path / "remote"
    remote.mkdir()
    subprocess.check_call(["git", "init", "--bare", "."], cwd=remote)
    upstream_git = tmp_path / "upstream_git"
    upstream_git.mkdir()
    initiate_git_repo(upstream_git, push=True, upstream_remote=str(remote))
    # mimic github PR
    pr_id = "123"
    ref = (
        subprocess.check_output(["git", "rev-parse", "HEAD^"], cwd=upstream_git)
        .strip()
        .decode()
    )
    local_tmp_branch = "asdqwe"
    subprocess.check_call(["git", "branch", local_tmp_branch, ref], cwd=upstream_git)
    subprocess.check_call(
        ["git", "push", "origin", f"{local_tmp_branch}:refs/pull/{pr_id}/head"],
        cwd=upstream_git,
    )
    subprocess.check_call(["git", "branch", "-D", local_tmp_branch], cwd=upstream_git)

    LocalProject(
        working_dir=upstream_git,
        offline=True,
        pr_id=pr_id,
        ref=ref,
        git_service=GithubService(),
    )

    assert (
        subprocess.check_output(
            ["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=upstream_git
        )
        .strip()
        .decode()
        == f"pr/{pr_id}"
    )
コード例 #2
0
ファイル: conftest.py プロジェクト: xsuchy/packit
def sourcegit_n_distgit(tmpdir):
    temp_dir = Path(str(tmpdir))

    sourcegit_remote = temp_dir / "source_git_remote"
    sourcegit_remote.mkdir()
    subprocess.check_call(["git", "init", "--bare", "."], cwd=sourcegit_remote)

    sourcegit_dir = temp_dir / "source_git"
    shutil.copytree(SOURCEGIT_UPSTREAM, sourcegit_dir)
    initiate_git_repo(sourcegit_dir, tag="0.1.0")
    subprocess.check_call(["cp", "-R", SOURCEGIT_SOURCEGIT, temp_dir],
                          cwd=sourcegit_remote)
    git_add_and_commit(directory=sourcegit_dir, message="sourcegit content")

    distgit_dir = temp_dir / "dist_git"
    shutil.copytree(DISTGIT, distgit_dir)
    initiate_git_repo(distgit_dir,
                      push=True,
                      upstream_remote=str(sourcegit_remote))
    prepare_dist_git_repo(distgit_dir)

    return sourcegit_dir, distgit_dir
コード例 #3
0
def test_fetch_upstream_ref(api_instance_source_git, tmp_path: Path):
    tag = "1.0.0"
    s = tmp_path.joinpath("s")
    u = tmp_path.joinpath("u")
    u.mkdir()
    create_new_repo(Path(s), [])
    initiate_git_repo(u, tag=tag)
    sgg = SourceGitGenerator(
        LocalProject(working_dir=s),
        api_instance_source_git.config,
        str(u),
        upstream_ref=tag,
        centos_package="x",
    )

    sgg._pull_upstream_ref()

    assert s.joinpath(".git").is_dir()
    assert sgg.local_project.ref == "main"
    assert sgg.local_project.working_dir.joinpath(
        "hops").read_text() == "Cascade\n"
    assert sgg.local_project.git_repo.head.commit.message == "commit with data\n"
コード例 #4
0
ファイル: test_upstream.py プロジェクト: hroncok/packit
def test_set_spec_ver_empty_changelog(tmp_path):
    u_remote_path = tmp_path / "upstream_remote"
    u_remote_path.mkdir(parents=True, exist_ok=True)

    create_new_repo(u_remote_path, ["--bare"])

    u = tmp_path / "upstream_git"
    shutil.copytree(EMPTY_CHANGELOG, u)
    initiate_git_repo(u, tag="0.1.0")

    with cwd(tmp_path):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        lp = LocalProject(working_dir=u)

        ups = Upstream(c, pc, lp)

    new_ver = "1.2.3"
    ups.specfile.set_spec_version(version=new_ver, changelog_entry="- asdqwe")

    assert ups.get_specfile_version() == new_ver
    assert "%changelog" not in u.joinpath("beer.spec").read_text()
コード例 #5
0
def example_repo(request, tmpdir):
    example_path, tag, remote = request.param
    t = Path(str(tmpdir))
    u = t / "up"
    initiate_git_repo(u, tag=tag, copy_from=example_path, upstream_remote=remote)
    return u