Beispiel #1
0
def repo_list(user, sync, with_all, skip_email):
    """List user's repositories hooks.

    Lists repositories currently `enabled` by the user.
    If `--all` flag is specified, lists full list of repositories from remote
    account extra data. For best result `--all` should be used with `--sync`,
    so that the GitHub information is fresh. Positional argument USER can be
    either an email or user ID.

    Examples:

      github list [email protected]

      github list 12345 --sync --all
    """
    user = resolve_user(user)
    gha = GitHubAPI(user_id=user.id)
    if not skip_email:
        verify_email(user)
    if sync:
        gha.sync(hooks=True, async_hooks=False)  # Sync hooks asynchronously
        db.session.commit()
    if with_all:
        repos = gha.account.extra_data['repos']
        click.echo("User has {0} repositories in total.".format(len(repos)))
        for gid, repo in repos.items():
            click.echo(' {name}:{gid}'.format(name=repo['full_name'], gid=gid))

    repos = Repository.query.filter(Repository.user_id == user.id,
                                    Repository.hook.isnot(None))
    click.echo("User has {0} enabled repositories.".format(repos.count()))
    for r in repos:
        click.echo(" {0}".format(r))
Beispiel #2
0
def sync(user, hooks, async_hooks, skip_email):
    """Sync user's repositories.

    USER can be either an email or user ID.

    Examples:

      github sync [email protected]

      github sync 999
    """
    user = resolve_user(user)
    gh_api = GitHubAPI(user_id=user.id)
    gh_api.sync(hooks=hooks, async_hooks=async_hooks)
    if not skip_email:
        verify_email(user)
    db.session.commit()
Beispiel #3
0
def is_github_owner(user, pid, sync=False):
    """Return true if the user can create a new version for a GitHub record.

    :param user: User to check for ownership.
    :param pid: pid of a record.
    :param sync: Condition to sync the user's repository info from GitHub.
    """
    depid = fetch_depid(pid)
    if sync:
        try:
            commit = False
            with db.session.begin_nested():
                gh = GitHubAPI(user_id=user.id)
                if gh.account and gh.check_sync():
                    gh.sync(hooks=False)
                    commit = True
            if commit:
                db.session.commit()
        except Exception:
            # TODO: Log a warning?
            # TODO: (In case GitHub is down, we still want to render the page)
            pass
    repo = get_github_repository(depid)
    return repo.user == user if repo else False