Ejemplo n.º 1
0
def milestones(globs: AttrDict, order: str, state: str, create: str,
               list: bool):
    """Repository milestones."""
    if not list and not create:
        fail('No action specified!')
        return 1
    milestones_url = '{}/repos/{}/milestones'.format(globs.host_url,
                                                     globs.project)
    r, milestones = globs.req_get(milestones_url, model='Milestone')

    if list:
        tmpl = template.get_template('view', '/list_milestones.txt')
        columns = utils.T.width if utils.T.width else 80
        max_id = max(i.number for i in milestones)
        id_len = len(str(max_id))

        result = tmpl.render(milestones=milestones, order=order, state=state,
                             project=globs.repo_obj(),
                             id_len=id_len, max_title=columns - id_len - 2)
        if result:
            utils.pager(result, pager=globs.pager)
    elif create:
        data = {'title': create}
        r, milestone = globs.req_post('', body=data, model='Milestone')
        success('Milestone {:d} created'.format(milestone.number))
Ejemplo n.º 2
0
def show(globs: AttrDict, full: bool, patch: bool, patch_only: bool,
         browse: bool, bugs: List[int]):
    """Displaying bugs."""
    results = []
    tmpl = template.get_template('view', '/issue.txt')
    for bug_no in bugs:
        if browse:
            click.launch('https://github.com/{}/issues/{:d}'.format(
                globs.project, bug_no))
            continue
        r, bug = globs.req_get(bug_no, model='Issue')

        if full and bug.comments:
            r, comments = globs.req_get('{}/comments'.format(bug_no),
                                        model='Comment')
        else:
            comments = []
        if (patch or patch_only) and bug.pull_request:
            url = '{}/repos/{}/pulls/{}'.format(globs.host_url, globs.project,
                                                bug_no)
            headers = {'Accept': 'application/vnd.github.patch'}
            r, c = globs.req_get(url, headers=headers, is_json=False)
            patch = c.decode('utf-8')
        else:
            patch = None
        results.append(tmpl.render(bug=bug, comments=comments, full=True,
                                   patch=patch, patch_only=patch_only,
                                   project=globs.repo_obj()))
    if results:
        utils.pager('\n'.join(results), pager=globs.pager)
Ejemplo n.º 3
0
def list_bugs(globs: AttrDict, label: List[str], page: int,
              pull_requests: bool, order: str, state: str):
    """Listing bugs."""
    bugs = []
    params = {}
    if pull_requests:
        # FIXME: Dirty solution to supporting PRs only, needs rethink
        url = '{}/repos/{}/pulls'.format(globs.host_url, globs.project)
    else:
        url = ''
    if page != 1:
        params['page'] = page
    if label:
        params['labels'] = ','.join(label)

    states = ['open', 'closed'] if state == 'all' else [state, ]
    for state in states:
        _params = params.copy()
        _params['state'] = state
        r, _bugs = globs.req_get(url, params=_params, model='Issue')
        bugs.extend(_bugs)

    result = template.display_bugs(bugs, order, state=state,
                                   project=globs.repo_obj())
    if result:
        utils.pager(result, pager=globs.pager)
Ejemplo n.º 4
0
def search(globs: AttrDict, order: str, state: str, term: str):
    """Searching bugs."""
    search_url = '{}/search/issues'.format(globs.host_url)
    states = ['open', 'closed'] if state == 'all' else [state, ]
    params = {
        'q': term,
        'repo': globs.project,
    }
    bugs = []
    for state in states:
        params['state'] = state
        r, c = globs.req_get(search_url, params=params, model='issue')
        bugs.extend(c.issues)
    result = template.display_bugs(bugs, order, term=term, state=state,
                                   project=globs.repo_obj())
    if result:
        utils.pager(result, pager=globs.pager)