Skip to content

Commit 3a72a2a

Browse files
committed
Changelog conversion script improvements and bugfix (#102)
1 parent 52c03bb commit 3a72a2a

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

tools/asciidoc_to_fragments.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,24 @@
88
from os import makedirs
99
from os.path import expanduser
1010
from datetime import datetime
11-
11+
from hashlib import sha1
12+
13+
# Using this script
14+
# Run it from destination repository root with:
15+
# python /path/to/elastic-agent-changelog-tool/tools/asciidoc_to_fragments.py --path CHANGELOG.next.asciidoc --workdir $PWD
16+
#
17+
# If errors arise you should at first try to solve them in the source changelog,
18+
# so that if you re-run the script you are not required to apply the same fixes
19+
# again.
20+
# Fixable errors:
21+
# - look for duplicated entries
22+
# - no response from Github API: look for missing or wrong data (es issue number instead of PR number) in {pull}
23+
# - no PR/issue fields: no {pull} or {issue field present}
24+
# - multiple PRs/issues found: the tool does not support multiple {pull} or {issue} on the same line; split them or remove all but one {issue} and one {pull}
25+
# - issue info lost due to multiple repositories: remove the one referring to an external repository
26+
# - look for files starting with "1000000*", as this timestamp means something is wrong (missing {pull} maybe?)
27+
#
28+
# For the remaining errors, fix them in the created fragments.
1229

1330
api_url = "https://api.github.com/repos/"
1431
github_token_location = "/.elastic/github.token"
@@ -30,20 +47,26 @@
3047
kind_token = "===="
3148
field_token = "-"
3249

33-
def write_fragment(title, fragment_timestamp, fragment_dict):
50+
def write_fragment(filename, fragment_timestamp, fragment_dict):
3451
if not fragment_timestamp:
3552
fragment_timestamp = str(1000000000 + fragments_counter)
3653

3754
path = "".join([fragments_path,
3855
fragment_timestamp,
3956
"-",
40-
title,
57+
filename,
4158
".yaml"])
4259

4360
with open(path, 'w+') as f:
4461
for k, v in fragment_dict.items():
4562
f.write(f"{k}: {v}\n")
4663

64+
# print path and SHA1 of it's content, for verification purposes
65+
with open(path, 'r') as f:
66+
content = f.read()
67+
hash_object = sha1(content.encode('utf-8'))
68+
print(path, hash_object.hexdigest())
69+
4770
def get_event_timestamp(repository, event, number):
4871
token_path = ''.join([expanduser("~"), github_token_location])
4972
with open(token_path, 'r') as f:
@@ -106,10 +129,8 @@ def parse_line(line, kind):
106129
issue_number, issue_repo = number, repo_link
107130

108131
if pr_repo:
109-
fragment_dict["repository"] = pr_repo
110132
fragment_timestamp = get_event_timestamp(pr_repo, "pulls", pr_number)
111133
elif issue_repo:
112-
fragment_dict["repository"] = issue_repo
113134
fragment_timestamp = get_event_timestamp(issue_repo, "issues", issue_number)
114135

115136
if fragment_timestamp == "not_found":

0 commit comments

Comments
 (0)