2020-12-22 02:04:33 +00:00
|
|
|
#!/usr/bin/env python3
|
2023-11-15 23:59:07 +00:00
|
|
|
from __future__ import annotations
|
2020-12-22 02:04:33 +00:00
|
|
|
|
|
|
|
import re
|
|
|
|
|
2021-01-21 16:34:39 +00:00
|
|
|
import ghapi.all
|
|
|
|
from rich import print
|
|
|
|
from rich.syntax import Syntax
|
2020-12-22 02:04:33 +00:00
|
|
|
|
|
|
|
ENTRY = re.compile(
|
|
|
|
r"""
|
|
|
|
Suggested \s changelog \s entry:
|
|
|
|
.*
|
|
|
|
```rst
|
|
|
|
\s*
|
|
|
|
(.*?)
|
|
|
|
\s*
|
|
|
|
```
|
|
|
|
""",
|
|
|
|
re.DOTALL | re.VERBOSE,
|
|
|
|
)
|
|
|
|
|
2021-01-21 16:34:39 +00:00
|
|
|
print()
|
|
|
|
|
2020-12-22 02:04:33 +00:00
|
|
|
|
2021-01-21 16:34:39 +00:00
|
|
|
api = ghapi.all.GhApi(owner="pybind", repo="pybind11")
|
2020-12-22 02:04:33 +00:00
|
|
|
|
2021-07-12 18:10:46 +00:00
|
|
|
issues_pages = ghapi.page.paged(
|
|
|
|
api.issues.list_for_repo, labels="needs changelog", state="closed"
|
|
|
|
)
|
|
|
|
issues = (issue for page in issues_pages for issue in page)
|
2020-12-22 02:04:33 +00:00
|
|
|
missing = []
|
2023-11-15 23:59:07 +00:00
|
|
|
cats_descr = {
|
|
|
|
"feat": "New Features",
|
|
|
|
"fix": "Bug fixes",
|
|
|
|
"fix(types)": "",
|
|
|
|
"fix(cmake)": "",
|
|
|
|
"docs": "Documentation",
|
|
|
|
"tests": "Tests",
|
|
|
|
"ci": "CI",
|
|
|
|
"chore": "Other",
|
|
|
|
"unknown": "Uncategorised",
|
|
|
|
}
|
|
|
|
cats: dict[str, list[str]] = {c: [] for c in cats_descr}
|
2020-12-22 02:04:33 +00:00
|
|
|
|
|
|
|
for issue in issues:
|
2023-01-03 16:34:22 +00:00
|
|
|
changelog = ENTRY.findall(issue.body or "")
|
|
|
|
if not changelog or not changelog[0]:
|
|
|
|
missing.append(issue)
|
|
|
|
else:
|
2020-12-22 02:04:33 +00:00
|
|
|
(msg,) = changelog
|
2023-11-15 23:59:07 +00:00
|
|
|
if msg.startswith("- "):
|
|
|
|
msg = msg[2:]
|
2020-12-22 02:04:33 +00:00
|
|
|
if not msg.startswith("* "):
|
|
|
|
msg = "* " + msg
|
|
|
|
if not msg.endswith("."):
|
|
|
|
msg += "."
|
|
|
|
|
2021-01-21 16:34:39 +00:00
|
|
|
msg += f"\n `#{issue.number} <{issue.html_url}>`_"
|
2023-11-15 23:59:07 +00:00
|
|
|
for cat in cats:
|
|
|
|
if issue.title.lower().startswith(f"{cat}:"):
|
|
|
|
cats[cat].append(msg)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
cats["unknown"].append(msg)
|
2021-01-21 16:34:39 +00:00
|
|
|
|
2023-11-15 23:59:07 +00:00
|
|
|
for cat, msgs in cats.items():
|
|
|
|
if msgs:
|
|
|
|
desc = cats_descr[cat]
|
|
|
|
print(f"[bold]{desc}:\n" if desc else "")
|
|
|
|
for msg in msgs:
|
|
|
|
print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True))
|
2021-01-21 16:34:39 +00:00
|
|
|
print()
|
2020-12-22 02:04:33 +00:00
|
|
|
|
|
|
|
if missing:
|
|
|
|
print()
|
2021-01-21 16:34:39 +00:00
|
|
|
print("[blue]" + "-" * 30)
|
2020-12-22 02:04:33 +00:00
|
|
|
print()
|
|
|
|
|
|
|
|
for issue in missing:
|
2021-01-21 16:34:39 +00:00
|
|
|
print(f"[red bold]Missing:[/red bold][red] {issue.title}")
|
|
|
|
print(f"[red] {issue.html_url}\n")
|
|
|
|
|
|
|
|
print("[bold]Template:\n")
|
|
|
|
msg = "## Suggested changelog entry:\n\n```rst\n\n```"
|
|
|
|
print(Syntax(msg, "md", theme="ansi_light"))
|
|
|
|
|
|
|
|
print()
|