]> Git Repo - VerusCoin.git/blob - zcutil/release-notes.py
Auto merge of #1978 - str4d:1941-scan-whole-chain-on-zkey-import, r=ebfull
[VerusCoin.git] / zcutil / release-notes.py
1 import re, sys, os, os.path
2 import subprocess
3 import argparse
4 from itertools import islice
5 from operator import itemgetter
6
7 author_aliases = {
8     'Simon': 'Simon Liu',
9     'bitcartel': 'Simon Liu',
10     'EthanHeilman': 'Ethan Heilman',
11 }
12
13 def apply_author_aliases(name):
14     if name in author_aliases:
15         return author_aliases[name]
16     else:
17         return name
18
19 def parse_authors(line):
20     commit_search = re.search('(\d+)', line)
21     if commit_search:
22         commits = commit_search.group(1)
23     else:
24         commits = 0
25     name = re.sub(' \(\d+\)|:|\n|\r\n$', '', line)
26     return name, commits
27
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])
32             break
33     return line
34
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:
39         authors = {}
40         line = f.readline()
41         first_name, commits = parse_authors(line)
42         authors[apply_author_aliases(first_name)] = commits
43         for line in f:
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
48         return authors
49
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')
56         total_contrib = {}
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
63                 else:
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:
67             if c != 0:
68                 f.write("{0} ({1})\n".format(n, c))
69
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))
81
82 def main(version, filename):
83     if version != None:
84         generate_release_note(version, filename)
85     document_authors()
86
87 if __name__ == "__main__":
88     parser = argparse.ArgumentParser()
89     parser.add_argument('--version')
90     args = parser.parse_args()
91
92     root_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
93     doc_dir = os.path.join(root_dir, 'doc')
94     version = None
95     filename = None
96     if args.version:
97         version = args.version
98         filename = 'release-notes-{0}.md'.format(version)
99     main(version, filename)
This page took 0.03001 seconds and 4 git commands to generate.