1import { Command } from '@expo/commander';
2
3import { reviewPullRequestAsync } from '../code-review';
4
5type ActionOptions = {
6  pr: string;
7};
8
9async function action(options: ActionOptions) {
10  if (isNaN(Number(options.pr))) {
11    throw new Error('Flag `--pr` must be provided with a number value.');
12  }
13  if (!process.env.GITHUB_TOKEN) {
14    throw new Error('Environment variable `GITHUB_TOKEN` is required for this command.');
15  }
16  await reviewPullRequestAsync(+options.pr);
17}
18
19export default (program: Command) => {
20  program
21    .command('code-review')
22    .alias('review')
23    .description('Reviews the pull request.')
24    .option('-p, --pr <string>', 'ID of the pull request to review.')
25    .asyncAction(action);
26};
27