make_changelog.py 1.17 KB
Newer Older
1
2
3
4
5
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re

6
7
8
9
import ghapi.all

from rich import print
from rich.syntax import Syntax
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


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

25
26
print()

27

28
api = ghapi.all.GhApi(owner="pybind", repo="pybind11")
29
30
31
32
33
34
35
36
37
38
39
40
41

issues = api.issues.list_for_repo(labels="needs changelog", state="closed")
missing = []

for issue in issues:
    changelog = ENTRY.findall(issue.body)
    if changelog:
        (msg,) = changelog
        if not msg.startswith("* "):
            msg = "* " + msg
        if not msg.endswith("."):
            msg += "."

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

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

    else:
        missing.append(issue)

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

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