generate_changelog.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. """ Generate a changelog for JupyterLab from the GitHub releases """
  2. # Copyright (c) Jupyter Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. import re
  5. import dateutil.parser
  6. import requests
  7. # Get the list of releases.
  8. r = requests.get("https://api.github.com/repos/jupyterlab/jupyterlab/releases")
  9. if r.status_code == 200:
  10. releases = r.json()
  11. with open("CHANGELOG.md", "w") as f:
  12. f.write("# JupyterLab Changelog\n\n")
  13. for release in releases:
  14. name = release["name"]
  15. tag_name = release["tag_name"]
  16. tag_url = release["html_url"]
  17. tag_date = dateutil.parser.parse(release["published_at"])
  18. notes = release["body"].replace("\r\n", "\n")
  19. notes = re.sub(
  20. r"#([0-9]+)", r"[#\1](https://github.com/jupyterlab/jupyterlab/issues/\1)", notes
  21. )
  22. title = f"{name} ({tag_name})" if name != tag_name else name
  23. f.write(f"## [{title}]({tag_url})\n")
  24. f.write(f'#### {tag_date.strftime("%b %d, %Y")}\n')
  25. f.write(notes)
  26. f.write("\n\n")