summaryrefslogtreecommitdiff
path: root/ci/github-script/run
blob: b523cc2dbc26cde4d07b68dc4072ca53e1c3d8ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env -S node --import ./run
import { execSync } from 'node:child_process'
import { closeSync, openSync } from 'node:fs'
import { program } from 'commander'
import * as core from '@actions/core'
import { getOctokit } from '@actions/github'

async function run(action, owner, repo, pull_number, options = {}) {
  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,
      }

  process.env['INPUT_GITHUB-TOKEN'] = token

  closeSync(openSync('step-summary.md', 'w'))
  process.env.GITHUB_STEP_SUMMARY = 'step-summary.md'

  await action({
    github,
    context: {
      payload,
      repo: { owner, repo },
    },
    core,
    dry: true,
    ...options,
  })
}

program
  .command('prepare')
  .description('Validate PR mergeability and branch targeting.')
  .argument('<owner>', 'Repository owner (e.g. YongDo-Hyun)')
  .argument('<repo>', 'Repository name (e.g. Project-Tick)')
  .argument('<pr>', 'Pull Request number')
  .option('--no-dry', 'Make actual modifications')
  .action(async (owner, repo, pr, options) => {
    const prepare = (await import('./prepare.js')).default
    await run(prepare, owner, repo, pr, options)
  })

program
  .command('lint-commits')
  .description('Lint commit messages for Conventional Commits compliance.')
  .argument('<owner>', 'Repository owner (e.g. YongDo-Hyun)')
  .argument('<repo>', 'Repository name (e.g. Project-Tick)')
  .argument('<pr>', 'Pull Request number')
  .action(async (owner, repo, pr) => {
    const lint = (await import('./lint-commits.js')).default
    await run(lint, owner, repo, pr)
  })

program.parse()