@doist/doistbot-cli 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,9 @@
1
- const REVIEW_USAGE_COMMANDS = ['doistbot review [staged]', 'db review [staged]'];
1
+ const REVIEW_USAGE_COMMANDS = [
2
+ 'doistbot review [--base <ref>]',
3
+ 'doistbot review staged',
4
+ 'db review [--base <ref>]',
5
+ 'db review staged',
6
+ ];
2
7
  const REVIEW_SETUP_COMMANDS = [
3
8
  'doistbot review',
4
9
  'doistbot review staged',
@@ -1,7 +1,6 @@
1
1
  import { getApiKeys } from '../config.js';
2
2
  import { getRepositoryRoot, loadSandboxFormatModule, loadSandboxReviewModule } from '../runtime.js';
3
3
  import { formatReviewProgress, renderAlert, renderMarkdown, withSpinner, writeLine, } from '../terminal.js';
4
- import { formatReviewUsage } from './review-usage.js';
5
4
  const LOCAL_REVIEW_SOURCE_STAGED = 'staged';
6
5
  const JSON_SCHEMA_VERSION = 1;
7
6
  const PROVIDER_DISPLAY_NAMES = {
@@ -197,12 +196,8 @@ async function runLocalReviewForCli({ source, onProgress, }) {
197
196
  onProgress,
198
197
  });
199
198
  }
200
- export async function runReview(sourceArg, options = {}) {
201
- if (sourceArg !== undefined && sourceArg !== LOCAL_REVIEW_SOURCE_STAGED) {
202
- throw new Error(formatReviewUsage());
203
- }
204
- const source = sourceArg === LOCAL_REVIEW_SOURCE_STAGED ? LOCAL_REVIEW_SOURCE_STAGED : 'base';
205
- if (options.json === true) {
199
+ export async function runReview({ source, json = false } = { source: 'base' }) {
200
+ if (json) {
206
201
  const result = await runLocalReviewForCli({ source });
207
202
  const output = formatReviewForJson(result);
208
203
  writeLine(JSON.stringify(output, null, 2));
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import { Command, Option } from 'commander';
6
6
  import { AUTH_LOGOUT_PROVIDER_USAGE, runAuthLogout, runAuthSetup, runAuthStatus, } from './actions/auth.js';
7
7
  import { runDoctor } from './actions/doctor.js';
8
8
  import { runReview } from './actions/review.js';
9
+ import { formatReviewUsage } from './actions/review-usage.js';
9
10
  import { runSetup } from './actions/setup.js';
10
11
  import { writeErrorLine } from './terminal.js';
11
12
  import { notifyAndRefreshCliUpdateCache, notifyIfCliUpdateAvailable } from './update-check.js';
@@ -21,9 +22,25 @@ function getPackageVersion() {
21
22
  }
22
23
  }
23
24
  const PACKAGE_VERSION = getPackageVersion();
25
+ const LOCAL_REVIEW_SOURCE_STAGED = 'staged';
24
26
  function getUpdateCacheEntrypointPath() {
25
27
  return fileURLToPath(new URL('./update-cache-entrypoint.js', import.meta.url));
26
28
  }
29
+ function parseReviewInput(sourceArg, options = {}) {
30
+ if (sourceArg !== undefined && sourceArg !== LOCAL_REVIEW_SOURCE_STAGED) {
31
+ throw new Error(formatReviewUsage());
32
+ }
33
+ if (sourceArg === LOCAL_REVIEW_SOURCE_STAGED && options.base) {
34
+ throw new Error(formatReviewUsage());
35
+ }
36
+ if (options.base !== undefined) {
37
+ return { source: { kind: 'base-ref', ref: options.base }, json: options.json === true };
38
+ }
39
+ return {
40
+ source: sourceArg === LOCAL_REVIEW_SOURCE_STAGED ? LOCAL_REVIEW_SOURCE_STAGED : 'base',
41
+ json: options.json === true,
42
+ };
43
+ }
27
44
  export function createProgram({ runAuthLogout: authLogout = runAuthLogout, runAuthSetup: authSetup = runAuthSetup, runAuthStatus: authStatus = runAuthStatus, runDoctor: doctor = runDoctor, runSetup: setup = runSetup, runReview: review = runReview, runAutomaticUpdateCheck: automaticUpdateCheck = async () => await notifyAndRefreshCliUpdateCache({
28
45
  currentVersion: PACKAGE_VERSION,
29
46
  updateCacheEntrypointPath: getUpdateCacheEntrypointPath(),
@@ -79,8 +96,9 @@ export function createProgram({ runAuthLogout: authLogout = runAuthLogout, runAu
79
96
  withAutomaticUpdateCheck(program
80
97
  .command('review [source]')
81
98
  .description('Run a local self-review. Use `staged` to review only staged changes.')
99
+ .option('--base <ref>', 'Review local changes against a specific base ref')
82
100
  .addOption(new Option('--json', 'Print machine-readable JSON instead of terminal-formatted markdown').hideHelp())
83
- .action(async (source, options) => await review(source, { json: options?.json === true })));
101
+ .action(async (source, options) => await review(parseReviewInput(source, options))));
84
102
  program
85
103
  .command('update')
86
104
  .description('Check whether a newer Doistbot CLI version is available')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/doistbot-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Local self-review CLI for Doistbot",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -177,7 +177,9 @@ export function getLocalReviewFiles({ runner, source, }) {
177
177
  baseBranch: `commit ${source.baseSha.slice(0, 7)}`,
178
178
  };
179
179
  }
180
- const baseBranch = resolveOriginBaseRef(runner);
180
+ const baseBranch = typeof source === 'object' && source.kind === 'base-ref'
181
+ ? source.ref
182
+ : resolveOriginBaseRef(runner);
181
183
  const mergeBase = runner(['merge-base', baseBranch, 'HEAD']).trim();
182
184
  const diff = runner(['diff', '--no-ext-diff', '--no-color', mergeBase]);
183
185
  return {