make_changelog.py 1.28 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
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)
34
35
36
37
38
39
40
41
42
43
44
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 += "."

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

47
        print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True))
48
        print()
49
50
51
52
53
54

    else:
        missing.append(issue)

if missing:
    print()
55
    print("[blue]" + "-" * 30)
56
57
58
    print()

    for issue in missing:
59
60
61
62
63
64
65
66
        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()