Skip to content

Commit

Permalink
Merge ac24cc8 into 381a2cb
Browse files Browse the repository at this point in the history
  • Loading branch information
schunka committed Mar 3, 2021
2 parents 381a2cb + ac24cc8 commit b6de5bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
* Existing CHANGELOGs will start using these headers after the new run of `changelog release`

### Fixed
* keeping format of `release line`
* Fix Description for pypi

### Removed
Expand Down
16 changes: 10 additions & 6 deletions src/changelog/templates.py
Expand Up @@ -6,10 +6,14 @@

DEFAULT_VERSION = "0.0.0"

RELEASE_LINE = "## {} - ({})\n"
RELEASE_LINE = {
"date": "## {} - ({})\n",
"pure": "## {}\n",
"bracket_date": "## [{}] - {}\n"
}

RELEASE_LINE_REGEXES = [
r"^##\s(?P<v>\d+\.\d+\.\d+)\s\-\s\(\d{4}-\d{2}-\d{2}\)$",
r"^##\sv?(?P<v>\d+\.\d+\.\d+)",
r"^##\s\[(?P<v>\d+\.\d+\.\d+)\]\s\-\s\d{4}-\d{2}-\d{2}$",
]
RELEASE_LINE_REGEXES = {
"date": r"^##\s(?P<v>\d+\.\d+\.\d+)\s\-\s\(\d{4}-\d{2}-\d{2}\)$",
"pure": r"^##\sv?(?P<v>\d+\.\d+\.\d+)",
"bracket_date": r"^##\s\[(?P<v>\d+\.\d+\.\d+)\]\s\-\s\d{4}-\d{2}-\d{2}$"
}
6 changes: 4 additions & 2 deletions src/changelog/utils.py
Expand Up @@ -22,6 +22,7 @@ class ChangelogUtils:

UNRELEASED: str = "\n## Unreleased\n---\n\n" + ''.join([f"{section_header}\n\n" for section_header in REVERSE_SECTIONS.keys()])
INIT: str = BASE + UNRELEASED
VERSION_FORMAT: str = "date"

def initialize_changelog_file(self) -> str:
"""
Expand Down Expand Up @@ -123,7 +124,7 @@ def cut_release(self, release_type: str = "suggest") -> None:
reading = False
if line == "## Unreleased\n":
unreleased_position = i
line = RELEASE_LINE.format(new_version, date.today().isoformat())
line = RELEASE_LINE[self.VERSION_FORMAT].format(new_version, date.today().isoformat())
if reading and line in self.REVERSE_SECTIONS and self.REVERSE_SECTIONS[line] not in change_types:
continue
output.append(line)
Expand Down Expand Up @@ -167,8 +168,9 @@ def match_version(self, line: str) -> Optional[str]:
"""
Matches a line vs the list of version strings. Returns group, or None if no match is found.
"""
for regex in RELEASE_LINE_REGEXES:
for version_format, regex in RELEASE_LINE_REGEXES.items():
match = re.match(regex, line)
if match and match.group('v'):
self.VERSION_FORMAT = version_format
return match.group('v')
return None

0 comments on commit b6de5bc

Please sign in to comment.