mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-11-10 01:33:11 +01:00
67 lines
1.6 KiB
JavaScript
Executable file
67 lines
1.6 KiB
JavaScript
Executable file
#!/usr/bin/env -S node --import ./run
|
|
import { execSync } from 'node:child_process'
|
|
import { mkdtempSync, rmSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { program } from 'commander'
|
|
import { getOctokit } from '@actions/github'
|
|
|
|
async function run(action, owner, repo, pull_number) {
|
|
const token = execSync('gh auth token', { encoding: 'utf-8' }).trim()
|
|
|
|
const github = getOctokit(token)
|
|
|
|
const payload = !pull_number ? {} : {
|
|
pull_request: (await github.rest.pulls.get({
|
|
owner,
|
|
repo,
|
|
pull_number,
|
|
})).data
|
|
}
|
|
|
|
const tmp = mkdtempSync(join(tmpdir(), 'github-script-'))
|
|
try {
|
|
process.env.GITHUB_WORKSPACE = tmp
|
|
process.chdir(tmp)
|
|
|
|
await action({
|
|
github,
|
|
context: {
|
|
payload,
|
|
repo: {
|
|
owner,
|
|
repo,
|
|
},
|
|
},
|
|
core: {
|
|
getInput() {
|
|
return token
|
|
},
|
|
error: console.error,
|
|
info: console.log,
|
|
notice: console.log,
|
|
setFailed(msg) {
|
|
console.error(msg)
|
|
process.exitCode = 1
|
|
},
|
|
},
|
|
dry: true,
|
|
})
|
|
} finally {
|
|
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)')
|
|
.argument('[pr]', 'Number of the Pull Request to label')
|
|
.action(async (owner, repo, pr) => {
|
|
const labels = (await import('./labels.js')).default
|
|
run(labels, owner, repo, pr)
|
|
})
|
|
|
|
await program.parse()
|