Skip to content

Commit 22f5b34

Browse files
committed
chore: wip
1 parent dad0cc9 commit 22f5b34

File tree

4 files changed

+113
-7
lines changed

4 files changed

+113
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ storage
1616
qjs*
1717
bin/buddy
1818
bin/buddy-*
19-
19+
vendor
20+
composer.lock

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pr/pr-generator.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ export class PullRequestGenerator {
168168
body += `\n`
169169
}
170170

171-
// Composer packages table (simplified, without badges)
171+
// Composer dependencies table (simplified, without badges)
172172
if (composerUpdates.length > 0) {
173173
body += `### PHP/Composer Dependencies\n\n`
174174
body += `| Package | Change | File | Status |\n`
175175
body += `|---|---|---|---|\n`
176176

177177
for (const update of composerUpdates) {
178-
// Generate package link to Packagist
178+
// Generate package link
179179
const packageUrl = `https://packagist.org/packages/${encodeURIComponent(update.name)}`
180180
const packageCell = `[${update.name}](${packageUrl})`
181181

@@ -225,6 +225,32 @@ export class PullRequestGenerator {
225225
body += `\n`
226226
}
227227

228+
// Composer dependencies table (simplified, without badges)
229+
if (composerUpdates.length > 0) {
230+
body += `### PHP/Composer Dependencies\n\n`
231+
body += `| Package | Change | File | Status |\n`
232+
body += `|---|---|---|---|\n`
233+
234+
for (const update of composerUpdates) {
235+
// Generate package link
236+
const packageUrl = `https://packagist.org/packages/${encodeURIComponent(update.name)}`
237+
const packageCell = `[${update.name}](${packageUrl})`
238+
239+
// Simple version change display
240+
const change = `\`${update.currentVersion}\` -> \`${update.newVersion}\``
241+
242+
// File reference
243+
const fileName = update.file.split('/').pop() || update.file
244+
245+
// Status (simple)
246+
const status = '✅ Available'
247+
248+
body += `| ${packageCell} | ${change} | ${fileName} | ${status} |\n`
249+
}
250+
251+
body += `\n`
252+
}
253+
228254
// GitHub Actions table (simplified, without badges, deduplicated)
229255
if (uniqueGithubActionsUpdates.length > 0) {
230256
body += `### GitHub Actions\n\n`

src/registry/registry-client.ts

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ export class RegistryClient {
617617
const metadata = await this.getComposerPackageMetadata(pkg.name)
618618

619619
// Find multiple update paths: patch, minor, and major
620-
const currentVersion = pkg.version
620+
// Extract the base version from the constraint (e.g., "^3.0" -> "3.0.0")
621+
const constraintBaseVersion = this.extractConstraintBaseVersion(constraint)
622+
const currentVersion = constraintBaseVersion || pkg.version
621623
const latestVersion = pkg.latest
622624

623625
// Get all available versions by querying composer show
@@ -633,8 +635,8 @@ export class RegistryClient {
633635
availableVersions = [latestVersion]
634636
}
635637

636-
// Find the best update for each type (patch, minor, major)
637-
const updateCandidates = await this.findBestUpdates(currentVersion, availableVersions, constraint)
638+
// Find the best constraint updates (e.g., ^3.0 -> ^3.9.0)
639+
const updateCandidates = await this.findBestConstraintUpdates(constraint, availableVersions, currentVersion)
638640

639641
for (const candidate of updateCandidates) {
640642
const updateType = getUpdateType(currentVersion, candidate.version)
@@ -917,4 +919,81 @@ export class RegistryClient {
917919

918920
return undefined
919921
}
922+
923+
/**
924+
* Extract the base version from a version constraint (e.g., "^3.0" -> "3.0.0")
925+
*/
926+
private extractConstraintBaseVersion(constraint: string): string | null {
927+
const match = constraint.match(/^[\^~>=<]*([\d.]+)/)
928+
if (match) {
929+
return match[1]
930+
}
931+
return null
932+
}
933+
934+
/**
935+
* Find the best constraint updates (e.g., ^3.0 -> ^3.9.0)
936+
*/
937+
private async findBestConstraintUpdates(constraint: string, availableVersions: string[], currentVersion: string): Promise<{ version: string, type: 'patch' | 'minor' | 'major' }[]> {
938+
const { getUpdateType } = await import('../utils/helpers')
939+
const candidates: { version: string, type: 'patch' | 'minor' | 'major' }[] = []
940+
941+
// Parse current version
942+
const currentParts = this.parseVersion(currentVersion)
943+
if (!currentParts) {
944+
return []
945+
}
946+
947+
let bestPatch: string | null = null
948+
let bestMinor: string | null = null
949+
let bestMajor: string | null = null
950+
951+
for (const version of availableVersions) {
952+
// Skip dev/alpha/beta versions for now (could be enhanced later)
953+
if (version.includes('dev') || version.includes('alpha') || version.includes('beta') || version.includes('RC')) {
954+
continue
955+
}
956+
957+
const versionParts = this.parseVersion(version)
958+
if (!versionParts) {
959+
continue
960+
}
961+
962+
// Skip versions that are not newer
963+
const comparison = this.compareVersions(version, currentVersion)
964+
if (comparison <= 0) {
965+
continue
966+
}
967+
968+
const updateType = getUpdateType(currentVersion, version)
969+
970+
// Find best update for each type
971+
if (updateType === 'patch' && versionParts.major === currentParts.major && versionParts.minor === currentParts.minor) {
972+
if (!bestPatch || this.compareVersions(version, bestPatch) > 0) {
973+
bestPatch = version
974+
}
975+
} else if (updateType === 'minor' && versionParts.major === currentParts.major) {
976+
if (!bestMinor || this.compareVersions(version, bestMinor) > 0) {
977+
bestMinor = version
978+
}
979+
} else if (updateType === 'major') {
980+
if (!bestMajor || this.compareVersions(version, bestMajor) > 0) {
981+
bestMajor = version
982+
}
983+
}
984+
}
985+
986+
// Add the best candidates
987+
if (bestPatch) {
988+
candidates.push({ version: bestPatch, type: 'patch' })
989+
}
990+
if (bestMinor) {
991+
candidates.push({ version: bestMinor, type: 'minor' })
992+
}
993+
if (bestMajor) {
994+
candidates.push({ version: bestMajor, type: 'major' })
995+
}
996+
997+
return candidates
998+
}
920999
}

0 commit comments

Comments
 (0)