示例#1
0
def import_(repo, milestones, milestones_map=None):
    """Import or update milestones."""
    milestones_map = milestones_map and milestones_map or {}

    o = {}
    e = exporter.Exporter()
    ms = repo.milestones()
    closed_ms = repo.milestones(state='closed')
    open_ms_by_id = dict((x['number'], x) for x in ms)
    closed_ms_by_id = dict((x['number'], x) for x in closed_ms)
    ms_by_id = open_ms_by_id.copy()
    ms_by_id.update(closed_ms_by_id)

    for x in milestones:
        params = {'title': x['name']}
        params['state'] = x['active'] and 'open' or 'closed'

        if x['date_targeted']:
            params['due_on'] = x['date_targeted']

        if x['summary']:
            params['description'] = x['summary']

        # either add a new one or update existing
        try:
            if x['name'] in milestones_map and milestones_map[
                    x['name']] in ms_by_id:
                rv = ms_by_id[milestones_map[x['name']]].update(params)
            else:
                rv = ms.append(**params)
            o[x['name']] = rv['number']
        except Exception as err:
            e.emit('exception: %s' % err)
    return o
示例#2
0
def export(project, only_active=None):
    o = []
    c = client.Client()
    p = c.project(project)
    e = exporter.Exporter()
    specifications = list_specifications(p)
    for x in specifications:
        e.emit('fetching %s' % x.title)
        rv = specification_to_dict(x)
        o.append(rv)
    return o
示例#3
0
def export(project, only_open=None):
    o = []
    c = client.Client()
    p = c.project(project)
    e = exporter.Exporter()
    bugs = list_bugs(p, only_open=only_open)
    for x in bugs:
        e.emit('fetching %s' % x.title)
        rv = bug_task_to_dict(x)
        o.append(rv)
    return o
示例#4
0
def export(project, only_active=None):
    o = []
    c = client.Client()
    p = c.project(project)
    e = exporter.Exporter()
    milestones = list_milestones(p, only_active=only_active)
    for x in milestones:
        e.emit('fetching %s' % x.title)
        rv = milestone_to_dict(x)
        o.append(rv)
    return o
示例#5
0
def import_(repo, bugs, milestones_map=None):
    e = exporter.Exporter()
    # set up all the labels we know
    for status in BUG_STATUS:
        try:
            e.emit('create label %s' % status)
            labels.create_label(repo, status, 'ddffdd')
        except Exception as err:
            e.emit('exception: %s' % err.read())

    for importance in BUG_IMPORTANCE:
        try:
            e.emit('create label %s' % importance)
            labels.create_label(repo, importance, 'ffdddd')
        except Exception as err:
            e.emit('exception: %s' % err.read())

    tags = []
    for x in bugs:
        tags.extend(x['tags'])
    tags = set(tags)

    # NOTE(termie): workaround for github case-sensitivity bug
    defaults_lower = [x.lower() for x in (BUG_STATUS + BUG_IMPORTANCE)]
    tags = [x for x in tags if str(x.lower()) not in defaults_lower]
    tags_map = dict(
        (x.lower(), x) for x in (tags + BUG_STATUS + BUG_IMPORTANCE))

    for tag in tags:
        try:
            e.emit('create label %s' % tag)
            labels.create_label(repo, tag)
        except Exception as err:
            e.emit('exception: %s' % err.read())

    mapping = {}
    # first pass
    issues = repo.issues()
    for bug in bugs:
        e.emit('create issue %s' % bug['title'])
        params = {
            'title': bug['title'],
            'body': bug['description'],
            'labels': bug['tags'] + [bug['importance']] + [bug['status']],
            # NOTE(termie): github does not support setting created_at
            #'created_at': bug['date_created'],
        }

        # NOTE(termie): workaround for github case-sensitivity bug
        params['labels'] = list(
            set([
                labels.translate_label(tags_map[x.lower()])
                for x in params['labels']
            ]))

        e.emit('with params: %s' % params)
        try:
            rv = issues.append(**params)
        except urllib2.HTTPError as err:
            e.emit('exception: %s' % err.read())
            raise

        mapping[bug['id']] = rv['number']

    # second pass
    for bug in bugs:
        e.emit('second pass on issue %s' % bug['title'])
        bug = translate_auto_links(bug, mapping)
        bug = add_summary(bug, mapping)
        issue_id = mapping[bug['id']]
        issue = repo.issue(issue_id)

        # add all the comments
        comments = repo.comments(issue_id)
        for msg in bug['comments']:
            # TODO(termie): username mapping
            by_line = '(by %s)' % msg['owner']
            try:
                comments.append(body='%s\n%s' % (by_line, msg['content']))
            except urllib2.HTTPError as err:
                e.emit('exception: %s' % err.read())
                raise

        # update the issue
        params = {'body': bug['description']}
        if bug['status'] in BUG_CLOSED_STATUS:
            params['state'] = 'closed'

        # NOTE(termie): workaround a bug in github where it does not allow
        #               creating bugs that are assigned to double-digit milestones
        #               but does allow editing an existing bug
        if bug['milestone']:
            params['milestone'] = milestones_map[bug['milestone']]
        try:
            issue.update(params)
        except urllib2.HTTPError as err:
            e.emit('exception: %s' % err.read())
            raise

    return mapping