示例#1
0
文件: __init__.py 项目: JNRowe/hubugs
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)
示例#2
0
文件: __init__.py 项目: JNRowe/hubugs
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))
示例#3
0
文件: __init__.py 项目: JNRowe/hubugs
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)
示例#4
0
文件: __init__.py 项目: JNRowe/hubugs
def milestone(globs: AttrDict, milestone: str, bugs: List[int]):
    """Issue milestones."""
    milestones_url = '{}/repos/{}/milestones'.format(globs.host_url,
                                                     globs.project)
    r, milestones = globs.req_get(milestones_url, model='Milestone')

    milestone_mapping = dict((m.title, m.number) for m in milestones)

    try:
        milestone = milestone_mapping[milestone]
    except KeyError:
        raise ValueError('No such milestone {:!r}'.format(milestone))

    for bug_no in bugs:
        globs.req_post(bug_no, body={'milestone': milestone},
                       model='Milestone')
示例#5
0
文件: __init__.py 项目: JNRowe/hubugs
def label(globs: AttrDict, add: List[str], create: List[str],
          remove: List[str], list: bool, bugs: List[int]):
    """Labelling bugs."""
    label_names = utils.sync_labels(globs, add, create)

    if list:
        click.echo(', '.join(sorted(label_names)))
        return

    for bug_no in bugs:
        r, bug = globs.req_get(bug_no, model='Issue')
        labels = [label.name for label in bug.labels]
        labels.extend(add + create)

        for string in remove:
            labels.remove(string)
        globs.req_post(bug_no, body={'labels': labels}, model='Label')
示例#6
0
文件: __init__.py 项目: JNRowe/hubugs
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)
示例#7
0
文件: __init__.py 项目: JNRowe/hubugs
def edit(globs: AttrDict, stdin: bool, title: str, body:str, bugs: List[int]):
    """Editing bugs."""
    if (title or stdin) and len(bugs) > 1:
        raise ValueError('Can not use --stdin or command line title/body '
                         'with multiple bugs')
    for bug in bugs:
        if stdin:
            text = click.get_text_stream().readlines()
        elif not title:
            r, current = globs.req_get(bug, model='Issue')
            current_data = {'title': current.title, 'body': current.body}
            text = template.edit_text('open', current_data).splitlines()
        if stdin or not title:
            title = text[0]
            body = '\n'.join(text[1:])
        else:
            title = title
            body = body

        data = {'title': title, 'body': body}
        globs.req_post(bug, body=data, model='Issue')