Exemplo n.º 1
0
def ensure_label_exists(
    repo: github3.repos.Repository, label_dict: dict, dry_run: bool = False,
) -> None:
    if dry_run:
        print(f"dry run: ensure label exists {label_dict['name']}")
    try:
        repo.label(label_dict["name"])
    except github3.exceptions.NotFoundError:
        repo.create_label(**label_dict)
Exemplo n.º 2
0
def find_sprint_milestone(
    repo: github3.repos.Repository,
    sprint: delivery.model.Sprint,
):
    for ms in repo.milestones():
        if ms.title == _milestone_title(sprint=sprint):
            return ms
    return None
Exemplo n.º 3
0
def label_pr(
    repo: github3.repos.Repository,
    pr_json: LazyJson,
    label_dict: dict,
    dry_run: bool = False,
) -> None:
    ensure_label_exists(repo, label_dict, dry_run)
    if dry_run:
        print(f"dry run: label pr {pr_json['number']} with {label_dict['name']}")
    else:
        iss = repo.issue(pr_json["number"])
        iss.add_labels(label_dict["name"])
Exemplo n.º 4
0
def enumerate_issues(
    component: cm.Component | None,
    resource: cm.Resource | None,
    repository: github3.repos.Repository,
    issue_type: str | None,
    state: str | None = None, # 'open' | 'closed'
) -> typing.Generator[github3.issues.ShortIssue, None, None]:
    labels = set(
        repository_labels(
            component=component,
            resource=resource,
            issue_type=issue_type,
        ),
    )

    for issue in repository.issues(state=state, labels=labels):
        issue_labels = set((l.name for l in issue.labels()))
        # workaround: skip if - even though we requested this - not all requested labels are present
        if not issue_labels & labels == labels:
            continue
        yield issue
Exemplo n.º 5
0
def _create_issue(
    component: cm.Component,
    resource: cm.Resource,
    repository: github3.repos.Repository,
    body:str,
    title:typing.Optional[str],
    assignees: typing.Iterable[str]=(),
    milestone: github3.issues.milestone.Milestone=None,
    issue_type: str=_label_bdba,
    extra_labels: typing.Iterable[str]=None,
) -> github3.issues.issue.ShortIssue:
    if not title:
        title = f'[{issue_type}] - {component.name}:{resource.name}'

    assignees = tuple(assignees)

    labels = tuple(repository_labels(
        component=component,
        resource=resource,
        issue_type=issue_type,
        extra_labels=extra_labels,
    ))

    try:
        return repository.create_issue(
            title=title,
            body=body,
            assignees=assignees,
            milestone=milestone.number if milestone else None,
            labels=labels,
        )
    except github3.exceptions.GitHubError as ghe:
        logger.warning(f'received error trying to create issue: {ghe=}')
        logger.warning(f'{ghe.message=} {ghe.code=} {ghe.errors=}')
        logger.warning(f'{component.name=} {resource.name=} {assignees=} {labels=}')
        raise ghe
Exemplo n.º 6
0
def push_repo(
    session_ctx: MigratorSessionContext,
    fctx: FeedstockContext,
    feedstock_dir: str,
    body: str,
    repo: github3.repos.Repository,
    title: str,
    head: str,
    branch: str,
) -> Union[dict, bool, None]:
    """Push a repo up to github

    Parameters
    ----------
    feedstock_dir : str
        The feedstock directory
    body : str
        The PR body

    Returns
    -------
    pr_json: dict
        The dict representing the PR, can be used with `from_json`
        to create a PR instance.
    """
    with indir(feedstock_dir), env.swap(RAISE_SUBPROC_ERROR=False):
        # Setup push from doctr
        # Copyright (c) 2016 Aaron Meurer, Gil Forsyth
        token = session_ctx.github_password
        deploy_repo = (session_ctx.github_username + "/" +
                       fctx.feedstock_name + "-feedstock")
        if session_ctx.dry_run:
            repo_url = f"https://github.com/{deploy_repo}.git"
            print(
                f"dry run: adding remote and pushing up branch for {repo_url}")
        else:
            doctr_run(
                [
                    "git",
                    "remote",
                    "add",
                    "regro_remote",
                    f"https://{token}@github.com/{deploy_repo}.git",
                ],
                token=token.encode("utf-8"),
            )

            doctr_run(
                ["git", "push", "--set-upstream", "regro_remote", branch],
                token=token.encode("utf-8"),
            )
    # lastly make a PR for the feedstock
    print("Creating conda-forge feedstock pull request...")
    if session_ctx.dry_run:
        print(f"dry run: create pr with title: {title}")
        return False
    else:
        pr = repo.create_pull(title, "master", head, body=body)
        if pr is None:
            print("Failed to create pull request!")
            return False
        else:
            print("Pull request created at " + pr.html_url)
    # Return a json object so we can remake the PR if needed
    pr_dict: dict = pr.as_dict()
    return pr_dict