Browse Source

"shore bump" now releases the staged changelog

master
Niklas Rosenstein 6 months ago
parent
commit
8f1e725987
Signed by: NiklasRosenstein <rosensteinniklas@gmail.com> GPG Key ID: 06D269B33D25F6C6
2 changed files with 26 additions and 3 deletions
  1. +12
    -2
      src/shore/__main__.py
  2. +14
    -1
      src/shore/util/changelog.py

+ 12
- 2
src/shore/__main__.py View File

@@ -427,6 +427,7 @@ def bump(**args):
"""

subject = _load_subject()
changelog_manager = ChangelogManager(subject.changelog_directory, mapper)

bump_flags = ('major', 'minor', 'patch', 'post', 'snapshot')
bump_args = ['--' + k for k in bump_flags if args[k]]
@@ -534,7 +535,7 @@ def bump(**args):
content = fp.read()
offset = 0
for ref in refs:
logger.info(' %s %s -> %s', ref.package, ref.sel, ref.new_sel)
logger.info(' %s %s %s', ref.package, ref.sel, ref.new_sel)
content = content[:ref.start - offset] + ref.new_sel + content[ref.end - offset:]
offset += len(ref.sel) - len(ref.new_sel)
if not args['dry']:
@@ -545,6 +546,15 @@ def bump(**args):
logger.warning('bump requires an update in order to automatically tag')
args['update'] = True

# Rename the unreleased changelog if it exists.
if changelog_manager.unreleased.exists():
if args['dry']:
changelog = changelog_manager.version(new_version)
else:
changelog = changelog_manager.release(new_version)
logger.info('release staged changelog (%s → %s)', changelog_manager.unreleased.filename,
changelog.filename)

if args['update']:
_cache.clear()
try:
@@ -793,7 +803,7 @@ def changelog(**args):
sys.exit(1)
if not entry.component:
logger.error('no component provided.')
created = not os.path.isfile(manager.unreleased.filename)
created = not manager.unreleased.exists()
manager.unreleased.add_entry(entry)
manager.unreleased.save(create_directory=True)
message = ('Created' if created else 'Updated') + ' "{}"'.format(manager.unreleased.filename)


+ 14
- 1
src/shore/util/changelog.py View File

@@ -41,6 +41,9 @@ class Changelog:
self.mapper = mapper
self.entries = []

def exists(self) -> bool:
return os.path.isfile(self.filename)

def load(self) -> None:
with open(self.filename) as fp:
data = yaml.safe_load(fp)
@@ -67,7 +70,7 @@ class ChangelogManager:
self._cache = {}

def _get(self, name: str, version: Optional[str]) -> Changelog:
key = (name, version)
key = (name, str(version))
if key in self._cache:
return self._cache[key]
changelog = Changelog(os.path.join(self.directory, name), version, self.mapper)
@@ -82,3 +85,13 @@ class ChangelogManager:

def version(self, version: Version) -> Changelog:
return self._get(str(version) + '.yml', version)

def release(self, version: Version) -> Changelog:
"""
Renames the unreleased changelog to the file name for the specified *version*.
"""

unreleased = self.unreleased
os.rename(unreleased.filename, self.version(version).filename)
self._cache.clear()
return self.version(version)

Loading…
Cancel
Save