extractFeaturesFromReleaseNotes.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python3
  2. #
  3. # extractFeaturesFromReleaseNotes.py
  4. #
  5. # Read the release notes - docs/release-notes.md - and generate text
  6. # for pasting in to individual documentation pages, to indicate which
  7. # versions recent features were released in.
  8. #
  9. # Using the output of the file is easier than manually constructing
  10. # the text to paste in to documentation pages.
  11. #
  12. # One way to use this:
  13. # - run this script, saving the output to some temporary file
  14. # - diff this output with the actual release notes page
  15. # - the differences are Markdown text that can be pasted in to the
  16. # appropriate documentation pages in the docs/ directory.
  17. # - each release also has a github link to show which documentation files
  18. # were changed in it.
  19. # This can be helpful to see which documentation pages
  20. # to add the 'Introduced in Catch ...' snippets to the relevant pages.
  21. #
  22. from __future__ import print_function
  23. import re
  24. def create_introduced_in_text(version, bug_number = None):
  25. """Generate text to paste in to documentation file"""
  26. if bug_number:
  27. return '> [Introduced](https://github.com/catchorg/Catch2/issues/%s) in Catch %s.' % (bug_number, version)
  28. else:
  29. # Use this text for changes that don't have issue numbers
  30. return '> Introduced in Catch %s.' % version
  31. def link_to_changes_in_release(release, releases):
  32. """
  33. Markdown text for a hyperlink showing all edits in a release, or empty string
  34. :param release: A release version, as a string
  35. :param releases: A container of releases, in descending order - newest to oldest
  36. :return: Markdown text for a hyperlink showing the differences between the give release and the prior one,
  37. or empty string, if the previous release is not known
  38. """
  39. if release == releases[-1]:
  40. # This is the earliest release we know about
  41. return ''
  42. index = releases.index(release)
  43. previous_release = releases[index + 1]
  44. return '\n[Changes in %s](https://github.com/catchorg/Catch2/compare/v%s...v%s)' % (release, previous_release, release)
  45. def write_recent_release_notes_with_introduced_text():
  46. current_version = None
  47. release_toc_regex = r'\[(\d.\d.\d)\]\(#\d+\)<br>'
  48. issue_number_regex = r'#[0-9]+'
  49. releases = []
  50. with open('../docs/release-notes.md') as release_notes:
  51. for line in release_notes:
  52. line = line[:-1]
  53. print(line)
  54. # Extract version number from table of contents
  55. match = re.search(release_toc_regex, line)
  56. if match:
  57. release_name = match.group(1)
  58. releases.append(release_name)
  59. if line.startswith('## '):
  60. # It's a section with version number
  61. current_version = line.replace('## ', '')
  62. # We decided not to add released-date info for older versions
  63. if current_version == 'Older versions':
  64. break
  65. print(create_introduced_in_text(current_version))
  66. print(link_to_changes_in_release(current_version, releases))
  67. # Not yet found a version number, so to avoid picking up hyperlinks to
  68. # version numbers in the index, keep going
  69. if not current_version:
  70. continue
  71. for bug_link in re.findall(issue_number_regex, line):
  72. bug_number = bug_link.replace('#', '')
  73. print(create_introduced_in_text(current_version, bug_number))
  74. if __name__ == '__main__':
  75. write_recent_release_notes_with_introduced_text()