Skip to content

Commit d2bbc29

Browse files
committed
release-commenter: Fix links for dev releases
1 parent 60634fd commit d2bbc29

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

.agents/release-workflow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The workflow `.github/workflows/comment-released-prs-and-issues.yml` uses the lo
3232
- Automatic base-tag selection is semver-aware:
3333
- Stable release tags compare to the previous stable semver tag.
3434
- Prerelease tags with a SHA suffix (for example `v3.4.1-dev.<sha>`) resolve base from npm-published versions with the same prerelease prefix and pick the nearest ancestor commit.
35+
- SHA-suffixed prerelease comments link to the npm published version page instead of GitHub release tags.
3536
- Other prerelease tags compare to the previous semver tag (including prereleases).
3637
- If no valid base tag is found, the action fails.
3738
- The action fails before posting if any target issue/PR already has a previous stable release-comment.

.github/actions/release-commenter/index.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ async function main() {
210210

211211
const currentRelease = await getCurrentRelease(token, owner, repo, currentTag, payload?.release)
212212
const releaseLabel = currentRelease.name || currentRelease.tag
213-
const releaseUrl = currentRelease.htmlUrl
213+
const npmPackageName = npmPackageNameInput || repo
214+
const releaseUrl = shaPrereleaseContext
215+
? npmVersionUrl(npmPackageName, currentTag)
216+
: currentRelease.htmlUrl
217+
if (shaPrereleaseContext) {
218+
log(`Using npm release URL for prerelease tag: ${releaseUrl}`)
219+
}
214220

215221
const commentTemplate = getInput('comment-template', defaultCommentTemplate)
216222
const labelTemplate = getInput('label-template')
@@ -235,7 +241,7 @@ async function main() {
235241
currentVersion,
236242
shaPrereleaseContext,
237243
baseTagInput,
238-
npmPackageNameInput,
244+
npmPackageName,
239245
)
240246

241247
log(`Base ref: ${baseRef}`)
@@ -314,7 +320,7 @@ async function main() {
314320
* @param {ParsedTag} currentVersion
315321
* @param {ShaPrereleaseContext | null} shaPrereleaseContext
316322
* @param {string} baseTagInput
317-
* @param {string} npmPackageNameInput
323+
* @param {string} npmPackageName
318324
* @returns {Promise<CompareRefs>}
319325
*/
320326
async function resolveCompareRefs(
@@ -325,7 +331,7 @@ async function resolveCompareRefs(
325331
currentVersion,
326332
shaPrereleaseContext,
327333
baseTagInput,
328-
npmPackageNameInput,
334+
npmPackageName,
329335
) {
330336
let baseRef = ''
331337
let headRef = currentTag
@@ -337,7 +343,6 @@ async function resolveCompareRefs(
337343
}
338344
log(`Using manual base ref input: ${baseRef}`)
339345
} else if (shaPrereleaseContext) {
340-
const npmPackageName = npmPackageNameInput || repo
341346
const shaResolution = await resolveShaPrereleaseBaseRef(
342347
token,
343348
owner,
@@ -945,6 +950,35 @@ function npmRegistryPath(packageName) {
945950
return `${registryRoot}/${encodeURIComponent(packageName)}`
946951
}
947952

953+
/**
954+
* Converts a git-like tag string into an npm version string.
955+
*
956+
* @param {string} tag
957+
* @returns {string}
958+
*/
959+
function npmVersionFromTag(tag) {
960+
let normalized = tag
961+
if (normalized.startsWith('refs/tags/')) {
962+
normalized = normalized.slice('refs/tags/'.length)
963+
}
964+
if (normalized.startsWith('v')) {
965+
normalized = normalized.slice(1)
966+
}
967+
return normalized
968+
}
969+
970+
/**
971+
* Builds the npm package version URL for a given tag.
972+
*
973+
* @param {string} packageName
974+
* @param {string} tag
975+
* @returns {string}
976+
*/
977+
function npmVersionUrl(packageName, tag) {
978+
const version = npmVersionFromTag(tag)
979+
return `https://www.npmjs.com/package/${packageName}/v/${encodeURIComponent(version)}`
980+
}
981+
948982
/**
949983
* Executes an authenticated GitHub REST request and parses JSON responses.
950984
*

0 commit comments

Comments
 (0)