Refactor - use renderVersionBadge - part 4 [githubrelease githubtag] (#10656)

* feat: add forcePrerelease option to renderVersionBadge function

Sometimes API would indicate if a version is pre-release while the version number does not have to be semantically a prerelease like in github-release service.
We don't use a isPrerelease that can also force a non-preleases as we trust here developer semantic over API tagging.

* refactor: GithubRelease to use renderVersionBadge

* refactor: GithubTag use renderVersionBadge

* refactor: change forcePrerelease to isPrerelease
This commit is contained in:
jNullj
2024-11-11 21:16:14 +02:00
committed by GitHub
parent 4d203e1937
commit 04638ab0ee
4 changed files with 7 additions and 35 deletions

View File

@@ -237,6 +237,7 @@ function rangeStart(v) {
* @param {string} [options.prefix] - The prefix to display on the message, such as ">=", "v", overrides the default behavior of using addv
* @param {string} [options.postfix] - The postfix to display on the message, such as "tested"
* @param {Function} [options.versionFormatter=versionColor] - The function to use to format the color of the badge based on the version number
* @param {boolean} [options.isPrerelease] - Whether the version is explicitly marked as a prerelease by upstream API
* @returns {object} A badge object that has three properties: label, message, and color
* @example
* renderVersionBadge({version: '1.2.3', tag: 'alpha', defaultLabel: 'npm'}) // returns {label: 'npm@alpha', message: 'v1.2.3', color: 'orange'} because
@@ -250,13 +251,14 @@ function renderVersionBadge({
prefix,
postfix,
versionFormatter = versionColor,
isPrerelease,
}) {
return {
label: tag ? `${defaultLabel}@${tag}` : defaultLabel,
message:
(prefix ? `${prefix}${version}` : addv(version)) +
(postfix ? ` ${postfix}` : ''),
color: versionFormatter(version),
color: versionFormatter(isPrerelease ? 'pre' : version),
}
}