Skip to content

Commit 910502c

Browse files
committed
feat: auto clean up stale branches
chore: wip
1 parent 922ce2b commit 910502c

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

.github/workflows/buddy-bot.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ jobs:
207207
bunx buddy-bot update-check --verbose
208208
fi
209209
210+
- name: Clean up stale branches
211+
if: ${{ github.event.inputs.dry_run != 'true' }}
212+
run: |
213+
echo "🧹 Cleaning up stale buddy-bot branches..."
214+
echo "This will remove branches older than 7 days that don't have associated open PRs"
215+
216+
# Run cleanup automatically (with confirmation disabled in CI)
217+
bunx buddy-bot cleanup --days 7 --force --verbose
218+
210219
env:
211220
GITHUB_TOKEN: ${{ secrets.BUDDY_BOT_TOKEN || secrets.GITHUB_TOKEN }}
212221
BUDDY_BOT_TOKEN: ${{ secrets.BUDDY_BOT_TOKEN }}
@@ -228,7 +237,7 @@ jobs:
228237
fi
229238
230239
echo "" >> $GITHUB_STEP_SUMMARY
231-
echo "📋 View detailed logs above for check results (rebase requests and auto-closing)." >> $GITHUB_STEP_SUMMARY
240+
echo "📋 View detailed logs above for check results (rebase requests, auto-closing, and branch cleanup)." >> $GITHUB_STEP_SUMMARY
232241
233242
# Dependency update job
234243
dependency-update:

bin/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ cli
18481848
}
18491849

18501850
logger.info(`📊 Found ${staleBranches.length} stale branches to clean up:`)
1851-
staleBranches.forEach(branch => {
1851+
staleBranches.forEach((branch) => {
18521852
const daysOld = Math.floor((Date.now() - branch.lastCommitDate.getTime()) / (1000 * 60 * 60 * 24))
18531853
logger.info(` - ${branch.name} (${daysOld} days old)`)
18541854
})
@@ -1977,7 +1977,7 @@ cli
19771977
// Sort by last commit date (newest first)
19781978
branches.sort((a, b) => b.lastCommitDate.getTime() - a.lastCommitDate.getTime())
19791979

1980-
branches.forEach(branch => {
1980+
branches.forEach((branch) => {
19811981
const hasOpenPR = prBranches.has(branch.name)
19821982
const daysOld = Math.floor((Date.now() - branch.lastCommitDate.getTime()) / (1000 * 60 * 60 * 24))
19831983
const isStale = branch.lastCommitDate < cutoffDate

src/git/github-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ export class GitHubProvider implements GitProvider {
806806

807807
if (dryRun) {
808808
console.log('🔍 [DRY RUN] Would delete the following branches:')
809-
staleBranches.forEach(branch => {
809+
staleBranches.forEach((branch) => {
810810
console.log(` - ${branch.name} (last commit: ${branch.lastCommitDate.toISOString()})`)
811811
})
812812
return { deleted: staleBranches.map(b => b.name), failed: [] }

src/setup.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,19 @@ ${generateComposerSetupSteps()}
13071307
GITHUB_TOKEN: ${tokenEnv}
13081308
BUDDY_BOT_TOKEN: \${{ secrets.BUDDY_BOT_TOKEN }}
13091309
1310+
- name: Clean up stale branches
1311+
if: \${{ github.event.inputs.dry_run != 'true' }}
1312+
run: |
1313+
echo "🧹 Cleaning up stale buddy-bot branches..."
1314+
echo "This will remove branches older than 7 days that don't have associated open PRs"
1315+
1316+
# Run cleanup automatically (with confirmation disabled in CI)
1317+
bunx buddy-bot cleanup --days 7 --force --verbose
1318+
1319+
env:
1320+
GITHUB_TOKEN: ${tokenEnv}
1321+
BUDDY_BOT_TOKEN: \${{ secrets.BUDDY_BOT_TOKEN }}
1322+
13101323
- name: Create check summary
13111324
if: always()
13121325
run: |
@@ -1324,7 +1337,7 @@ ${generateComposerSetupSteps()}
13241337
fi
13251338
13261339
echo "" >> \$GITHUB_STEP_SUMMARY
1327-
echo "📋 View detailed logs above for check results (rebase requests and auto-closing)." >> \$GITHUB_STEP_SUMMARY
1340+
echo "📋 View detailed logs above for check results (rebase requests, auto-closing, and branch cleanup)." >> \$GITHUB_STEP_SUMMARY
13281341
13291342
# Dependency update job
13301343
dependency-update:

0 commit comments

Comments
 (0)