-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_changelog.py
executable file
·112 lines (89 loc) · 3.8 KB
/
write_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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
"""Generate YAML changelog"""
import yaml
from nested_dict import nested_dict
def gen_changelog1():
"""Hard code all PRs in dictionary & convert to YAML."""
dict_file = [
{
"pr-1": {
"meta": {
"url": "https://github.com/mikemadden42/hello-changelog/pull/1",
"author": "mikemadden42",
"hash": "bba923c9b989832ce7b99bfc29d94ba667f5a1b8",
"description": "hello python",
},
"tags": ["release-highlights"],
}
},
{
"pr-2": {
"meta": {
"url": "https://github.com/mikemadden42/hello-changelog/pull/1",
"author": "mikemadden42",
"hash": "bba923c9b989832ce7b99bfc29d94ba667f5a1b8",
"description": "hello python",
},
"tags": ["release-highlights"],
}
},
{
"pr-3": {
"meta": {
"url": "https://github.com/mikemadden42/hello-changelog/pull/3",
"author": "mikemadden42",
"hash": "e6c6efa24c49ae71f13611f9785db9dfa0cc248f",
"description": "hello go",
},
"tags": ["breaking-changes"],
}
},
]
with open(r"changelog.yml", "w") as file:
yaml.dump(dict_file, file)
# The following classes, functions originated on the following site.
# This allows for multi-line changelog entries.
# https://stackoverflow.com/questions/6432605/any-yaml-libraries-in-python-that-support-dumping-of-long-strings-as-block-liter
class FoldedUnicode(str):
pass
class LiteralUnicode(str):
pass
def folded_unicode_representer(dumper, data):
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style=">")
def literal_unicode_representer(dumper, data):
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
yaml.add_representer(FoldedUnicode, folded_unicode_representer)
yaml.add_representer(LiteralUnicode, literal_unicode_representer)
def gen_changelog2():
"""Define all PRs in nested dictionary & convert to YAML."""
changelog = nested_dict()
changelog["pr-1"]["meta"]["author"] = "mikemadden42"
changelog["pr-1"]["meta"]["description"] = "hello python"
changelog["pr-1"]["meta"]["hash"] = "472ab8cb35800f5a228bdb55ef6c792ced3d6e6b"
changelog["pr-1"]["meta"]["url"] = (
"https://github.com/mikemadden42/hello-changelog/pull/1"
)
changelog["pr-1"]["changelog"] = "break(packetbeat): add java example"
changelog["pr-1"]["meta"]["tags"] = ["release-highlights", "breaking-change"]
changelog["pr-2"]["meta"]["author"] = "mikemadden42"
changelog["pr-2"]["meta"]["description"] = "hello rust"
changelog["pr-2"]["meta"]["hash"] = "42e46bdcbd95fc187fe29b0be4e9bf6403a638c6"
changelog["pr-2"]["meta"]["url"] = (
"https://github.com/mikemadden42/hello-changelog/pull/2"
)
changelog["pr-2"]["changelog"] = "break(packetbeat): add java example"
changelog["pr-2"]["meta"]["tags"] = ["breaking-change"]
changelog["pr-3"]["meta"]["author"] = "mikemadden42"
changelog["pr-3"]["meta"]["description"] = "hello go"
changelog["pr-3"]["meta"]["hash"] = "04fcab4a7e9ccfa98ea3e7ee33c192caa5731ae0"
changelog["pr-3"]["meta"]["url"] = (
"https://github.com/mikemadden42/hello-changelog/pull/3"
)
changelog["pr-3"]["changelog"] = LiteralUnicode(
"break(packetbeat): add java example\nfix(functionbeat, journalbeat):hello java"
)
changelog["pr-3"]["meta"]["tags"] = ["backport"]
with open(r"changelog.yml", "w") as file:
yaml.dump(changelog.to_dict(), file)
if __name__ == "__main__":
gen_changelog2()