Skip to content

Commit bdc0725

Browse files
committed
feat: improve version change display to preserve constraint formats
- Add formatVersionChange method to preserve constraint prefixes (^, ~, >=) - Fix issue where ^6.0 → 6.0.0 was displayed instead of ^6.0 → ^6.0.0 - Apply consistent version formatting across all sections: - System dependencies table - GitHub Actions table - Release notes sections for all package types - Ensures PR bodies show proper constraint format like ^3.0 → ^3.0.0
1 parent f664b99 commit bdc0725

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

src/pr/pr-generator.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ export class PullRequestGenerator {
452452
: `https://pkgx.com/pkg/${encodeURIComponent(update.name)}`
453453
const packageCell = `[${displayName}](${packageUrl})`
454454

455-
// Enhanced version change display with update type
455+
// Enhanced version change display with update type and proper constraint format
456456
const updateType = this.getUpdateType(update.currentVersion, update.newVersion)
457457
const typeEmoji = updateType === 'major' ? '🔴' : updateType === 'minor' ? '🟡' : '🟢'
458-
const change = `\`${update.currentVersion}\` → \`${update.newVersion}\``
458+
const change = this.formatVersionChange(update.currentVersion, update.newVersion)
459459

460460
// File reference with link to actual file
461461
const fileName = update.file.split('/').pop() || update.file
@@ -491,10 +491,10 @@ export class PullRequestGenerator {
491491
const actionUrl = `https://github.com/${update.name}`
492492
const actionCell = `[${update.name}](${actionUrl})`
493493

494-
// Enhanced version change display with update type
494+
// Enhanced version change display with update type and proper constraint format
495495
const updateType = this.getUpdateType(update.currentVersion, update.newVersion)
496496
const typeEmoji = updateType === 'major' ? '🔴' : updateType === 'minor' ? '🟡' : '🟢'
497-
const change = `\`${update.currentVersion}\` → \`${update.newVersion}\``
497+
const change = this.formatVersionChange(update.currentVersion, update.newVersion)
498498

499499
// Enhanced file reference with proper GitHub links
500500
const fileLinks = update.file.includes(', ')
@@ -619,7 +619,11 @@ export class PullRequestGenerator {
619619

620620
body += `<details>\n`
621621
body += `<summary>${displayName}</summary>\n\n`
622-
body += `**${update.currentVersion} -> ${update.newVersion}**\n\n`
622+
623+
// Use consistent version formatting with constraints
624+
const versionChange = this.formatVersionChange(update.currentVersion, update.newVersion)
625+
.replace(/`/g, '') // Remove backticks for clean display in details
626+
body += `**${versionChange}**\n\n`
623627

624628
// Add file reference with link to the dependency file
625629
if (update.file) {
@@ -651,7 +655,12 @@ export class PullRequestGenerator {
651655
for (const update of uniqueComposerUpdates) {
652656
body += `<details>\n`
653657
body += `<summary>${update.name}</summary>\n\n`
654-
body += `**${update.currentVersion} -> ${update.newVersion}**\n\n`
658+
659+
// Use consistent version formatting with constraints
660+
const versionChange = this.formatVersionChange(update.currentVersion, update.newVersion)
661+
.replace(/`/g, '') // Remove backticks for clean display in details
662+
body += `**${versionChange}**\n\n`
663+
655664
body += `Visit [${update.name}](https://packagist.org/packages/${encodeURIComponent(update.name)}) on Packagist for more information.\n\n`
656665
body += `</details>\n\n`
657666
}
@@ -660,7 +669,12 @@ export class PullRequestGenerator {
660669
for (const update of uniqueGithubActionsUpdates) {
661670
body += `<details>\n`
662671
body += `<summary>${update.name}</summary>\n\n`
663-
body += `**${update.currentVersion} -> ${update.newVersion}**\n\n`
672+
673+
// Use consistent version formatting with constraints
674+
const versionChange = this.formatVersionChange(update.currentVersion, update.newVersion)
675+
.replace(/`/g, '') // Remove backticks for clean display in details
676+
body += `**${versionChange}**\n\n`
677+
664678
body += `Visit [${update.name}](https://github.com/${update.name}/releases) for release notes.\n\n`
665679
body += `</details>\n\n`
666680
}
@@ -982,6 +996,25 @@ export class PullRequestGenerator {
982996
return 'patch'
983997
}
984998

999+
/**
1000+
* Format version change preserving constraint prefixes
1001+
*/
1002+
private formatVersionChange(currentVersion: string, newVersion: string): string {
1003+
// Check if current version has constraint prefix (^, ~, >=, etc.)
1004+
const constraintMatch = currentVersion.match(/^([^0-9]+)/)
1005+
const constraintPrefix = constraintMatch ? constraintMatch[1] : ''
1006+
1007+
// If there's a constraint prefix, preserve it in the new version display
1008+
if (constraintPrefix) {
1009+
const cleanCurrent = currentVersion.replace(/^[^0-9]+/, '')
1010+
const cleanNew = newVersion.replace(/^[^0-9]+/, '')
1011+
return `\`${constraintPrefix}${cleanCurrent}\` → \`${constraintPrefix}${cleanNew}\``
1012+
}
1013+
1014+
// No constraint prefix, display as-is
1015+
return `\`${currentVersion}\` → \`${newVersion}\``
1016+
}
1017+
9851018
/**
9861019
* Generate a description of the version change
9871020
*/

0 commit comments

Comments
 (0)