コード例 #1
0
def write_issue(ticket, outfile):
    """Dumps a csv line *row* from the issue query to *outfile*.
    """
    # Issue text body
    body = ticket[3]['description']
    body = trac_to_gh(body)

    # Default state: open (no known resolution)
    state = STATES.get(ticket[3]['status'], 'open')

    # Trac will have stored some kind of username.
    reporter = ticket[3]['reporter']

    # Not sure whether we have a related github account for that user.
    if USERNAMES.get(reporter):
        userdata = USERNAMES[reporter]
    else: # If we do not, at least mention the user in our issue body
        userdata = DEFAULT_USER
    
    body = ('This issue was reported by **%s**\r\n\r\n' % reporter) + body

    # Whether this is stored in 'milestone' or '__group__' depends on the
    # query type. Try to find the data or assign the default milestone 0.
    milestone_info = ticket[3]['milestone']
    milestone = MILESTONES.get(milestone_info, 3)

    labels = [] # Collect random tags that might serve as labels
    for tag in ('type', 'component', 'priority'):
        if ticket[3].get(tag) and LABELS.get(ticket[3][tag]):
            label = LABELS[ticket[3][tag]]
            labels.append({'name': github_label(label)})


    # Dates
    updated_at = DateTime(str(ticket[2])).ISO8601()
    created_at = DateTime(str(ticket[1])).ISO8601()
    
    # Now prepare writing all data into the json files
    dct = {
          'title': ticket[3]['summary'],
          'body': body,
          'state': state,
          'user': userdata,
          'milestone': int(milestone),
          'labels': labels,
          'updated_at': updated_at,
          'created_at': created_at,
       }

    # Assigned user in trac and github account of that assignee
#    assigned_trac = ticket[3]['owner']
#    assigned = USERNAMES.get(assigned_trac)
    # Assigning really does not make sense without github account
#    if state == 'open' and assigned and assigned['login'] != 'fifengine':
#        print assigned
#        dct['assignee'] = assigned

    # Everything collected, write the json file
    json.dump(dct, outfile, indent=5)
コード例 #2
0
def write_issue(row, outfile):
    """Dumps a csv line *row* from the issue query to *outfile*.
    """
    for key, value in row.items():
        row[key] = row[key].decode('utf-8')
    # Issue text body
    body = row.get('_description', u'')
    body = trac_to_gh(body) + '\r\n\r\n' \
        '[> Link to originally reported Trac ticket <] ({url})'.format(
        url=TRAC_TICKET_URL % row['ticket'])

    # Default state: open (no known resolution)
    state = STATES.get(row.get('status'), 'open')

    # Trac will have stored some kind of username.
    reporter = row['_reporter']

    # Not sure whether we have a related github account for that user.
    if USERNAMES.get(reporter):
        userdata = USERNAMES[reporter]
    else: # If we do not, at least mention the user in our issue body
        userdata = DEFAULT_USER
        body = ('This issue was reported by **%s**\r\n\r\n' % reporter) + body

    # Whether this is stored in 'milestone' or '__group__' depends on the
    # query type. Try to find the data or assign the default milestone 0.
    milestone_info = row.get(('milestone'), row.get('__group__'))
    milestone = MILESTONES.get(milestone_info, 0)

    labels = [] # Collect random tags that might serve as labels
    for tag in ('type', 'component', 'priority'):
        if row.get(tag) and LABELS.get(row[tag]):
            label = LABELS[row[tag]]
            labels.append({'name': github_label(label)})

    # Also attach a special label to our starter tasks.
    # Again, please ignore this.
    #if row['ticket'] in easy_tickets:
    #    labels.append({'name': unicode(LABELS.get('start').lower())})

    # Dates
    updated_at = row.get('modified') or row.get('_changetime')
    created_at = row.get('created') or updated_at

    # Now prepare writing all data into the json files
    dct = {
          'title': row['summary'],
          'body': body,
          'state': state,
          'user': userdata,
          'milestone': {'number': milestone},
          'labels': labels,
          'updated_at': updated_at,
          'created_at': created_at,
       }

    # Assigned user in trac and github account of that assignee
    assigned_trac = row.get('owner')
    assigned = USERNAMES.get(assigned_trac)
    # Assigning really does not make sense without github account
    if state == 'open' and assigned:
        dct['assignee'] = assigned

    # Everything collected, write the json file
    json.dump(dct, outfile, indent=5)