Skip to content

Commit

Permalink
Including tag-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Stewart committed Mar 3, 2022
1 parent 352242a commit 4573996
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -159,12 +159,16 @@ module.exports = (app, { getRouter }) => {
}

const targetCommitish = commitish || config['commitish'] || ref
const filterByCommitish = config['filter-by-commitish']
const {
'filter-by-commitish': filterByCommitish,
'tag-prefix': tagPrefix,
} = config

const { draftRelease, lastRelease } = await findReleases({
context,
targetCommitish,
filterByCommitish,
tagPrefix,
})

const { commits, pullRequests: mergedPullRequests } =
Expand Down
1 change: 1 addition & 0 deletions lib/default-config.js
Expand Up @@ -3,6 +3,7 @@ const { SORT_BY, SORT_DIRECTIONS } = require('./sort-pull-requests')
const DEFAULT_CONFIG = Object.freeze({
'name-template': '',
'tag-template': '',
'tag-prefix': '',
'change-template': `* $TITLE (#$NUMBER) @$AUTHOR`,
'change-title-escapes': '',
'no-changes-template': `* No changes`,
Expand Down
9 changes: 7 additions & 2 deletions lib/releases.js
Expand Up @@ -21,6 +21,7 @@ const findReleases = async ({
context,
targetCommitish,
filterByCommitish,
tagPrefix,
}) => {
let releases = await context.octokit.paginate(
context.octokit.repos.listReleases.endpoint.merge(
Expand All @@ -32,9 +33,12 @@ const findReleases = async ({

log({ context, message: `Found ${releases.length} releases` })

const filteredReleases = filterByCommitish
const commitishFilteredReleases = filterByCommitish
? releases.filter((r) => targetCommitish.match(`/${r.target_commitish}$`))
: releases
const filteredReleases = tagPrefix
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
: commitishFilteredReleases
const sortedPublishedReleases = sortReleases(
filteredReleases.filter((r) => !r.draft)
)
Expand Down Expand Up @@ -301,7 +305,8 @@ const generateReleaseInfo = ({
// Use the first override parameter to identify
// a version, from the most accurate to the least
version || tag || name,
resolveVersionKeyIncrement(mergedPullRequests, config)
resolveVersionKeyIncrement(mergedPullRequests, config),
config['tag-prefix']
)

if (versionInfo) {
Expand Down
18 changes: 12 additions & 6 deletions lib/versions.js
Expand Up @@ -136,24 +136,30 @@ const toSemver = (version) => {
return semver.coerce(version)
}

const coerceVersion = (input) => {
const coerceVersion = (input, tagPrefix) => {
if (!input) {
return
}

const stripTag = (input) =>
tagPrefix && input.startsWith(tagPrefix)
? input.slice(tagPrefix.length)
: input

return typeof input === 'object'
? toSemver(input.tag_name) || toSemver(input.name)
: toSemver(input)
? toSemver(stripTag(input.tag_name)) || toSemver(stripTag(input.name))
: toSemver(stripTag(input))
}

const getVersionInfo = (
release,
template,
inputVersion,
versionKeyIncrement
versionKeyIncrement,
tagPrefix
) => {
const version = coerceVersion(release)
inputVersion = coerceVersion(inputVersion)
const version = coerceVersion(release, tagPrefix)
inputVersion = coerceVersion(inputVersion, tagPrefix)

if (!version && !inputVersion) {
return defaultVersionInfo
Expand Down

0 comments on commit 4573996

Please sign in to comment.