Ejemplo n.º 1
0
def get_pr(namespace: str, repo: str, pr_num: int) -> PullRequest:
    service = PagureService(
        instance_url=getenv("PAGURE_URL") or "https://git.stg.centos.org",
        token=getenv("PAGURE_TOKEN"),
        read_only=True,
    )
    project = service.get_project(namespace=namespace, repo=repo)
    return project.get_pr(pr_num)
Ejemplo n.º 2
0
    def process_new_dg_flag(self, msg):
        """
        Process flags from the PR and update source git PR with those flags
        :param msg:
        :return:
        """
        raise NotImplementedError(
            "The watching of the Fedora CI is not implemented yet."
        )

        project_name = msg["msg"]["pullrequest"]["project"]["name"]
        logger.info("new flag for PR for %s", project_name)

        try:
            source_git = get_package_mapping()[project_name]["source-git"]
        except KeyError:
            logger.info("source git not found")
            return

        ps = PagureService(token=self.pagure_token)
        project = ps.get_project(repo=project_name, namespace="rpms")

        pr_id = msg["msg"]["pullrequest"]["id"]

        # find info for the matching source git pr
        sg_pr_id = project.get_sg_pr_id(pr_id)

        # check the commit which tests were running for
        commit = project.get_sg_top_commit(pr_id)

        if not (sg_pr_id and commit):
            logger.info("this doesn't seem to be a source-git related event")
            return

        repo = self.gh.get_repo(source_git)
        sg_pull = repo.get_pull(sg_pr_id)
        for c in sg_pull.get_commits():
            if c.sha == commit:
                gh_commit = c
                break
        else:
            raise RuntimeError("commit was not found in source git")

        # Pagure states match github states, coolzies
        # https://developer.github.com/v3/repos/statuses/#create-a-status
        gh_commit.create_status(
            msg["msg"]["flag"]["status"],
            target_url=msg["msg"]["flag"]["url"],
            description=msg["msg"]["flag"]["comment"],
            context=msg["msg"]["flag"]["username"],  # simple-koji-ci or Fedora CI
        )
Ejemplo n.º 3
0
def test_basic_distgit_workflow(tmpdir):
    pagure_token = os.getenv("PAGURE_TOKEN")

    pag = PagureService(
        token=pagure_token,
        repo="tmux-top",
        namespace="rpms",
        instance_url="https://src.stg.fedoraproject.org/",
    )

    print(pag.pagure.whoami())

    proj = pag.get_project()

    proj.fork_create()
    fork = proj.get_fork()
    clone_url = fork.get_git_urls()

    t = Path(tmpdir)
    repo = t.joinpath("repo")

    branch_name = "cookie"

    subprocess.check_call(["git", "clone", clone_url, repo])
    git_set_user_email(repo)
    subprocess.check_call(["git", "checkout", "-B", branch_name], cwd=repo)

    repo.joinpath("README").write_text("just trying something out\n")

    subprocess.check_call(["git", "add", "README"], cwd=repo)
    subprocess.check_call(["git", "commit", "-m", "test commit"], cwd=repo)
    subprocess.check_call(
        ["git", "push", "origin", f"{branch_name}:{branch_name}"], cwd=repo)

    pr = fork.pr_create("testing PR", "serious description", "master",
                        branch_name)

    proj.pr_comment(pr.id, "howdy!")
Ejemplo n.º 4
0

# PAGURE_TOKEN="ABC" BUGZILLA_API_KEY="XYZ" python3 psbugzilla.py
if __name__ == "__main__":
    from os import getenv
    from ogr.services.pagure import PagureService

    namespace = getenv("NAMESPACE") or "source-git"
    repo = getenv("REPO") or "rpm"
    pr_id = int(getenv("PR_ID")) or 19
    service = PagureService(
        instance_url="https://git.stg.centos.org",
        token=getenv("PAGURE_TOKEN"),
        read_only=True,
    )
    project = service.get_project(namespace=namespace, repo=repo)
    pr = project.get_pr(pr_id)

    bz = Bugzilla(url="https://partner-bugzilla.redhat.com",
                  api_key=getenv("BUGZILLA_API_KEY"))
    logging.basicConfig()
    bz.logger.setLevel(logging.DEBUG)
    description = f"Based on approved CentOS Stream Pull Request: {pr.url}"
    bzid, url = bz.create_bug(
        product="Red Hat Enterprise Linux 8",
        version="CentOS-Stream",
        component=repo,
        summary=pr.title,
        description=description,
    )
    bz.add_patch(bzid=bzid,