Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .github/changeset-preview/preview-changeset-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ function main() {
const explicit = readChangesetEntries()

if (explicit.size === 0) {
const msg = 'No changeset entries found β€” nothing to preview.\n'
const msg =
'No changeset entries found. Merging this PR will not cause a version bump for any packages.\n'
process.stdout.write(msg)
if (values.output) {
writeFileSync(values.output, msg)
} else {
process.stdout.write(msg)
process.stdout.write(`Written to ${values.output}\n`)
}
return
}
Expand Down Expand Up @@ -138,12 +139,11 @@ function main() {

// 7. Build markdown
const lines = []
lines.push('<!-- changeset-version-preview -->')
lines.push('## Changeset Version Preview')
lines.push('')

if (bumps.length === 0) {
lines.push('No version changes detected.')
lines.push(
'No version changes detected. Merging this PR will not cause a version bump for any packages.',
)
} else {
const explicitBumps = bumps.filter((b) => b.source !== 'dependency')
const dependencyBumps = bumps.filter((b) => b.source === 'dependency')
Expand Down Expand Up @@ -184,13 +184,12 @@ function main() {
}

lines.push('')

const md = lines.join('\n')

process.stdout.write(md)
if (values.output) {
writeFileSync(values.output, md)
process.stdout.write(`Written to ${values.output}\n`)
} else {
process.stdout.write(md)
}
}

Expand Down
8 changes: 4 additions & 4 deletions .github/changeset-preview/upsert-pr-comment.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { promises as fsp } from 'node:fs'
import path from 'node:path'
import { parseArgs as parseNodeArgs } from 'node:util'

const DEFAULT_MARKER = '<!-- bundle-size-benchmark -->'
const DEFAULT_MARKER = '<!-- changeset-version-preview -->'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟑 Minor

Handle legacy marker during migration to avoid duplicate bot comments.

After switching markers, existing comments using the old marker are no longer matched, so the first run can create a second preview comment instead of updating the existing one.

Suggested patch
 const DEFAULT_MARKER = '<!-- changeset-version-preview -->'
+const LEGACY_MARKERS = ['<!-- bundle-size-benchmark -->']
@@
   const existing = comments.find(
     (comment) =>
-      typeof comment?.body === 'string' && comment.body.includes(args.marker),
+      typeof comment?.body === 'string' &&
+      [args.marker, ...LEGACY_MARKERS].some((marker) =>
+        comment.body.includes(marker),
+      ),
   )

Also applies to: 123-126

πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/changeset-preview/upsert-pr-comment.mjs at line 7, The change
introduces a new DEFAULT_MARKER but doesn't handle existing legacy comments,
causing duplicate bot posts; update the upsert logic to search for and treat
legacy and new markers as equivalent by defining an array of markers (e.g.,
const MARKERS = [DEFAULT_MARKER, '<!-- old-marker-string -->']) and use that
when finding/updating comments in the functions that create or replace comments
(the code paths that reference DEFAULT_MARKER for matching). Ensure when
updating you prefer the existing legacy comment (replace its body and then
update to the new marker) rather than creating a new comment so the bot will not
post duplicates.


function parseArgs(argv) {
const { values } = parseNodeArgs({
Expand Down Expand Up @@ -109,9 +109,9 @@ async function main() {
const args = parseArgs(process.argv.slice(2))
const bodyPath = path.resolve(args.bodyFile)
const rawBody = await fsp.readFile(bodyPath, 'utf8')
const body = rawBody.includes(args.marker)
? rawBody
: `${args.marker}\n${rawBody}`
const body = `${args.marker}\n## πŸš€ Changeset Version Preview\n\n${rawBody}`

process.stdout.write(body)

const comments = await listIssueComments({
apiUrl: args.apiUrl,
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/changeset-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Changeset Preview

on:
pull_request:
paths:
- '.changeset/**'

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
Expand Down
Loading