-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite_existing.py
81 lines (70 loc) · 2.24 KB
/
rewrite_existing.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Uses the GitHub command line tool to easily rewrite a existing release note
How To Use:
python -m path_to_repository previousTag..nextTag [filter_path1 filter_path2]
"""
import subprocess
from argparse import ArgumentParser
from changelog_generator.generator import generate
def run():
parser = ArgumentParser()
parser.add_argument(
"repository_path",
help="The path to the repository",
)
parser.add_argument(
"target",
help="A rev1..rev2 string to be used to generate the commit list",
)
parser.add_argument(
"filter_paths",
nargs="*",
help="A space separated list of path to be used to the commits that edited files within "
"them",
)
args = parser.parse_args()
target = args.target
filter_paths = args.filter_paths
path = args.repository_path
update_release_note(filter_paths, path, target)
def update_release_note(filter_paths, path, target, create: bool = True):
tag_n, tag_n1 = target.split("..")
print("Will rewrite the release with the commits between ", tag_n, tag_n1)
changelog = generate(path, target=target, filter_paths=filter_paths)
changelog = changelog[:125000]
try:
# checking if the release exists
subprocess.check_output(
["gh", "release", "view", tag_n1],
input=changelog.encode(),
cwd=path,
)
except subprocess.CalledProcessError:
print(f"the tag {tag_n1} exists but has not been released yet")
if create:
print(
subprocess.check_output(
[
"gh",
"release",
"create",
tag_n1,
"--title",
f"Release {tag_n1}",
"-F",
"-",
],
input=changelog.encode(),
cwd=path,
)
)
else:
print(
subprocess.check_output(
["gh", "release", "edit", tag_n1, "-F", "-"],
input=changelog.encode(),
cwd=path,
)
)
if __name__ == "__main__":
run()