Skip to content

Commit 9ac6f33

Browse files
committed
Avoid duplicate entires when generating changelog
1 parent 555f64d commit 9ac6f33

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

scripts/generate_changelog.py

+36-17
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,22 @@ def print_section(crate: str, items: List[str]) -> None:
115115
print()
116116

117117

118+
def changelog_filepath(crate: str) -> str:
119+
scripts_dirpath = os.path.dirname(os.path.realpath(__file__))
120+
if crate == "egui":
121+
file_path = f"{scripts_dirpath}/../CHANGELOG.md"
122+
else:
123+
file_path = f"{scripts_dirpath}/../crates/{crate}/CHANGELOG.md"
124+
return os.path.normpath(file_path)
125+
126+
118127
def add_to_changelog_file(crate: str, items: List[str], version: str) -> None:
119128
insert_text = f"\n## {version} - {date.today()}\n"
120129
for item in items:
121130
insert_text += f"* {item}\n"
122131
insert_text += "\n"
123132

124-
scripts_dirpath = os.path.dirname(os.path.realpath(__file__))
125-
if crate == "egui":
126-
file_path = f"{scripts_dirpath}/../CHANGELOG.md"
127-
else:
128-
file_path = f"{scripts_dirpath}/../crates/{crate}/CHANGELOG.md"
129-
file_path = os.path.normpath(file_path)
133+
file_path = changelog_filepath(crate)
130134

131135
with open(file_path, 'r') as file:
132136
content = file.read()
@@ -151,6 +155,28 @@ def main() -> None:
151155
print("ERROR: --version is required when --write is used")
152156
sys.exit(1)
153157

158+
crate_names = [
159+
"ecolor",
160+
"eframe",
161+
"egui_extras",
162+
"egui_plot",
163+
"egui_glow",
164+
"egui-wgpu",
165+
"egui-winit",
166+
"egui",
167+
"epaint",
168+
]
169+
170+
# We read all existing changelogs to remove duplicate entries.
171+
# For instance: the PRs that were part of 0.27.2 would also show up in the diff for `0.27.0..HEAD`
172+
# when its time for a 0.28 release. We can't do `0.27.2..HEAD` because we would miss PRs that were
173+
# merged before in `0.27.0..0.27.2` that were not cherry-picked into `0.27.2`.
174+
all_changelogs = ""
175+
for crate in crate_names:
176+
file_path = changelog_filepath(crate)
177+
with open(file_path, 'r') as file:
178+
all_changelogs += file.read()
179+
154180
repo = Repo(".")
155181
commits = list(repo.iter_commits(args.commit_range))
156182
commits.reverse() # Most recent last
@@ -167,17 +193,6 @@ def main() -> None:
167193

168194
ignore_labels = ["CI", "dependencies"]
169195

170-
crate_names = [
171-
"ecolor",
172-
"eframe",
173-
"egui_extras",
174-
"egui_plot",
175-
"egui_glow",
176-
"egui-wgpu",
177-
"egui-winit",
178-
"egui",
179-
"epaint",
180-
]
181196
sections = {}
182197
unsorted_prs = []
183198
unsorted_commits = []
@@ -193,6 +208,10 @@ def main() -> None:
193208
summary = f"{title} [{hexsha[:7]}](https://github.com/{OWNER}/{REPO}/commit/{hexsha})"
194209
unsorted_commits.append(summary)
195210
else:
211+
if f"[#{pr_number}]" in all_changelogs:
212+
print(f"Ignoring PR that is already in the changelog: #{pr_number}")
213+
continue
214+
196215
# We prefer the PR title if available
197216
title = pr_info.pr_title if pr_info else title
198217
labels = pr_info.labels if pr_info else []

0 commit comments

Comments
 (0)