Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions stub_uploader/update_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def update_changelog(
if not log:
print(f"{distribution}: Changelog unchanged")
return
new_entry = process_git_log(log, version)
today = datetime.date.today()
new_entry = process_git_log(log, version, today)

changelog = os.path.join(CHANGELOG_PATH, f"{distribution}.md")
try:
Expand All @@ -84,8 +85,7 @@ def update_changelog(
f.write(new_entry + old_entries)


def process_git_log(log: str, version: str) -> str:
today = datetime.date.today()
def process_git_log(log: str, version: str, today: datetime.date) -> str:
entry = f"## {version} ({today:%Y-%m-%d})\n"
for line in log.splitlines():
if line.strip() == "":
Expand All @@ -96,6 +96,10 @@ def process_git_log(log: str, version: str) -> str:
else:
pass # Ignore header entries.
entry += "\n"
# Create hyperlinks for PR numbers.
entry = re.sub(
r"\(#(\d+)\)", r"([#\1](https://github.com/python/typeshed/pull/\1))", entry
)
# Strip multiple empty lines.
return re.sub("\n\n+", "\n\n", entry)

Expand Down
27 changes: 27 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from stub_uploader.get_version import compute_stub_version, ensure_specificity
from stub_uploader.metadata import Metadata, _UploadedPackages, strip_types_prefix
from stub_uploader.ts_data import TypeshedData, parse_requirements, read_typeshed_data
from stub_uploader.update_changelog import process_git_log


def test_strip_types_prefix() -> None:
Expand Down Expand Up @@ -322,3 +323,29 @@ def test_upstream_repo_validation(data: dict[str, Any], expected: str | None) ->
m = Metadata("foo", data)
assert m.upstream_repository == expected
assert type(m.upstream_repository) is type(expected)


def test_process_git_log() -> None:
git_log = """
commit 126768408a69b7a3a09b7d3992970b289f92937e

Replace `Incomplete | None = None` in third party stubs (#14063)

commit 337fd828e819988af2d3600283d8068bbbab7f50

Bump setuptools to 80.7.* (#14069)

Body text #12345 python/typeshed#12345 https://example.com/#123
"""
expected_entry = f"""\
## 80.7.0.{TODAY_V} ({TODAY:%Y-%m-%d})

Replace `Incomplete | None = None` in third party stubs ([#14063](https://github.com/python/typeshed/pull/14063))

Bump setuptools to 80.7.* ([#14069](https://github.com/python/typeshed/pull/14069))

Body text #12345 python/typeshed#12345 https://example.com/#123

"""
actual_entry = process_git_log(git_log, f"80.7.0.{TODAY_V}", TODAY)
assert actual_entry == expected_entry