bin: make update-authors.py add multiple contributors in a single commit

When more than one new contributor is found, list their names in the
commit body rather than making one commit per person.
This commit is contained in:
Nick Craig-Wood committed 2026-09-10 16:57:15 +01:00
1 parent 3fe205796a
commit e7bc3b2483
1 file changed
+22 -6
+22 -6
View File
@@ -17,15 +17,28 @@ def load(filename):
authors = fd.read()
return set(re.findall(r"<(.*?)>", authors))
def add_email(name, email):
def add_email(added, name, email):
"""
adds the email passed in to the end of authors.md
adds the email passed in to the end of authors.md and records it in added
"""
print("Adding %s <%s>" % (name, email))
with open(AUTHORS, "a+") as fd:
print("- %s <%s>" % (name, email), file=fd)
subprocess.check_call(["git", "commit", "-m", "Add %s to contributors" % name, AUTHORS])
added.append((name, email))
def commit(added):
"""
commits authors.md with a message describing the names in added
"""
if not added:
return
if len(added) == 1:
message = "Add %s to contributors" % added[0][0]
else:
message = "Add %d new contributors\n\n" % len(added)
message += "".join("- %s\n" % name for name, _ in added)
subprocess.check_call(["git", "commit", "-m", message, AUTHORS])
def main():
# Add emails from authors
out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"])
@@ -34,6 +47,7 @@ def main():
ignored = load(IGNORE)
previous = load(AUTHORS)
previous.update(ignored)
added = []
for line in out.split("\n"):
line = line.strip()
if line == "":
@@ -42,7 +56,7 @@ def main():
if email in previous:
continue
previous.add(email)
add_email(name, email)
add_email(added, name, email)
# Add emails from Co-authored-by: lines
out = subprocess.check_output(["git", "log", '-i', '--grep', 'Co-authored-by:', "master"])
@@ -60,7 +74,9 @@ def main():
if email in previous:
continue
previous.add(email)
add_email(name, email)
add_email(added, name, email)
commit(added)
if __name__ == "__main__":
main()