You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

  1. """Generate the changelog for develop.
  2. This requires the github module:
  3. pip3 install PyGithub
  4. """
  5. from datetime import datetime
  6. from pathlib import Path
  7. import yaml
  8. from milc import cli
  9. from github import Github
  10. def pr_body(text):
  11. """Returns the description from a PR body.
  12. """
  13. lines = []
  14. found = False
  15. for line in text.split('\n'):
  16. if line.startswith('## Description'):
  17. found = True
  18. continue
  19. if line.startswith('## Issues Fixed'):
  20. found = True
  21. lines.append('##### Issues Fixed or Closed by This PR')
  22. continue
  23. if not found:
  24. continue
  25. if line.startswith('##'):
  26. found = False
  27. continue
  28. lines.append(line.rstrip())
  29. new_text = '\n'.join(lines)
  30. return new_text.strip()
  31. @cli.subcommand('Get a list of PRs for develop.', hidden=True)
  32. def generate_develop_changelog(cli):
  33. # Setup the github api
  34. hub_config = yaml.safe_load(Path('~/.config/hub').expanduser().open())
  35. github_token = hub_config['github.com'][0]['oauth_token']
  36. github = Github(github_token)
  37. # Find our branchpoint
  38. master_revs = cli.run(['git', 'rev-list', '--first-parent', 'master'])
  39. develop_revs = cli.run(['git', 'rev-list', '--first-parent', 'develop'])
  40. master_commits = master_revs.stdout.split('\n')
  41. develop_commits = develop_revs.stdout.split('\n')
  42. first_commit = None
  43. for commit in develop_commits:
  44. if commit in master_commits:
  45. branchpoint = commit
  46. break
  47. if not branchpoint:
  48. cli.log.error('Could not find branchpoint!')
  49. exit(1)
  50. # Find the time of our branchpoint
  51. repo = github.get_repo('qmk/qmk_firmware')
  52. bp = repo.get_commit(branchpoint)
  53. last_modified = datetime.strptime(bp.last_modified, '%a, %d %b %Y %H:%M:%S %Z')
  54. # Get a list of PR's targetting develop since last_modified
  55. for pr in repo.get_pulls(state='closed', base='develop'):
  56. if pr.merged and pr.merged_at > last_modified:
  57. print(f'#### {pr.title} ([#{pr.number}](https://github.com/qmk/qmk_firmware/pull/{pr.number}))')
  58. print()
  59. print(pr_body(pr.body))