ReviewOS

also looking at this

stacks/buddy

refactor: one update-type classifier, with the edge cases decided instead of accidental

#1439
Merged glennmichael123 wants to merge refactor/one-update-type into main
4 files +108 -116
src/buddy.tsmodified+3-48
Changes to src/buddy.ts
@@ -1213,7 +1213,7 @@ export class Buddy {
12131213 }
12141214
12151215 // Determine update type
1216 const updateType = this.getUpdateType(constraintVersion, dep.version)
1216 const updateType = getUpdateType(constraintVersion, dep.version)
12171217
12181218 // Don't add prefix here - let the file updater handle prefix preservation
12191219 // This prevents double prefixes when the constraint already has one
@@ -1361,7 +1361,7 @@ export class Buddy {
13611361
13621362 if (latestVersion !== dep.currentVersion) {
13631363 // Determine update type
1364 const updateType = this.getUpdateType(dep.currentVersion, latestVersion)
1364 const updateType = getUpdateType(dep.currentVersion, latestVersion)
13651365
13661366 this.logger.info(`Update available: ${dep.name} ${dep.currentVersion} → ${latestVersion} (${updateType})`)
13671367
@@ -1532,7 +1532,7 @@ export class Buddy {
15321532
15331533 if (latestVersion !== dep.currentVersion) {
15341534 // Determine update type
1535 const updateType = this.getUpdateType(dep.currentVersion, latestVersion)
1535 const updateType = getUpdateType(dep.currentVersion, latestVersion)
15361536
15371537 this.logger.info(`Update available: ${dep.name} ${dep.currentVersion} → ${latestVersion} (${updateType})`)
15381538
@@ -1590,51 +1590,6 @@ export class Buddy {
15901590 return deduplicatedUpdates
15911591 }
15921592
1593 /**
1594 * Determine update type based on version comparison
1595 */
1596 private getUpdateType(current: string, latest: string): 'major' | 'minor' | 'patch' {
1597 try {
1598 // Clean version strings, including v, @ prefix for version ranges
1599 let cleanCurrent = current.replace(/^[v^~>=<@]+/, '')
1600 let cleanLatest = latest.replace(/^[v^~>=<@]+/, '')
1601
1602 // For GitHub Actions, normalize incomplete versions like "4" to "4.0.0"
1603 // This is important for proper semver comparison
1604 const normalizeVersion = (version: string): string => {
1605 const parts = version.split('.')
1606 while (parts.length < 3) {
1607 parts.push('0')
1608 }
1609 return parts.join('.')
1610 }
1611
1612 cleanCurrent = normalizeVersion(cleanCurrent)
1613 cleanLatest = normalizeVersion(cleanLatest)
1614
1615 if (Bun.semver.order(cleanLatest, cleanCurrent) <= 0)
1616 return 'patch'
1617
1618 // Use manual comparison for more accurate update type determination
1619 const currentParts = cleanCurrent.split('.').map(Number)
1620 const latestParts = cleanLatest.split('.').map(Number)
1621
1622 // Major version change
1623 if (latestParts[0] > currentParts[0])
1624 return 'major'
1625
1626 // Minor version change
1627 if (latestParts[0] === currentParts[0] && latestParts[1] > currentParts[1])
1628 return 'minor'
1629
1630 // Patch version change
1631 return 'patch'
1632 }
1633 catch {
1634 return 'patch'
1635 }
1636 }
1637
16381593 /**
16391594 * Check if latest version is strictly newer than current
16401595 */