generate_changelog.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  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 requests
  6. import dateutil.parser
  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(r'#([0-9]+)',
  20. r'[#\1](https://github.com/jupyterlab/jupyterlab/issues/\1)',
  21. notes)
  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')