#!/usr/bin/env -S perl -wp
#
# This terrible perl script helps convert the easy-to-edit
#
#   - Changelog item.
#     !1234
#     #6789
#     TROVE-2024-001
#
# into our canonical CHANGELOG.md style
#
#   - Changelog item.
#     ([!1234], [#6789], [TROVE-2024-001])
#
# You pipe the new bit of the changelog through it manually.
# You'll probably need to edit it before and after.

use strict;

our @links;

s{[ \t]*$}{};

my $linky = qr{[!#]\d{3,}|TROVE-\d+-\d+};

if (m{^  ($linky)$}) {
  push @links, "[$1]";
  $_ = '';
} else {
  if (@links) {
    print "  (";
    print join ', ', @links;
    print ")\n";
    @links = ();
  }
}
