Skip to content

Commit f5ea6a0

Browse files
committed
Update CI files
1 parent 2d4da20 commit f5ea6a0

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

.ci/scripts/collect_changes.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@
77
# For more info visit https://github.com/pulp/plugin_template
88

99
import itertools
10+
import json
1011
import os
1112
import re
1213
import tomllib
14+
import urllib.request
15+
from pathlib import Path
1316

1417
from git import GitCommandError, Repo
1518
from packaging.version import parse as parse_version
1619

20+
21+
PYPI_PROJECT = "pulp_deb"
22+
1723
# Read Towncrier settings
18-
with open("pyproject.toml", "rb") as fp:
19-
tc_settings = tomllib.load(fp)["tool"]["towncrier"]
24+
tc_settings = tomllib.loads(Path("pyproject.toml").read_text())["tool"]["towncrier"]
2025

2126
CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst")
2227
START_STRING = tc_settings.get(
@@ -35,7 +40,7 @@
3540
# see help(re.split) for more info.
3641
NAME_REGEX = r".*"
3742
VERSION_REGEX = r"[0-9]+\.[0-9]+\.[0-9][0-9ab]*"
38-
VERSION_CAPTURE_REGEX = rf"({VERSION_REGEX})"
43+
VERSION_CAPTURE_REGEX = rf"(?:YANKED )?({VERSION_REGEX})"
3944
DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}"
4045
TITLE_REGEX = (
4146
"("
@@ -75,6 +80,20 @@ def main():
7580
branches.sort(key=lambda ref: parse_version(ref.remote_head), reverse=True)
7681
branches = [ref.name for ref in branches]
7782

83+
changed = False
84+
85+
try:
86+
response = urllib.request.urlopen(f"https://pypi.org/pypi/{PYPI_PROJECT}/json")
87+
pypi_record = json.loads(response.read())
88+
yanked_versions = {
89+
parse_version(version): release[0]["yanked_reason"]
90+
for version, release in pypi_record["releases"].items()
91+
if release[0]["yanked"] is True
92+
}
93+
except Exception:
94+
# If something failed, just don't mark anything as yanked.
95+
yanked_versions = {}
96+
7897
with open(CHANGELOG_FILE, "r") as f:
7998
main_changelog = f.read()
8099
preamble, main_changes = split_changelog(main_changelog)
@@ -95,9 +114,19 @@ def main():
95114
if left[0] != right[0]:
96115
main_changes.append(right)
97116

117+
if yanked_versions:
118+
for change in main_changes:
119+
if change[0] in yanked_versions and "YANKED" not in change[1].split("\n")[0]:
120+
reason = yanked_versions[change[0]]
121+
version = str(change[0])
122+
change[1] = change[1].replace(version, "YANKED " + version, count=1)
123+
if reason:
124+
change[1] = change[1].replace("\n", f"\n\nYank reason: {reason}\n", count=1)
125+
changed = True
126+
98127
new_length = len(main_changes)
99-
if old_length < new_length:
100-
print(f"{new_length - old_length} new versions have been added.")
128+
if old_length < new_length or changed:
129+
print(f"{new_length - old_length} new versions have been added (or something has changed).")
101130
with open(CHANGELOG_FILE, "w") as fp:
102131
fp.write(preamble)
103132
for change in main_changes:

0 commit comments

Comments
 (0)