also looking at this
refactor: one update-type classifier, with the edge cases decided instead of accidental
#1439
4 files
+108
-116
| @@ -1213,7 +1213,7 @@ export class Buddy { | ||
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | // Determine update type |
| 1216 | const updateType = this.getUpdateType(constraintVersion, dep.version) | |
| 1216 | const updateType = getUpdateType(constraintVersion, dep.version) | |
| 1217 | 1217 | |
| 1218 | 1218 | // Don't add prefix here - let the file updater handle prefix preservation |
| 1219 | 1219 | // This prevents double prefixes when the constraint already has one |
| @@ -1361,7 +1361,7 @@ export class Buddy { | ||
| 1361 | 1361 | |
| 1362 | 1362 | if (latestVersion !== dep.currentVersion) { |
| 1363 | 1363 | // Determine update type |
| 1364 | const updateType = this.getUpdateType(dep.currentVersion, latestVersion) | |
| 1364 | const updateType = getUpdateType(dep.currentVersion, latestVersion) | |
| 1365 | 1365 | |
| 1366 | 1366 | this.logger.info(`Update available: ${dep.name} ${dep.currentVersion} → ${latestVersion} (${updateType})`) |
| 1367 | 1367 | |
| @@ -1532,7 +1532,7 @@ export class Buddy { | ||
| 1532 | 1532 | |
| 1533 | 1533 | if (latestVersion !== dep.currentVersion) { |
| 1534 | 1534 | // Determine update type |
| 1535 | const updateType = this.getUpdateType(dep.currentVersion, latestVersion) | |
| 1535 | const updateType = getUpdateType(dep.currentVersion, latestVersion) | |
| 1536 | 1536 | |
| 1537 | 1537 | this.logger.info(`Update available: ${dep.name} ${dep.currentVersion} → ${latestVersion} (${updateType})`) |
| 1538 | 1538 | |
| @@ -1590,51 +1590,6 @@ export class Buddy { | ||
| 1590 | 1590 | return deduplicatedUpdates |
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 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 | ||
| 1638 | 1593 | /** |
| 1639 | 1594 | * Check if latest version is strictly newer than current |
| 1640 | 1595 | */ |