1 import re, sys, os, os.path
4 from itertools import islice
5 from operator import itemgetter
9 'bitcartel': 'Simon Liu',
10 'EthanHeilman': 'Ethan Heilman',
13 def apply_author_aliases(name):
14 if name in author_aliases:
15 return author_aliases[name]
19 def parse_authors(line):
20 commit_search = re.search('(\d+)', line)
22 commits = commit_search.group(1)
25 name = re.sub(' \(\d+\)|:|\n|\r\n$', '', line)
28 def alias_authors_in_release_notes(line):
29 for key in author_aliases:
30 if re.match(key, line):
31 line = line.replace(key, author_aliases[key])
35 ## Returns dict of {'author': #_of_commits} from a release note
36 def authors_in_release_notes(filename):
37 note = os.path.join(doc_dir, 'release-notes', filename)
38 with open(note, 'r') as f:
41 first_name, commits = parse_authors(line)
42 authors[apply_author_aliases(first_name)] = commits
44 if line in ['\n', '\r\n']:
45 for author in islice(f, 1):
46 name, commits = parse_authors(author)
47 authors[apply_author_aliases(name)] = commits
50 ## Sums commits made by contributors in each Zcash release note in ./doc/release-notes and writes to authors.md
51 def document_authors():
52 print "Writing contributors documented in release-notes directory to authors.md."
53 authors_file = os.path.join(doc_dir, 'authors.md')
54 with open(authors_file, 'w') as f:
55 f.write('Zcash Contributors\n==================\n\n')
57 for notes in os.listdir(os.path.join(doc_dir, 'release-notes')):
58 authors = authors_in_release_notes(notes)
59 for author in authors:
60 commits = int(authors[author])
61 if author in total_contrib:
62 total_contrib[author] += commits
64 total_contrib[author] = commits
65 sorted_contrib = sorted(total_contrib.items(), key=itemgetter(1, 0), reverse=True)
66 for n, c in sorted_contrib:
68 f.write("{0} ({1})\n".format(n, c))
70 ## Writes release note to ./doc/release-notes based on git shortlog when current version number is specified
71 def generate_release_note(version, filename):
72 print "Automatically generating release notes for {0} from git shortlog. Should review {1} for accuracy.".format(version, filename)
73 latest_tag = subprocess.Popen(['git describe --abbrev=0'], shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
74 print "Previous release tag: ", latest_tag
75 notes = subprocess.Popen(['git shortlog --no-merges {0}..HEAD'.format(latest_tag)], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[0]
76 lines = notes.split('\n')
77 lines = [alias_authors_in_release_notes(line) for line in lines]
78 release_note = os.path.join(doc_dir, 'release-notes', 'release-notes-{0}.md'.format(version))
79 with open(release_note, 'w') as f:
80 f.writelines('\n'.join(lines))
82 def main(version, filename):
84 generate_release_note(version, filename)
87 if __name__ == "__main__":
88 parser = argparse.ArgumentParser()
89 parser.add_argument('--version')
90 args = parser.parse_args()
92 root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
93 doc_dir = os.path.join(root_dir, 'doc')
97 version = args.version
98 filename = 'release-notes-{0}.md'.format(version)
99 main(version, filename)