make_changelog.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import re
  4. import ghapi.all
  5. from rich import print
  6. from rich.syntax import Syntax
  7. ENTRY = re.compile(
  8. r"""
  9. Suggested \s changelog \s entry:
  10. .*
  11. ```rst
  12. \s*
  13. (.*?)
  14. \s*
  15. ```
  16. """,
  17. re.DOTALL | re.VERBOSE,
  18. )
  19. print()
  20. api = ghapi.all.GhApi(owner="pybind", repo="pybind11")
  21. issues = api.issues.list_for_repo(labels="needs changelog", state="closed")
  22. missing = []
  23. for issue in issues:
  24. changelog = ENTRY.findall(issue.body)
  25. if changelog:
  26. (msg,) = changelog
  27. if not msg.startswith("* "):
  28. msg = "* " + msg
  29. if not msg.endswith("."):
  30. msg += "."
  31. msg += f"\n `#{issue.number} <{issue.html_url}>`_"
  32. print(Syntax(msg, "rst", theme="ansi_light"))
  33. print()
  34. else:
  35. missing.append(issue)
  36. if missing:
  37. print()
  38. print("[blue]" + "-" * 30)
  39. print()
  40. for issue in missing:
  41. print(f"[red bold]Missing:[/red bold][red] {issue.title}")
  42. print(f"[red] {issue.html_url}\n")
  43. print("[bold]Template:\n")
  44. msg = "## Suggested changelog entry:\n\n```rst\n\n```"
  45. print(Syntax(msg, "md", theme="ansi_light"))
  46. print()