From cd4ee5f854b5e1dc27493cea6b17b576ac741f28 Mon Sep 17 00:00:00 2001 From: Ross McFarland Date: Wed, 25 Jun 2025 15:09:13 -0700 Subject: [PATCH] changelog script improvements, manual pr, sort order, formatting --- .../ff12d7ab1c614a15b3ce8c6bba3407fb.md | 5 +++ CHANGELOG.md | 5 --- script/changelog | 38 +++++++++++++++---- 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 .changelog/ff12d7ab1c614a15b3ce8c6bba3407fb.md diff --git a/.changelog/ff12d7ab1c614a15b3ce8c6bba3407fb.md b/.changelog/ff12d7ab1c614a15b3ce8c6bba3407fb.md new file mode 100644 index 0000000..2a6bc1d --- /dev/null +++ b/.changelog/ff12d7ab1c614a15b3ce8c6bba3407fb.md @@ -0,0 +1,5 @@ +--- +type: minor +pr: 1251 +--- +Correct type-o in name of AcmeManagingProcessor, backwards compatible alias in place \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0df45b4..d69254e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,3 @@ -## v1.11.? - 2025-??-?? - ??? - -* Correct type-o in name of AcmeManagingProcessor, backwards compatible alias - in place - ## v1.11.0 - 2025-02-03 - Cleanup & deprecations with meta planning * Deprecation warning for Source.populate w/o the lenient param, to be removed diff --git a/script/changelog b/script/changelog index 4623dc8..dc622f4 100755 --- a/script/changelog +++ b/script/changelog @@ -11,7 +11,7 @@ from subprocess import PIPE, run from sys import argv, exit, path, stderr from uuid import uuid4 -from yaml import safe_load_all +from yaml import safe_load def create(argv): @@ -39,6 +39,11 @@ def create(argv): See https://semver.org/ for more info''', ) + parser.add_argument( + '-p', + '--pr', + help='Manually override the PR number for the change, maintainer use only.', + ) parser.add_argument( '-a', '--add', @@ -62,6 +67,9 @@ and links.''', with open(filepath, 'w') as fh: fh.write('---\ntype: ') fh.write(args.type) + if args.pr: + fh.write('\npr: ') + fh.write(args.pr) fh.write('\n---\n') fh.write(' '.join(args.md)) @@ -106,7 +114,7 @@ class _ChangeMeta: _pr_cache = None @classmethod - def get(cls, filepath): + def get(cls, filepath, data): if cls._pr_cache is None: result = run( [ @@ -139,7 +147,13 @@ class _ChangeMeta: try: return cls._pr_cache[filepath] except KeyError: - return None, datetime(year=1970, month=1, day=1) + # couldn't find a PR with the changelog file in it + try: + # if a PR number was specified in the changelog entry use it + return data['pr'], datetime(year=1970, month=1, day=1) + except KeyError: + # otherwise just give up + return None, datetime(year=1970, month=1, day=1) def _get_changelogs(): @@ -150,8 +164,12 @@ def _get_changelogs(): continue filepath = join(dirname, filename) with open(filepath) as fh: - data, md = safe_load_all(fh) - pr, time = _ChangeMeta.get(filepath) + pieces = fh.read().split('---\n') + data = safe_load(pieces[1]) + md = pieces[2] + if md[-1] == '\n': + md = md[:-1] + pr, time = _ChangeMeta.get(filepath, data) if not pr: continue ret.append( @@ -165,7 +183,7 @@ def _get_changelogs(): ) ordering = {'major': 0, 'minor': 1, 'patch': 2, 'none': 3, '': 3} - ret.sort(key=lambda c: (ordering[c['type']], c['time'])) + ret.sort(key=lambda c: (ordering[c['type']], c['time']), reverse=True) return ret @@ -204,6 +222,9 @@ def bump(argv): action='store_true', help='Write changelog update and bump version number', ) + parser.add_argument( + 'title', nargs='+', help='A short title/quip for the release title' + ) args = parser.parse_args(argv) @@ -224,7 +245,7 @@ def bump(argv): buf.write(' - ') buf.write(datetime.now().strftime('%Y-%m-%d')) buf.write(' - ') - buf.write(' '.join(argv[1:])) + buf.write(' '.join(args.title)) buf.write('\n') current_type = None @@ -234,6 +255,9 @@ def bump(argv): continue _type = changelog['type'] + if _type == 'none': + # these aren't included in the listing + continue if _type != current_type: buf.write('\n') buf.write(_type.capitalize())