make_changelog.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_pages = ghapi.page.paged(
  22. api.issues.list_for_repo, labels="needs changelog", state="closed"
  23. )
  24. issues = (issue for page in issues_pages for issue in page)
  25. missing = []
  26. for issue in issues:
  27. changelog = ENTRY.findall(issue.body)
  28. if changelog:
  29. (msg,) = changelog
  30. if not msg.startswith("* "):
  31. msg = "* " + msg
  32. if not msg.endswith("."):
  33. msg += "."
  34. msg += f"\n `#{issue.number} <{issue.html_url}>`_"
  35. print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True))
  36. print()
  37. else:
  38. missing.append(issue)
  39. if missing:
  40. print()
  41. print("[blue]" + "-" * 30)
  42. print()
  43. for issue in missing:
  44. print(f"[red bold]Missing:[/red bold][red] {issue.title}")
  45. print(f"[red] {issue.html_url}\n")
  46. print("[bold]Template:\n")
  47. msg = "## Suggested changelog entry:\n\n```rst\n\n```"
  48. print(Syntax(msg, "md", theme="ansi_light"))
  49. print()