Skip to content

Commit

Permalink
ci: auto-merge translation PRs once approved
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Jul 18, 2024
1 parent 2139725 commit 7ddd52d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/translate-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: pnpm install --ignore-scripts

- name: Adjust labels
run: pnpm run ci:adjust-labels
run: pnpm run ci:adjust-labels --merge-if-approved
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
31 changes: 26 additions & 5 deletions src/cli/adjustLabels.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import {adjustLabels} from '../api/ghLabels'
import {parseArgs} from 'node:util'

import {adjustLabels, PR_LABEL_APPROVED} from '../api/ghLabels'
import {mergePR} from '../api/gitActions'
import {runScript} from '../util/runScript'

const PR_NUMBER = parseInt((process.env.PR_NUMBER || '').trim(), 10)
if (!PR_NUMBER || PR_NUMBER <= 0 || isNaN(PR_NUMBER)) {
throw new Error('PR_NUMBER environment variable is required')
}

runScript(() =>
adjustLabels({
const {
values: {'merge-if-approved': mergeIfApproved},
} = parseArgs({
strict: true,
options: {
'merge-if-approved': {
type: 'boolean',
description: 'Merge the PR if it is approved by a maintainer',
default: false,
},
},
})

runScript(async () => {
const result = await adjustLabels({
prNumber: PR_NUMBER,
logger: (message) => console.log(message),
}),
)
})

if (mergeIfApproved && result === PR_LABEL_APPROVED) {
console.log('PR is approved, merging')
await mergePR(PR_NUMBER)
}
})

0 comments on commit 7ddd52d

Please sign in to comment.