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