Skip to content

Commit f67ba91

Browse files
Add asciidoc changelog to fragments script (#71)
Co-authored-by: Edoardo Tenani <[email protected]>
1 parent 27cd2c2 commit f67ba91

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed

tools/CHANGELOG.next.asciidoc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Use these for links to issue and pulls. Note issues and pulls redirect one to
2+
// each other on Github, so don't worry too much on using the right prefix.
3+
:issue-beats: https://github.com/elastic/beats/issues/
4+
:pull-beats: https://github.com/elastic/beats/pull/
5+
6+
:issue: https://github.com/elastic/elastic-agent/issues/
7+
:pull: https://github.com/elastic/elastic-agent/pull/
8+
9+
=== Elastic Agent version HEAD
10+
11+
==== Breaking changes
12+
13+
- Docker container is not run as root by default. {pull-beats}[21213]
14+
- Read Fleet connection information from `fleet.*` instead of `fleet.kibana.*`. {pull-beats}[24713]
15+
16+
==== Bugfixes
17+
18+
- diagnostics collect log names are fixed on Windows machines, command will ignore failures. AgentID is included in diagnostics(and diagnostics collect) output. {issue}81[81] {issue}92[92] {issue}190[190] {pull}262[262]
19+
- Allow the / char in variable names in eql and transpiler. {issue}715[715] {pull}718[718]
20+
- Fix data duplication for standalone agent on Kubernetes using the default manifest {issue-beats}31512[31512] {pull}742[742]
21+
- Agent updates will clean up unneeded artifacts. {issue}693[693] {issue}694[694] {pull}752[752]
22+
23+
==== New features
24+
25+
- Allow pprof endpoints for elastic-agent or beats if enabled. {pull-beats}[28983] {pull-beats}[29155]
26+
- Set `agent.id` to the Fleet Agent ID in events published from inputs backed by Beats. {issue-beats}[21121] {pull-beats}[26394] {pull-beats}[26548]
27+
- Agent now adapts the beats queue size based on output settings. {issue-beats}[26638] {pull-beats}[27429]
28+
- Support ephemeral containers in Kubernetes dynamic provider. {issue-beats}[#27020] {pull-beats}[27707]
29+
- Add support for enabling the metrics buffer endpoint in the elastic-agent and beats it runs. diagnostics collect command will gather metrics-buffer data if enabled. {pull-beats}[30471]
30+
- Changed the default policy selection logic. When the agent has no policy id or name defined, it will fall back to defaults (defined by $FLEET_SERVER_POLICY_ID and $FLEET_DEFAULT_TOKEN_POLICY_NAME environment variables respectively). {issue-beats}[29774] {pull}226[226]
31+
- Support scheduled actions and cancellation of pending actions. {issue}393[393] {pull}419[419]
32+
- Bump node.js version for heartbeat/synthetics to 16.15.0

tools/asciidoc_to_fragments.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
# or more contributor license agreements. Licensed under the Elastic License 2.0;
3+
# you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
import time
6+
import argparse
7+
from os import makedirs
8+
9+
10+
timestamp = round(time.time())
11+
12+
fragments_path = "changelog/fragments/"
13+
fragments_counter = 0
14+
15+
repo_dict = {
16+
"agent": "https://github.com/elastic/elastic-agent",
17+
"beats": "https://github.com/elastic/beats"
18+
}
19+
default_repolink = "https://github.com/elastic/elastic-agent"
20+
21+
kind_dict = {
22+
"Breaking changes": "breaking-change",
23+
"Bugfixes": "bug-fix",
24+
"New features": "feature",
25+
}
26+
kind_token = "===="
27+
field_token = "-"
28+
29+
30+
def write_fragment(title, fragment_dict):
31+
path = "".join([fragments_path,
32+
str(timestamp + fragments_counter),
33+
"-",
34+
title,
35+
".yaml"])
36+
37+
with open(path, 'w+') as f:
38+
for k, v in fragment_dict.items():
39+
f.write(f"{k}: {v}\n")
40+
41+
def parse_line(line, kind):
42+
global fragments_counter
43+
fragments_counter += 1
44+
45+
summary, *entries = line.split(" {")
46+
if len(entries) == 0:
47+
print(f"Warning: {line} has no PR/issue fields!\n")
48+
49+
fragment_dict = {"kind": kind}
50+
fragment_dict["summary"] = summary.lstrip(field_token).strip()
51+
fragment_dict["summary"] = fragment_dict["summary"].replace(":", "")
52+
53+
title = fragment_dict["summary"]
54+
title = title.replace(" ", "-")
55+
title = title.replace("/", "|")
56+
title = title.rstrip(".")
57+
58+
repo_link = ""
59+
60+
for entry in entries:
61+
number = entry[entry.find("[")+1:entry.find("]")]
62+
number = ''.join(filter(lambda n: n.isdigit(), number))
63+
64+
if "pull" in entry:
65+
fragment_field, default_repo_token = ["pr", "pull}"]
66+
if "issue" in entry:
67+
fragment_field, default_repo_token = ["issue", "issue}"]
68+
69+
if fragment_field in fragment_dict.keys():
70+
print(f"Skipping {line} -> multiple PRs/issues found!\n")
71+
return
72+
73+
fragment_dict[fragment_field] = number
74+
75+
if entry.startswith(default_repo_token):
76+
if repo_link:
77+
if repo_link != default_repolink:
78+
print(f"Skipping {line} -> multiple repositories found!\n")
79+
return
80+
repo_link = default_repolink
81+
else:
82+
for repo in repo_dict.keys():
83+
if repo in entry:
84+
if repo_link and repo_link != repo_dict[repo]:
85+
print(f"Skipping {line} -> multiple repositories found!\n")
86+
return
87+
repo_link = repo_dict[repo]
88+
89+
if repo_link:
90+
fragment_dict["repository"] = repo_link
91+
92+
write_fragment(title, fragment_dict)
93+
94+
95+
def iterate_lines(f, kind='', skip=True):
96+
line = next(f, None)
97+
if line is None:
98+
return
99+
100+
if line.startswith(kind_token):
101+
iterate_lines(f, kind_dict[line.lstrip(kind_token).strip()], skip=False)
102+
103+
elif line.isspace():
104+
iterate_lines(f, kind, skip)
105+
106+
elif line.startswith(field_token) and skip is False:
107+
parse_line(line, kind)
108+
109+
else:
110+
iterate_lines(f, kind, skip=True)
111+
112+
iterate_lines(f, kind, skip)
113+
114+
if __name__ == "__main__":
115+
parser = argparse.ArgumentParser()
116+
parser.add_argument("--path", help="Changelog file path", required=True)
117+
parser.add_argument("--workdir", help="Working directory path")
118+
parser.add_argument("--repo", help="Repository name")
119+
args = parser.parse_args()
120+
121+
if args.workdir:
122+
args.path = ''.join([args.workdir, '/', args.path])
123+
fragments_path = ''.join([args.workdir, '/', fragments_path])
124+
125+
if args.repo:
126+
default_repolink = repo_dict[args.repo]
127+
128+
try:
129+
makedirs(fragments_path)
130+
except FileExistsError as e:
131+
pass
132+
133+
print("Skipped entries should be manually created")
134+
with open(args.path, 'r') as f:
135+
iterate_lines(f)

0 commit comments

Comments
 (0)