INNER CODE UNIT · JavaScript
previous_tags
scality/Zenko · .github/scripts/get-previous-tag.js:20
const previous_tags = allReleases.filter(r =>
r.tag_name.startsWith(stem) &&
!/[-.]/.test(r.tag_name.substring(stem.length))
);
if (previous_tags.length > 0) {
// Use a custom sort function, to ensure 'natural' sort of numeric parts
const compare = new Intl.Collator(undefined, { numeric: true }).compare;
return previous_tags.sort(
(a, b) => compare(a.tag_name, b.tag_name)
).reverse()[0].tag_name;
}
// No direct sibling: fall back to the "parent" — the prefix itself as
// an exact release. e.g. previous of X.Y.Z.1 is X.Y.Z (the base), and
// previous of X.Y.Z-1-rc.1 (when no earlier rc exists) is X.Y.Z-1.
// Without this, we'd peel further up and pick a same-level sibling of
// the parent (like X.Y.(Z+1)), which is on a different branch.
if (allReleases.some(r => r.tag_name === prefix)) {