-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate-changelog.py
executable file
·36 lines (32 loc) · 1.21 KB
/
generate-changelog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
def marshall_artifacts(artifact_id):
artifacts = artifact_id.split(',')
for i in range(len(artifacts)):
index = artifacts[i].find(":")
artifacts[i] = artifacts[i][:index + 1] + " " + artifacts[i][index + 1:]
artifacts[i] = "- " + artifacts[i]
return "\n".join(artifacts)
def append_to_output(output, name, artifact_id):
output += "\n"
output += "### " + name + "\n"
output += marshall_artifacts(artifact_id) + "\n"
return output
import json
with open("./manifest.json") as f:
data = json.load(f)
builds = data["builds"]
changes = ""
for build in builds:
name = build["name"]
if changes == "":
changes += "## " + build["custom_data"]["sourcegraph_version"] + "\n"
changes += "\n ## Updates \n"
artifact_id = build["artifact_id"]
changes = append_to_output(changes, name, artifact_id)
changes = changes + "\n"
changes.split('\n')
with open("CHANGELOG.md", 'r+') as fd:
contents = fd.readlines()
contents.insert(74, changes) # new_string should end in a newline
fd.seek(0) # readlines consumes the iterator, so we need to start over
fd.writelines(contents) # No need to truncate as we are increasing filesize