Skip to content

Instantly share code, notes, and snippets.

@ilyasfoo
Last active April 14, 2017 07:21
Show Gist options
  • Select an option

  • Save ilyasfoo/4bddfc4773e96b6aae314e8c5a33d0de to your computer and use it in GitHub Desktop.

Select an option

Save ilyasfoo/4bddfc4773e96b6aae314e8c5a33d0de to your computer and use it in GitHub Desktop.
Commits summary generator for gitlab when you'd have to give release review for each commit.
import gitlab
import pickle
# Config stuff
accesscode = 'GITLAB_ACCESS_CODE_HERE'
committext = 'Notification CR'
gl = gitlab.Gitlab('http://gitlab.com', accesscode)
# Filter stuff
branch = 'newfeatures-notification'
authors = ['[email protected]', '[email protected]']
since = '2016-12-09T00:00:00Z'
def download():
commits = gl.project_commits.list(project_id=1414194, ref_name=branch, since=since, per_page=2000)
realcommits = []
for commit in commits:
if commit.author_email in authors :
realcommits.append(commit)
for idx, commit in enumerate(realcommits):
print 'Getting ' + str(idx) + ' of ' + str(len(realcommits)) + ' commits'
realcommits[idx].diffdata = commit.diff()
with open('data.pkl', 'wb') as output:
pickle.dump(realcommits, output, pickle.HIGHEST_PROTOCOL)
print 'Got ' + str(len(realcommits))
# main
download()
with open('data.pkl', 'rb') as input:
commits = pickle.load(input)
rows = []
for commit in commits:
title = commit.title.encode('utf-8')
hash = commit.id
message = commit.message.encode('utf-8')
files = '\n'.join(map(lambda x: x['old_path'], commit.diffdata)).encode('utf-8')
details = '<b>'+ committext +'</b>\n\n' + message + '\nImpacted files:\n' + files
rows.append([hash, details, 'Done'])
import HTML
rows.reverse()
with open('output.html', 'wb') as output:
data = '''<html><head><style>
td {
unicode-bidi: embed;
font-family: monospace;
white-space: pre;
}
</style></head><body>'''
data += HTML.table(rows)
data += '''</body></html>'''
output.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment