ci/github-script: add commander CLI interface
This makes it easier to add additional features.
This commit is contained in:
@@ -10,4 +10,4 @@ To run any of the scripts locally:
|
|||||||
|
|
||||||
## Labeler
|
## Labeler
|
||||||
|
|
||||||
Run `./run.js OWNER REPO`, where OWNER is your username or "NixOS" and REPO the name of your fork or "nixpkgs".
|
Run `./run.js labels OWNER REPO`, where OWNER is your username or "NixOS" and REPO the name of your fork or "nixpkgs".
|
||||||
|
|||||||
14
ci/github-script/package-lock.json
generated
14
ci/github-script/package-lock.json
generated
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "labels",
|
"name": "github-script",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
@@ -7,7 +7,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/artifact": "2.3.2",
|
"@actions/artifact": "2.3.2",
|
||||||
"@actions/github": "6.0.1",
|
"@actions/github": "6.0.1",
|
||||||
"bottleneck": "2.19.5"
|
"bottleneck": "2.19.5",
|
||||||
|
"commander": "14.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/artifact": {
|
"node_modules/@actions/artifact": {
|
||||||
@@ -950,6 +951,15 @@
|
|||||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/commander": {
|
||||||
|
"version": "14.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/commander/-/commander-14.0.0.tgz",
|
||||||
|
"integrity": "sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/compress-commons": {
|
"node_modules/compress-commons": {
|
||||||
"version": "6.0.2",
|
"version": "6.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-6.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-6.0.2.tgz",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/artifact": "2.3.2",
|
"@actions/artifact": "2.3.2",
|
||||||
"@actions/github": "6.0.1",
|
"@actions/github": "6.0.1",
|
||||||
"bottleneck": "2.19.5"
|
"bottleneck": "2.19.5",
|
||||||
|
"commander": "14.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,21 +3,18 @@ import { execSync } from 'node:child_process'
|
|||||||
import { mkdtempSync, rmSync } from 'node:fs'
|
import { mkdtempSync, rmSync } from 'node:fs'
|
||||||
import { tmpdir } from 'node:os'
|
import { tmpdir } from 'node:os'
|
||||||
import { join } from 'node:path'
|
import { join } from 'node:path'
|
||||||
|
import { program } from 'commander'
|
||||||
import { getOctokit } from '@actions/github'
|
import { getOctokit } from '@actions/github'
|
||||||
import labels from './labels.cjs'
|
|
||||||
|
|
||||||
if (process.argv.length !== 4)
|
|
||||||
throw new Error('Call this with exactly three arguments: ./run OWNER REPO')
|
|
||||||
const [, , owner, repo] = process.argv
|
|
||||||
|
|
||||||
|
async function run(action, owner, repo) {
|
||||||
const token = execSync('gh auth token', { encoding: 'utf-8' }).trim()
|
const token = execSync('gh auth token', { encoding: 'utf-8' }).trim()
|
||||||
|
|
||||||
const tmp = mkdtempSync(join(tmpdir(), 'labels-'))
|
const tmp = mkdtempSync(join(tmpdir(), 'github-script-'))
|
||||||
try {
|
try {
|
||||||
process.env.GITHUB_WORKSPACE = tmp
|
process.env.GITHUB_WORKSPACE = tmp
|
||||||
process.chdir(tmp)
|
process.chdir(tmp)
|
||||||
|
|
||||||
await labels({
|
await action({
|
||||||
github: getOctokit(token),
|
github: getOctokit(token),
|
||||||
context: {
|
context: {
|
||||||
payload: {},
|
payload: {},
|
||||||
@@ -43,3 +40,16 @@ try {
|
|||||||
} finally {
|
} finally {
|
||||||
rmSync(tmp, { recursive: true })
|
rmSync(tmp, { recursive: true })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('labels')
|
||||||
|
.description('Manage labels on pull requests.')
|
||||||
|
.argument('<owner>', 'Owner of the GitHub repository to label (Example: NixOS)')
|
||||||
|
.argument('<repo>', 'Name of the GitHub repository to label (Example: nixpkgs)')
|
||||||
|
.action(async (owner, repo) => {
|
||||||
|
const labels = (await import('./labels.cjs')).default
|
||||||
|
run(labels, owner, repo)
|
||||||
|
})
|
||||||
|
|
||||||
|
await program.parse()
|
||||||
|
|||||||
Reference in New Issue
Block a user