2022-09-28 17:17:40 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Example of usage: changelog.py <old-release-tag> <new-release-tag>
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
2022-11-08 14:44:28 +00:00
|
|
|
import collections
|
2022-09-28 17:17:40 +01:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
GENERAL = "General"
|
2022-11-08 14:44:28 +00:00
|
|
|
MULTINODE = "Multinode"
|
2022-09-28 17:17:40 +01:00
|
|
|
SATELLITE = "Satellite"
|
|
|
|
STORAGENODE = "Storagenode"
|
|
|
|
TEST = "Test"
|
|
|
|
UPLINK = "Uplink"
|
|
|
|
GITHUB_LINK = "[{0}](https://github.com/storj/storj/commit/{0})"
|
|
|
|
|
|
|
|
|
|
|
|
def git_ref_field(from_ref, to_ref):
|
|
|
|
# Execute command to show diff without cherry-picks
|
|
|
|
cmd = "git cherry {} {} -v | grep '^+'".format(from_ref, to_ref)
|
|
|
|
ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
output = ps.communicate()[0]
|
|
|
|
return output.decode()
|
|
|
|
|
|
|
|
|
|
|
|
def generate_changelog(commits):
|
|
|
|
changelog = "# Changelog\n"
|
2022-11-08 14:44:28 +00:00
|
|
|
section = {SATELLITE: [], MULTINODE: [], STORAGENODE: [], TEST: [], UPLINK: [], GENERAL: []}
|
2022-09-28 17:17:40 +01:00
|
|
|
|
|
|
|
# Sorting and populating the dictionary d with commit hash and message
|
|
|
|
for commit in commits.splitlines():
|
|
|
|
if TEST.lower() in commit[42:].split(":")[0]:
|
|
|
|
section[TEST].append(generate_line(commit))
|
2022-11-08 14:44:28 +00:00
|
|
|
elif MULTINODE.lower() in commit[42:].split(":")[0]:
|
|
|
|
section[MULTINODE].append(generate_line(commit))
|
2022-09-28 17:17:40 +01:00
|
|
|
elif STORAGENODE.lower() in commit[42:].split(":")[0]:
|
|
|
|
section[STORAGENODE].append(generate_line(commit))
|
|
|
|
elif UPLINK.lower() in commit[42:].split(":")[0]:
|
|
|
|
section[UPLINK].append(generate_line(commit))
|
|
|
|
elif SATELLITE.lower() in commit[42:].split(":")[0]:
|
|
|
|
section[SATELLITE].append(generate_line(commit))
|
|
|
|
else:
|
|
|
|
section[GENERAL].append(generate_line(commit))
|
|
|
|
|
2022-11-08 14:44:28 +00:00
|
|
|
for title in collections.OrderedDict(sorted(section.items())):
|
2022-09-28 17:17:40 +01:00
|
|
|
if section[title]:
|
|
|
|
changelog += ('### {}\n'.format(title))
|
|
|
|
for line in section[title]:
|
|
|
|
changelog += line
|
|
|
|
return changelog
|
|
|
|
|
|
|
|
|
|
|
|
def generate_line(commit):
|
|
|
|
return "- {}{} \n".format(GITHUB_LINK.format(commit[2:9]), commit[42:])
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
p = argparse.ArgumentParser(description=(
|
|
|
|
"generate changelog sorted by topics."))
|
|
|
|
p.add_argument("from_ref", help="the ref to show the path from")
|
|
|
|
p.add_argument("to_ref", help="the ref to show the path to")
|
|
|
|
args = p.parse_args()
|
|
|
|
commits = git_ref_field(args.from_ref, args.to_ref)
|
|
|
|
|
|
|
|
print(generate_changelog(commits))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|