Skip to content

Commit f2e6988

Browse files
committed
chore: wip
1 parent e8fa170 commit f2e6988

9 files changed

+101
-99
lines changed

src/buddy.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ export class Buddy {
191191
// Create branch
192192
await gitProvider.createBranch(branchName, this.config.repository.baseBranch || 'main')
193193

194-
195-
196194
// Update package.json with new versions
197195
const packageJsonUpdates = await this.generateAllFileUpdates(group.updates)
198196

@@ -446,8 +444,8 @@ export class Buddy {
446444
// Handle dependency file updates (deps.yaml, dependencies.yaml, etc.)
447445
// Only process if we have dependency file updates to avoid unnecessary processing
448446
const dependencyFileUpdates = updates.filter(update =>
449-
(update.file.includes('.yaml') || update.file.includes('.yml')) &&
450-
!update.file.includes('.github/workflows/')
447+
(update.file.includes('.yaml') || update.file.includes('.yml'))
448+
&& !update.file.includes('.github/workflows/'),
451449
)
452450
if (dependencyFileUpdates.length > 0) {
453451
try {
@@ -464,7 +462,7 @@ export class Buddy {
464462
// Handle Composer updates
465463
// Only process if we have composer updates to avoid unnecessary processing
466464
const composerUpdates = updates.filter(update =>
467-
update.file.endsWith('composer.json') || update.file.endsWith('composer.lock')
465+
update.file.endsWith('composer.json') || update.file.endsWith('composer.lock'),
468466
)
469467
if (composerUpdates.length > 0) {
470468
try {
@@ -481,7 +479,7 @@ export class Buddy {
481479
// Handle GitHub Actions updates
482480
// Only process if we have GitHub Actions updates to avoid unnecessary processing
483481
const githubActionsUpdates = updates.filter(update =>
484-
update.file.includes('.github/workflows/')
482+
update.file.includes('.github/workflows/'),
485483
)
486484
if (githubActionsUpdates.length > 0) {
487485
try {
@@ -624,7 +622,7 @@ export class Buddy {
624622
/**
625623
* Check if two PR titles are similar (for dependency updates)
626624
*/
627-
private isSimilarPRTitle(existingTitle: string, newTitle: string): boolean {
625+
private isSimilarPRTitle(existingTitle: string, newTitle: string): boolean {
628626
// Exact match is always similar
629627
if (existingTitle.toLowerCase() === newTitle.toLowerCase()) {
630628
return true
@@ -635,8 +633,8 @@ export class Buddy {
635633
const newLower = newTitle.toLowerCase()
636634

637635
// If one is for "all non-major" and other is for specific dependency, they're different
638-
if ((existingLower.includes('all non-major') && newLower.includes('dependency ')) ||
639-
(newLower.includes('all non-major') && existingLower.includes('dependency '))) {
636+
if ((existingLower.includes('all non-major') && newLower.includes('dependency '))
637+
|| (newLower.includes('all non-major') && existingLower.includes('dependency '))) {
640638
return false
641639
}
642640

src/git/github-provider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export class GitHubProvider implements GitProvider {
5858
if (nonWorkflowFiles.length > 0) {
5959
console.log(`📝 Attempting to commit ${nonWorkflowFiles.length} non-workflow files only...`)
6060
files = nonWorkflowFiles
61-
} else {
61+
}
62+
else {
6263
throw new Error('All files are workflow files but GitHub App lacks workflows permission. Please add "workflows: write" permission to the GitHub App.')
6364
}
6465
}
@@ -158,7 +159,8 @@ export class GitHubProvider implements GitProvider {
158159
if (nonWorkflowFiles.length > 0) {
159160
console.log(`📝 Attempting to commit ${nonWorkflowFiles.length} non-workflow files only...`)
160161
files = nonWorkflowFiles
161-
} else {
162+
}
163+
else {
162164
throw new Error('All files are workflow files but GitHub App lacks workflows permission. Please add "workflows: write" permission to the GitHub App.')
163165
}
164166
}

src/registry/registry-client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,14 @@ export class RegistryClient {
542542
* Extract major version number from a version string
543543
*/
544544
private getMajorVersion(version: string): string {
545-
return version.replace(/^[v\^~>=<]+/, '').split('.')[0] || '0'
545+
return version.replace(/^[v^~>=<]+/, '').split('.')[0] || '0'
546546
}
547547

548548
/**
549549
* Extract minor version number from a version string
550550
*/
551551
private getMinorVersion(version: string): string {
552-
const parts = version.replace(/^[v\^~>=<]+/, '').split('.')
552+
const parts = version.replace(/^[v^~>=<]+/, '').split('.')
553553
return parts[1] || '0'
554554
}
555555

@@ -588,21 +588,21 @@ export class RegistryClient {
588588
this.logger.warn('Failed to read composer.json for dependency type detection:', error)
589589
}
590590

591-
// Parse composer outdated output and filter based on version constraints
591+
// Parse composer outdated output and filter based on version constraints
592592
if (composerData.installed) {
593593
for (const pkg of composerData.installed) {
594594
if (pkg.name && pkg.version && pkg.latest) {
595595
// Get the version constraint from composer.json
596596
const requireConstraint = composerJsonData.require?.[pkg.name]
597597
const requireDevConstraint = composerJsonData['require-dev']?.[pkg.name]
598598
const constraint = requireConstraint || requireDevConstraint
599-
599+
600600
if (!constraint) {
601601
continue // Skip packages not found in composer.json
602602
}
603603

604-
// Include all available updates - let grouping and strategy handle filtering
605-
let newVersion = pkg.latest
604+
// Include all available updates - let grouping and strategy handle filtering
605+
const newVersion = pkg.latest
606606

607607
const updateType = getUpdateType(pkg.version, newVersion)
608608

src/utils/composer-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export async function generateComposerUpdates(updates: Array<{ name: string, new
207207
const fs = await import('node:fs')
208208
let composerContent = fs.readFileSync(filePath, 'utf-8')
209209

210-
// Parse to understand structure
210+
// Parse to understand structure
211211
const composerData: ComposerPackage = JSON.parse(composerContent)
212212

213213
// Apply updates using string replacement to preserve formatting

src/utils/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export function groupUpdates(updates: PackageUpdate[]): UpdateGroup[] {
220220
})
221221
}
222222

223-
if (minorUpdates.length > 0 || patchUpdates.length > 0) {
223+
if (minorUpdates.length > 0 || patchUpdates.length > 0) {
224224
const nonMajorUpdates = [...minorUpdates, ...patchUpdates]
225225
groups.push({
226226
name: 'Non-Major Updates',

test/composer-individual-pr-simulation.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { beforeEach, describe, expect, it, spyOn } from 'bun:test'
2-
import { Buddy } from '../src/buddy'
32
import fs from 'node:fs'
3+
import { Buddy } from '../src/buddy'
44

55
describe('Composer Individual PR Simulation', () => {
66
let buddy: Buddy
77

88
const mockComposerJson = {
9-
"require": {
10-
"php": "^8.1",
11-
"laravel/framework": "^10.0",
12-
"guzzlehttp/guzzle": "^7.0",
13-
"symfony/console": "^6.0",
14-
"monolog/monolog": "^3.0",
15-
"doctrine/dbal": "^3.0"
9+
'require': {
10+
'php': '^8.1',
11+
'laravel/framework': '^10.0',
12+
'guzzlehttp/guzzle': '^7.0',
13+
'symfony/console': '^6.0',
14+
'monolog/monolog': '^3.0',
15+
'doctrine/dbal': '^3.0',
16+
},
17+
'require-dev': {
18+
'phpunit/phpunit': '^10.0',
1619
},
17-
"require-dev": {
18-
"phpunit/phpunit": "^10.0"
19-
}
2020
}
2121

2222
const mockComposerJsonString = JSON.stringify(mockComposerJson, null, 2)
@@ -26,14 +26,14 @@ describe('Composer Individual PR Simulation', () => {
2626
repository: {
2727
owner: 'test-owner',
2828
name: 'test-repo',
29-
baseBranch: 'main'
29+
baseBranch: 'main',
3030
},
3131
packages: {
3232
strategy: 'all' as const,
3333
ignore: [],
3434
includePrerelease: false,
35-
excludeMajor: false
36-
}
35+
excludeMajor: false,
36+
},
3737
}
3838
buddy = new Buddy(mockConfig)
3939

@@ -53,8 +53,8 @@ describe('Composer Individual PR Simulation', () => {
5353
newVersion: 'v7.3.1',
5454
updateType: 'major' as const,
5555
dependencyType: 'require' as const,
56-
file: 'composer.json'
57-
}
56+
file: 'composer.json',
57+
},
5858
]
5959

6060
const fileUpdates = await buddy.generateAllFileUpdates(symfonyGroup)
@@ -85,8 +85,8 @@ describe('Composer Individual PR Simulation', () => {
8585
newVersion: '4.3.1',
8686
updateType: 'major' as const,
8787
dependencyType: 'require' as const,
88-
file: 'composer.json'
89-
}
88+
file: 'composer.json',
89+
},
9090
]
9191

9292
const fileUpdates = await buddy.generateAllFileUpdates(doctrineGroup)
@@ -115,8 +115,8 @@ describe('Composer Individual PR Simulation', () => {
115115
newVersion: 'v12.21.0',
116116
updateType: 'major' as const,
117117
dependencyType: 'require' as const,
118-
file: 'composer.json'
119-
}
118+
file: 'composer.json',
119+
},
120120
]
121121

122122
const fileUpdates = await buddy.generateAllFileUpdates(laravelGroup)
@@ -146,7 +146,7 @@ describe('Composer Individual PR Simulation', () => {
146146
newVersion: 'v7.3.1',
147147
updateType: 'major' as const,
148148
dependencyType: 'require' as const,
149-
file: 'composer.json'
149+
file: 'composer.json',
150150
}]
151151

152152
const symfonyFiles = await buddy.generateAllFileUpdates(symfonyGroup)
@@ -163,7 +163,7 @@ describe('Composer Individual PR Simulation', () => {
163163
newVersion: '4.3.1',
164164
updateType: 'major' as const,
165165
dependencyType: 'require' as const,
166-
file: 'composer.json'
166+
file: 'composer.json',
167167
}]
168168

169169
const doctrineFiles = await buddy.generateAllFileUpdates(doctrineGroup)

test/composer-individual-updates.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { beforeEach, describe, expect, it, spyOn } from 'bun:test'
2-
import { generateComposerUpdates } from '../src/utils/composer-parser'
32
import fs from 'node:fs'
3+
import { generateComposerUpdates } from '../src/utils/composer-parser'
44

55
describe('Composer Individual Updates', () => {
66
const mockComposerJson = {
7-
"require": {
8-
"php": "^8.1",
9-
"laravel/framework": "^10.0",
10-
"guzzlehttp/guzzle": "^7.0",
11-
"symfony/console": "^6.0",
12-
"monolog/monolog": "^3.0",
13-
"doctrine/dbal": "^3.0"
7+
'require': {
8+
'php': '^8.1',
9+
'laravel/framework': '^10.0',
10+
'guzzlehttp/guzzle': '^7.0',
11+
'symfony/console': '^6.0',
12+
'monolog/monolog': '^3.0',
13+
'doctrine/dbal': '^3.0',
14+
},
15+
'require-dev': {
16+
'phpunit/phpunit': '^10.0',
1417
},
15-
"require-dev": {
16-
"phpunit/phpunit": "^10.0"
17-
}
1818
}
1919

2020
const mockComposerJsonString = JSON.stringify(mockComposerJson, null, 2)
@@ -28,7 +28,7 @@ describe('Composer Individual Updates', () => {
2828
it('should update ONLY the target package for individual major updates', async () => {
2929
// Test individual symfony/console update (should only change symfony/console)
3030
const symfonyUpdate = [
31-
{ name: 'symfony/console', newVersion: 'v7.3.1', file: 'composer.json' }
31+
{ name: 'symfony/console', newVersion: 'v7.3.1', file: 'composer.json' },
3232
]
3333

3434
const result = await generateComposerUpdates(symfonyUpdate)
@@ -52,7 +52,7 @@ describe('Composer Individual Updates', () => {
5252
it('should update ONLY the target package for individual doctrine/dbal update', async () => {
5353
// Test individual doctrine/dbal update
5454
const doctrineUpdate = [
55-
{ name: 'doctrine/dbal', newVersion: '4.3.1', file: 'composer.json' }
55+
{ name: 'doctrine/dbal', newVersion: '4.3.1', file: 'composer.json' },
5656
]
5757

5858
const result = await generateComposerUpdates(doctrineUpdate)
@@ -73,7 +73,7 @@ describe('Composer Individual Updates', () => {
7373
it('should update ONLY the target package for individual laravel/framework update', async () => {
7474
// Test individual laravel/framework update
7575
const laravelUpdate = [
76-
{ name: 'laravel/framework', newVersion: 'v12.21.0', file: 'composer.json' }
76+
{ name: 'laravel/framework', newVersion: 'v12.21.0', file: 'composer.json' },
7777
]
7878

7979
const result = await generateComposerUpdates(laravelUpdate)
@@ -96,7 +96,7 @@ describe('Composer Individual Updates', () => {
9696
const multipleUpdates = [
9797
{ name: 'symfony/console', newVersion: 'v7.3.1', file: 'composer.json' },
9898
{ name: 'doctrine/dbal', newVersion: '4.3.1', file: 'composer.json' },
99-
{ name: 'monolog/monolog', newVersion: '3.8.0', file: 'composer.json' }
99+
{ name: 'monolog/monolog', newVersion: '3.8.0', file: 'composer.json' },
100100
]
101101

102102
const result = await generateComposerUpdates(multipleUpdates)
@@ -117,7 +117,7 @@ describe('Composer Individual Updates', () => {
117117

118118
it('should preserve formatting and structure', async () => {
119119
const singleUpdate = [
120-
{ name: 'symfony/console', newVersion: 'v7.3.1', file: 'composer.json' }
120+
{ name: 'symfony/console', newVersion: 'v7.3.1', file: 'composer.json' },
121121
]
122122

123123
const result = await generateComposerUpdates(singleUpdate)

0 commit comments

Comments
 (0)