script to update contributor list automatically
The script merges new contributors in the short-term contributor list in CONTRIBUTORS.rst
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
#!/usr/bin/python2
|
||||
"""List contributors that are not yet in the contributor list
|
||||
"""Update the contributor list
|
||||
|
||||
Alias handling is done by git with .mailmap
|
||||
New contributors are merged in the short-term list.
|
||||
Moving them to a "higher" list should be a manual process.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import fileinput
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
def main():
|
||||
if len(sys.argv) > 1:
|
||||
branch = sys.argv[1]
|
||||
else:
|
||||
branch = "master"
|
||||
def format_contributor(contributor):
|
||||
return " * {0} {1}".format(
|
||||
" ".join(contributor["name"]),
|
||||
contributor["email"])
|
||||
|
||||
|
||||
def main():
|
||||
# generate list of contributors
|
||||
contributors=[]
|
||||
p_git = Popen(["git", "shortlog", "-se", branch], stdout=PIPE)
|
||||
p_git = Popen(["git", "shortlog", "-se"], stdout=PIPE)
|
||||
for line in p_git.stdout:
|
||||
contributors.append({
|
||||
'count': int(line.split("\t")[0].strip()),
|
||||
@@ -22,6 +26,7 @@ def main():
|
||||
'email': line.split("\t")[1].split()[-1]
|
||||
})
|
||||
|
||||
# cache listed contributors
|
||||
old_contributors=[]
|
||||
with open("CONTRIBUTORS.rst", "r") as contrib_file:
|
||||
for line in contrib_file:
|
||||
@@ -35,6 +40,7 @@ def main():
|
||||
# So we parse it anyways and strip it off again.
|
||||
old_emails = map(lambda x: x['email'], old_contributors)
|
||||
|
||||
# check which contributors are new
|
||||
new_contributors=[]
|
||||
for contributor in contributors:
|
||||
if contributor["email"] not in old_emails:
|
||||
@@ -43,9 +49,34 @@ def main():
|
||||
# sort on the last word of the name
|
||||
new_contributors = sorted(new_contributors,
|
||||
key=lambda x: x['name'][-1].lower())
|
||||
|
||||
# show new contributors to be merged to the list
|
||||
for contributor in new_contributors:
|
||||
print "{0:3d} {1:25s} {2}".format(contributor["count"],
|
||||
" ".join(contributor["name"]), contributor["email"])
|
||||
print format_contributor(contributor)
|
||||
|
||||
# merge with contributor list
|
||||
i = 0
|
||||
short_term_found = False
|
||||
for line in fileinput.input("CONTRIBUTORS.rst", inplace=1):
|
||||
if not short_term_found:
|
||||
print line,
|
||||
if "Short-term" in line:
|
||||
short_term_found = True
|
||||
else:
|
||||
if i >= len(new_contributors) or "@" not in line:
|
||||
print line,
|
||||
else:
|
||||
contributor = new_contributors[i]
|
||||
if line.split()[-2] > contributor["name"][-1]:
|
||||
print format_contributor(contributor)
|
||||
i += 1
|
||||
print line,
|
||||
# append remaining contributors
|
||||
with open("CONTRIBUTORS.rst", "a") as contrib_file:
|
||||
while i < len(new_contributors):
|
||||
contrib_file.write(format_contributor(new_contributors[i]) + "\n")
|
||||
i += 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user