diff --git a/releasenotes/notes/release-date-3a1dec42c91a3f0b.yaml b/releasenotes/notes/release-date-3a1dec42c91a3f0b.yaml new file mode 100644 index 0000000..9934fc4 --- /dev/null +++ b/releasenotes/notes/release-date-3a1dec42c91a3f0b.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add an option, ``add_release_date``, to print the release dates for every + version. diff --git a/reno/config.py b/reno/config.py index fe32c19..da1d13c 100644 --- a/reno/config.py +++ b/reno/config.py @@ -64,6 +64,12 @@ _OPTIONS = [ The template used by reno new to create a note. """)), + Opt('add_release_date', False, + textwrap.dedent("""\ + Should the report include release date (True) based on + the date of objects associated with the release tag. + """)), + Opt('release_tag_re', textwrap.dedent('''\ ((?:v?[\\d.ab]|rc)+) # digits, a, b, and rc cover regular and diff --git a/reno/formatter.py b/reno/formatter.py index a4f8742..a6172b8 100644 --- a/reno/formatter.py +++ b/reno/formatter.py @@ -11,6 +11,7 @@ # under the License. from __future__ import print_function +from datetime import datetime def _indent_for_list(text, prefix=' '): @@ -71,6 +72,15 @@ def format_report(loader, config, versions_to_include, title=None, report.append('=' * len(version_title)) report.append('') + if (config.add_release_date + # Currently, this only works when the Scanner is used + and loader._scanner is not None + and version in loader._scanner._repo._tags_to_dates.keys()): + date = datetime.fromtimestamp( + loader._scanner._repo._tags_to_dates[version]) + report.append('Release Date: ' + date.strftime("%Y-%m-%d")) + report.append('') + # Add the preludes. notefiles = loader[version] prelude_name = config.prelude_section_name diff --git a/reno/scanner.py b/reno/scanner.py index 02129dc..75785ae 100644 --- a/reno/scanner.py +++ b/reno/scanner.py @@ -391,6 +391,7 @@ class RenoRepo(repo.Repo): # Populated by _load_tags(). _all_tags = None _shas_to_tags = None + _tags_to_dates = None def _get_commit_from_tag(self, tag, tag_sha): """Return the commit referenced by the tag and when it was tagged.""" @@ -434,9 +435,11 @@ class RenoRepo(repo.Repo): if k.startswith(b'refs/tags/') } self._shas_to_tags = {} + self._tags_to_dates = {} for tag, tag_sha in self._all_tags.items(): tagged_sha, date = self._get_commit_from_tag(tag, tag_sha) self._shas_to_tags.setdefault(tagged_sha, []).append((tag, date)) + self._tags_to_dates[tag] = date def get_tags_on_commit(self, sha): "Return the tag(s) on a commit, in application order."