make_changelog.py 1.28 KB
Newer Older
1
2
3
4
#!/usr/bin/env python3

import re

5
6
7
import ghapi.all
from rich import print
from rich.syntax import Syntax
8
9
10
11
12
13
14
15
16
17
18
19
20
21

ENTRY = re.compile(
    r"""
    Suggested \s changelog \s entry:
    .*
    ```rst
    \s*
    (.*?)
    \s*
    ```
""",
    re.DOTALL | re.VERBOSE,
)

22
23
print()

24

25
api = ghapi.all.GhApi(owner="pybind", repo="pybind11")
26

27
28
29
30
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)
31
32
33
missing = []

for issue in issues:
34
35
36
37
    changelog = ENTRY.findall(issue.body or "")
    if not changelog or not changelog[0]:
        missing.append(issue)
    else:
38
39
40
41
42
43
        (msg,) = changelog
        if not msg.startswith("* "):
            msg = "* " + msg
        if not msg.endswith("."):
            msg += "."

44
45
        msg += f"\n  `#{issue.number} <{issue.html_url}>`_"

46
        print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True))
47
        print()
48
49
50

if missing:
    print()
51
    print("[blue]" + "-" * 30)
52
53
54
    print()

    for issue in missing:
55
56
57
58
59
60
61
62
        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()