with MongoConnection() as conn:
    count = 0
    for msg in get_messages():
        try:
            all_data = extract_bug_info(msg)
        except:
            continue

        who = all_data['changed_by']
        all_data.pop('changed_by')

        author_info = who
        if 'author_name' in all_data:
            author_info += " " + all_data['author_name']
            all_data.pop('author_name')
        volunteer = classify_volunteer(author_info)

        all_data['volunteer_assignee'] = classify_volunteer(all_data['assignee'])

        when_str = all_data['changed_at']
        when_tuple = email.utils.parsedate_tz(when_str)
        when = datetime.datetime.fromtimestamp(email.utils.mktime_tz(when_tuple))
        all_data.pop('changed_at')
        source = 'bugzilla'
        comment = ('#c' + str(all_data['comment'])) if 'comment' in all_data else ''
        canonical = 'https://bugzilla.mozilla.org/show_bug.cgi?id=%s%s' % (all_data['id'],
                                                                           comment)
        conn.add_contribution(who, when, source, canonical, volunteer, all_data)

        count += 1
    print 'Synced %d bug(s) from email' % count
Exemple #2
0
for commit in repo.iter_commits('master'):
    if last_commit and commit.hexsha in last_commit:
        break
    email = commit.author.email
    commit_date = commit.committed_date
    offset = commit.committer_tz_offset / 3600
    data.append({'email': email,
                 'name': commit.author.name,
                 'datetime': datetime.fromtimestamp(commit_date, FixedOffset(offset)),
                 'source': 'hg',
                 'extra': {'tree': tree},
                 'sha': commit.hexsha})

print 'done'

with MongoConnection(configfilename='config') as conn:
    for datum in reversed(data):
        print 'Inserting ' + datum['sha']
        conn.add_contribution(who=datum['email'],
                              when=datum['datetime'],
                              source=datum['source'],
                              canonical='https://github.com/mozilla/gecko-dev/commit/' + datum['sha'],
                              volunteer=classify_volunteer('%s <%s>' % (datum['name'], datum['email'])),
                              extra=datum['extra'])
        f = open('last_commit', 'wb')
        f.write(datum['sha'])
        f.close()

print 'Updated database'