mirror of
https://github.com/CHN-beta/nixpkgs.git
synced 2026-01-13 11:30:35 +08:00
This allows building markdown summaries, which is hard to mock.
(cherry picked from commit 2433050fb7)
59 lines
1.5 KiB
JavaScript
Executable File
59 lines
1.5 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 * as core from '@actions/core'
|
|
import { getOctokit } from '@actions/github'
|
|
|
|
async function run(action, owner, repo, pull_number, dry) {
|
|
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.env['INPUT_GITHUB-TOKEN'] = token
|
|
process.chdir(tmp)
|
|
|
|
await action({
|
|
github,
|
|
context: {
|
|
payload,
|
|
repo: {
|
|
owner,
|
|
repo,
|
|
},
|
|
},
|
|
core,
|
|
dry,
|
|
})
|
|
} 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')
|
|
.option('--no-dry', 'Make actual modifications')
|
|
.action(async (owner, repo, pr, options) => {
|
|
const labels = (await import('./labels.js')).default
|
|
run(labels, owner, repo, pr, options.dry)
|
|
})
|
|
|
|
await program.parse()
|