@pilatos/bitbucket-cli 1.6.0 → 1.7.1

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.
Files changed (3) hide show
  1. package/README.md +35 -168
  2. package/dist/index.js +881 -812
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10901,6 +10901,17 @@ var require_db = __commonJS((exports, module) => {
10901
10901
  };
10902
10902
  });
10903
10903
 
10904
+ // node_modules/mime-db/index.js
10905
+ var require_mime_db = __commonJS((exports, module) => {
10906
+ /*!
10907
+ * mime-db
10908
+ * Copyright(c) 2014 Jonathan Ong
10909
+ * Copyright(c) 2015-2022 Douglas Christopher Wilson
10910
+ * MIT Licensed
10911
+ */
10912
+ module.exports = require_db();
10913
+ });
10914
+
10904
10915
  // node_modules/mime-types/index.js
10905
10916
  var require_mime_types = __commonJS((exports) => {
10906
10917
  /*!
@@ -10909,7 +10920,7 @@ var require_mime_types = __commonJS((exports) => {
10909
10920
  * Copyright(c) 2015 Douglas Christopher Wilson
10910
10921
  * MIT Licensed
10911
10922
  */
10912
- var db = require_db();
10923
+ var db = require_mime_db();
10913
10924
  var extname = __require("path").extname;
10914
10925
  var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
10915
10926
  var TEXT_TYPE_REGEXP = /^text\//i;
@@ -11256,7 +11267,7 @@ var require_round = __commonJS((exports, module) => {
11256
11267
 
11257
11268
  // node_modules/math-intrinsics/isNaN.js
11258
11269
  var require_isNaN = __commonJS((exports, module) => {
11259
- module.exports = Number.isNaN || function isNaN2(a) {
11270
+ module.exports = Number.isNaN || function isNaN(a) {
11260
11271
  return a !== a;
11261
11272
  };
11262
11273
  });
@@ -11390,7 +11401,7 @@ var require_implementation = __commonJS((exports, module) => {
11390
11401
  var toStr = Object.prototype.toString;
11391
11402
  var max = Math.max;
11392
11403
  var funcType = "[object Function]";
11393
- var concatty = function concatty2(a, b) {
11404
+ var concatty = function concatty(a, b) {
11394
11405
  var arr = [];
11395
11406
  for (var i = 0;i < a.length; i += 1) {
11396
11407
  arr[i] = a[i];
@@ -11400,7 +11411,7 @@ var require_implementation = __commonJS((exports, module) => {
11400
11411
  }
11401
11412
  return arr;
11402
11413
  };
11403
- var slicy = function slicy2(arrLike, offset) {
11414
+ var slicy = function slicy(arrLike, offset) {
11404
11415
  var arr = [];
11405
11416
  for (var i = offset || 0, j = 0;i < arrLike.length; i += 1, j += 1) {
11406
11417
  arr[j] = arrLike[i];
@@ -11417,7 +11428,7 @@ var require_implementation = __commonJS((exports, module) => {
11417
11428
  }
11418
11429
  return str;
11419
11430
  };
11420
- module.exports = function bind2(that) {
11431
+ module.exports = function bind(that) {
11421
11432
  var target = this;
11422
11433
  if (typeof target !== "function" || toStr.apply(target) !== funcType) {
11423
11434
  throw new TypeError(ERROR_MESSAGE + target);
@@ -11441,7 +11452,7 @@ var require_implementation = __commonJS((exports, module) => {
11441
11452
  }
11442
11453
  bound = Function("binder", "return function (" + joiny(boundArgs, ",") + "){ return binder.apply(this,arguments); }")(binder);
11443
11454
  if (target.prototype) {
11444
- var Empty = function Empty2() {};
11455
+ var Empty = function Empty() {};
11445
11456
  Empty.prototype = target.prototype;
11446
11457
  bound.prototype = new Empty;
11447
11458
  Empty.prototype = null;
@@ -11680,7 +11691,7 @@ var require_get_intrinsic = __commonJS((exports, module) => {
11680
11691
  }
11681
11692
  }
11682
11693
  var errorProto;
11683
- var doEval = function doEval2(name) {
11694
+ var doEval = function doEval(name) {
11684
11695
  var value;
11685
11696
  if (name === "%AsyncFunction%") {
11686
11697
  value = getEvalledConstructor("async function () {}");
@@ -11689,12 +11700,12 @@ var require_get_intrinsic = __commonJS((exports, module) => {
11689
11700
  } else if (name === "%AsyncGeneratorFunction%") {
11690
11701
  value = getEvalledConstructor("async function* () {}");
11691
11702
  } else if (name === "%AsyncGenerator%") {
11692
- var fn = doEval2("%AsyncGeneratorFunction%");
11703
+ var fn = doEval("%AsyncGeneratorFunction%");
11693
11704
  if (fn) {
11694
11705
  value = fn.prototype;
11695
11706
  }
11696
11707
  } else if (name === "%AsyncIteratorPrototype%") {
11697
- var gen = doEval2("%AsyncGenerator%");
11708
+ var gen = doEval("%AsyncGenerator%");
11698
11709
  if (gen && getProto) {
11699
11710
  value = getProto(gen.prototype);
11700
11711
  }
@@ -11765,7 +11776,7 @@ var require_get_intrinsic = __commonJS((exports, module) => {
11765
11776
  var $exec = bind2.call($call, RegExp.prototype.exec);
11766
11777
  var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
11767
11778
  var reEscapeChar = /\\(\\)?/g;
11768
- var stringToPath = function stringToPath2(string) {
11779
+ var stringToPath = function stringToPath(string) {
11769
11780
  var first = $strSlice(string, 0, 1);
11770
11781
  var last = $strSlice(string, -1);
11771
11782
  if (first === "%" && last !== "%") {
@@ -11779,7 +11790,7 @@ var require_get_intrinsic = __commonJS((exports, module) => {
11779
11790
  });
11780
11791
  return result;
11781
11792
  };
11782
- var getBaseIntrinsic = function getBaseIntrinsic2(name, allowMissing) {
11793
+ var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
11783
11794
  var intrinsicName = name;
11784
11795
  var alias;
11785
11796
  if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
@@ -15954,7 +15965,7 @@ var require_lodash = __commonJS((exports, module) => {
15954
15965
  function unicodeWords(string) {
15955
15966
  return string.match(reUnicodeWord) || [];
15956
15967
  }
15957
- var runInContext = function runInContext2(context) {
15968
+ var runInContext = function runInContext(context) {
15958
15969
  context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
15959
15970
  var { Array: Array2, Date: Date2, Error: Error2, Function: Function2, Math: Math2, Object: Object2, RegExp: RegExp2, String: String2, TypeError: TypeError2 } = context;
15960
15971
  var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
@@ -20467,7 +20478,7 @@ __p += '`;
20467
20478
  lodash.replace = replace;
20468
20479
  lodash.result = result;
20469
20480
  lodash.round = round;
20470
- lodash.runInContext = runInContext2;
20481
+ lodash.runInContext = runInContext;
20471
20482
  lodash.sample = sample2;
20472
20483
  lodash.size = size;
20473
20484
  lodash.snakeCase = snakeCase;
@@ -29121,7 +29132,7 @@ var require_multicast = __commonJS((exports) => {
29121
29132
  if (typeof subjectOrSubjectFactory === "function") {
29122
29133
  subjectFactory = subjectOrSubjectFactory;
29123
29134
  } else {
29124
- subjectFactory = function subjectFactory2() {
29135
+ subjectFactory = function subjectFactory() {
29125
29136
  return subjectOrSubjectFactory;
29126
29137
  };
29127
29138
  }
@@ -32592,7 +32603,7 @@ var require_signal_exit = __commonJS((exports, module) => {
32592
32603
  emitter.on(ev, cb);
32593
32604
  return remove;
32594
32605
  };
32595
- unload = function unload2() {
32606
+ unload = function unload() {
32596
32607
  if (!loaded || !processOk(global.process)) {
32597
32608
  return;
32598
32609
  }
@@ -32607,7 +32618,7 @@ var require_signal_exit = __commonJS((exports, module) => {
32607
32618
  emitter.count -= 1;
32608
32619
  };
32609
32620
  module.exports.unload = unload;
32610
- emit = function emit2(event, code, signal) {
32621
+ emit = function emit(event, code, signal) {
32611
32622
  if (emitter.emitted[event]) {
32612
32623
  return;
32613
32624
  }
@@ -32636,7 +32647,7 @@ var require_signal_exit = __commonJS((exports, module) => {
32636
32647
  return signals;
32637
32648
  };
32638
32649
  loaded = false;
32639
- load = function load2() {
32650
+ load = function load() {
32640
32651
  if (loaded || !processOk(global.process)) {
32641
32652
  return;
32642
32653
  }
@@ -32655,7 +32666,7 @@ var require_signal_exit = __commonJS((exports, module) => {
32655
32666
  };
32656
32667
  module.exports.load = load;
32657
32668
  originalProcessReallyExit = process3.reallyExit;
32658
- processReallyExit = function processReallyExit2(code) {
32669
+ processReallyExit = function processReallyExit(code) {
32659
32670
  if (!processOk(global.process)) {
32660
32671
  return;
32661
32672
  }
@@ -32665,7 +32676,7 @@ var require_signal_exit = __commonJS((exports, module) => {
32665
32676
  originalProcessReallyExit.call(process3, process3.exitCode);
32666
32677
  };
32667
32678
  originalProcessEmit = process3.emit;
32668
- processEmit = function processEmit2(ev, arg) {
32679
+ processEmit = function processEmit(ev, arg) {
32669
32680
  if (ev === "exit" && processOk(global.process)) {
32670
32681
  if (arg !== undefined) {
32671
32682
  process3.exitCode = arg;
@@ -42622,7 +42633,7 @@ var require_lib = __commonJS((exports, module) => {
42622
42633
  iconv.encodings = null;
42623
42634
  iconv.defaultCharUnicode = "\uFFFD";
42624
42635
  iconv.defaultCharSingleByte = "?";
42625
- iconv.encode = function encode3(str, encoding, options) {
42636
+ iconv.encode = function encode(str, encoding, options) {
42626
42637
  str = "" + (str || "");
42627
42638
  var encoder = iconv.getEncoder(encoding, options);
42628
42639
  var res = encoder.write(str);
@@ -44099,9 +44110,7 @@ class Container {
44099
44110
  services = new Map;
44100
44111
  static instance = null;
44101
44112
  static getInstance() {
44102
- if (!Container.instance) {
44103
- Container.instance = new Container;
44104
- }
44113
+ Container.instance ??= new Container;
44105
44114
  return Container.instance;
44106
44115
  }
44107
44116
  static reset() {
@@ -44446,14 +44455,14 @@ class ContextService {
44446
44455
  this.configService = configService;
44447
44456
  }
44448
44457
  parseRemoteUrl(url) {
44449
- const sshMatch = url.match(/git@bitbucket\.org:([^/]+)\/([^.]+)(?:\.git)?/);
44458
+ const sshMatch = new RegExp(/git@bitbucket\.org:([^/]+)\/([^.]+)(?:\.git)?/).exec(url);
44450
44459
  if (sshMatch) {
44451
44460
  return {
44452
44461
  workspace: sshMatch[1],
44453
44462
  repoSlug: sshMatch[2]
44454
44463
  };
44455
44464
  }
44456
- const httpsMatch = url.match(/https?:\/\/(?:[^@]+@)?bitbucket\.org\/([^/]+)\/([^/.]+)(?:\.git)?/);
44465
+ const httpsMatch = new RegExp(/https?:\/\/(?:[^@]+@)?bitbucket\.org\/([^/]+)\/([^/.]+)(?:\.git)?/).exec(url);
44457
44466
  if (httpsMatch) {
44458
44467
  return {
44459
44468
  workspace: httpsMatch[1],
@@ -45069,6 +45078,30 @@ class OutputService {
45069
45078
  bold(text) {
45070
45079
  return this.format(text, source_default.bold);
45071
45080
  }
45081
+ red(text) {
45082
+ return this.format(text, source_default.red);
45083
+ }
45084
+ green(text) {
45085
+ return this.format(text, source_default.green);
45086
+ }
45087
+ yellow(text) {
45088
+ return this.format(text, source_default.yellow);
45089
+ }
45090
+ cyan(text) {
45091
+ return this.format(text, source_default.cyan);
45092
+ }
45093
+ magenta(text) {
45094
+ return this.format(text, source_default.magenta);
45095
+ }
45096
+ gray(text) {
45097
+ return this.format(text, source_default.gray);
45098
+ }
45099
+ blue(text) {
45100
+ return this.format(text, source_default.blue);
45101
+ }
45102
+ underline(text) {
45103
+ return this.format(text, source_default.underline);
45104
+ }
45072
45105
  }
45073
45106
  // src/services/version.service.ts
45074
45107
  var NPM_REGISTRY_URL = "https://registry.npmjs.org/@pilatos/bitbucket-cli";
@@ -45158,7 +45191,7 @@ class VersionService {
45158
45191
  const cleanVersion = version.replace(/^v/, "");
45159
45192
  return cleanVersion.split(".").map((part) => {
45160
45193
  const numPart = part.split("-")[0];
45161
- return parseInt(numPart, 10) || 0;
45194
+ return Number.parseInt(numPart, 10) || 0;
45162
45195
  });
45163
45196
  };
45164
45197
  const newParts = parseVersion(newVersion);
@@ -51476,6 +51509,14 @@ class BaseCommand {
51476
51509
  constructor(output) {
51477
51510
  this.output = output;
51478
51511
  }
51512
+ async run(options, context) {
51513
+ try {
51514
+ return await this.execute(options, context);
51515
+ } catch (error) {
51516
+ this.handleError(error, context);
51517
+ throw error;
51518
+ }
51519
+ }
51479
51520
  handleError(error, context) {
51480
51521
  if (error instanceof Error) {
51481
51522
  this.output.error(error.message);
@@ -51512,24 +51553,30 @@ class LoginCommand extends BaseCommand {
51512
51553
  const username = options.username || process.env.BB_USERNAME;
51513
51554
  const apiToken = options.password || process.env.BB_API_TOKEN;
51514
51555
  if (!username) {
51515
- const error = new Error("Username is required. Use --username option or set BB_USERNAME environment variable.");
51516
- this.output.error(error.message);
51517
- throw error;
51556
+ throw new Error("Username is required. Use --username option or set BB_USERNAME environment variable.");
51518
51557
  }
51519
51558
  if (!apiToken) {
51520
- const error = new Error("API token is required. Use --password option or set BB_API_TOKEN environment variable.");
51521
- this.output.error(error.message);
51522
- throw error;
51559
+ throw new Error("API token is required. Use --password option or set BB_API_TOKEN environment variable.");
51523
51560
  }
51524
51561
  await this.configService.setCredentials({ username, apiToken });
51525
51562
  try {
51526
51563
  const response = await this.usersApi.userGet();
51527
51564
  const user = response.data;
51565
+ if (context.globalOptions.json) {
51566
+ this.output.json({
51567
+ authenticated: true,
51568
+ user: {
51569
+ username: user.username,
51570
+ displayName: user.display_name,
51571
+ accountId: user.account_id
51572
+ }
51573
+ });
51574
+ return;
51575
+ }
51528
51576
  this.output.success(`Logged in as ${user.display_name} (${user.username})`);
51529
51577
  } catch (error) {
51530
51578
  await this.configService.clearConfig();
51531
- this.output.error(`Authentication failed: ${error instanceof Error ? error.message : String(error)}`);
51532
- throw error;
51579
+ throw new Error(`Authentication failed: ${error instanceof Error ? error.message : String(error)}`);
51533
51580
  }
51534
51581
  }
51535
51582
  }
@@ -51543,8 +51590,12 @@ class LogoutCommand extends BaseCommand {
51543
51590
  super(output);
51544
51591
  this.configService = configService;
51545
51592
  }
51546
- async execute(_options, _context) {
51593
+ async execute(_options, context) {
51547
51594
  await this.configService.clearConfig();
51595
+ if (context.globalOptions.json) {
51596
+ this.output.json({ authenticated: false, success: true });
51597
+ return;
51598
+ }
51548
51599
  this.output.success("Logged out of Bitbucket");
51549
51600
  }
51550
51601
  }
@@ -51563,24 +51614,38 @@ class StatusCommand extends BaseCommand {
51563
51614
  async execute(_options, context) {
51564
51615
  const config = await this.configService.getConfig();
51565
51616
  if (!config.username || !config.apiToken) {
51617
+ if (context.globalOptions.json) {
51618
+ this.output.json({ authenticated: false });
51619
+ return;
51620
+ }
51566
51621
  this.output.info("Not logged in");
51567
- this.output.text(`Run ${source_default.cyan("bb auth login")} to authenticate.`);
51622
+ this.output.text(`Run ${this.output.highlight("bb auth login")} to authenticate.`);
51568
51623
  return;
51569
51624
  }
51570
51625
  try {
51571
51626
  const response = await this.usersApi.userGet();
51572
51627
  const user = response.data;
51628
+ if (context.globalOptions.json) {
51629
+ this.output.json({
51630
+ authenticated: true,
51631
+ user: {
51632
+ username: user.username,
51633
+ displayName: user.display_name,
51634
+ accountId: user.account_id
51635
+ },
51636
+ defaultWorkspace: config.defaultWorkspace
51637
+ });
51638
+ return;
51639
+ }
51573
51640
  this.output.success("Logged in to Bitbucket");
51574
- this.output.text(` Username: ${source_default.cyan(user.username)}`);
51641
+ this.output.text(` Username: ${this.output.highlight(user.username ?? "")}`);
51575
51642
  this.output.text(` Display name: ${user.display_name}`);
51576
51643
  this.output.text(` Account ID: ${user.account_id}`);
51577
51644
  if (config.defaultWorkspace) {
51578
- this.output.text(` Default workspace: ${source_default.cyan(config.defaultWorkspace)}`);
51645
+ this.output.text(` Default workspace: ${this.output.highlight(config.defaultWorkspace)}`);
51579
51646
  }
51580
51647
  } catch (error) {
51581
- this.output.error("Authentication is invalid or expired");
51582
- this.output.text(`Run ${source_default.cyan("bb auth login")} to re-authenticate.`);
51583
- throw error;
51648
+ throw new Error(`Authentication is invalid or expired. Run ${this.output.highlight("bb auth login")} to re-authenticate.`);
51584
51649
  }
51585
51650
  }
51586
51651
  }
@@ -51594,14 +51659,16 @@ class TokenCommand extends BaseCommand {
51594
51659
  super(output);
51595
51660
  this.configService = configService;
51596
51661
  }
51597
- async execute(_options, _context) {
51662
+ async execute(_options, context) {
51598
51663
  const credentials = await this.configService.getCredentials();
51599
51664
  if (!credentials.username || !credentials.apiToken) {
51600
- const error = new Error("Not authenticated. Run 'bb auth login' first.");
51601
- this.output.error(error.message);
51602
- throw error;
51665
+ throw new Error("Not authenticated. Run 'bb auth login' first.");
51603
51666
  }
51604
51667
  const token = Buffer.from(`${credentials.username}:${credentials.apiToken}`).toString("base64");
51668
+ if (context.globalOptions.json) {
51669
+ this.output.json({ token });
51670
+ return;
51671
+ }
51605
51672
  this.output.text(token);
51606
51673
  }
51607
51674
  }
@@ -51622,6 +51689,15 @@ class CloneCommand extends BaseCommand {
51622
51689
  const repoUrl = await this.resolveRepositoryUrl(repository);
51623
51690
  await this.gitService.clone(repoUrl, directory);
51624
51691
  const targetDir = directory || this.extractRepoName(repository);
51692
+ if (context.globalOptions.json) {
51693
+ this.output.json({
51694
+ success: true,
51695
+ repository,
51696
+ path: targetDir,
51697
+ cloneUrl: repoUrl
51698
+ });
51699
+ return;
51700
+ }
51625
51701
  this.output.success(`Cloned ${repository} into ${targetDir}`);
51626
51702
  }
51627
51703
  async resolveRepositoryUrl(repository) {
@@ -51648,7 +51724,10 @@ class CloneCommand extends BaseCommand {
51648
51724
  }
51649
51725
  extractRepoName(repository) {
51650
51726
  const parts = repository.split("/");
51651
- const lastPart = parts[parts.length - 1];
51727
+ const lastPart = parts.at(-1);
51728
+ if (!lastPart) {
51729
+ throw new Error("Invalid repository format.");
51730
+ }
51652
51731
  return lastPart.replace(".git", "");
51653
51732
  }
51654
51733
  }
@@ -51680,22 +51759,21 @@ class CreateRepoCommand extends BaseCommand {
51680
51759
  if (project) {
51681
51760
  request.project = { type: "project", key: project };
51682
51761
  }
51683
- try {
51684
- const response = await this.repositoriesApi.repositoriesWorkspaceRepoSlugPost({
51685
- workspace,
51686
- repoSlug: name,
51687
- body: request
51688
- });
51689
- const repo = response.data;
51690
- this.output.success(`Created repository ${repo.full_name}`);
51691
- this.output.text(` ${source_default.dim("URL:")} ${repo.links?.html?.href}`);
51692
- const sshClone = Array.from(repo.links?.clone ?? []).find((c) => c.name === "ssh");
51693
- if (sshClone?.href) {
51694
- this.output.text(` ${source_default.dim("Clone:")} git clone ${sshClone.href}`);
51695
- }
51696
- } catch (error) {
51697
- this.handleError(error, context);
51698
- throw error;
51762
+ const response = await this.repositoriesApi.repositoriesWorkspaceRepoSlugPost({
51763
+ workspace,
51764
+ repoSlug: name,
51765
+ body: request
51766
+ });
51767
+ const repo = response.data;
51768
+ if (context.globalOptions.json) {
51769
+ this.output.json(repo);
51770
+ return;
51771
+ }
51772
+ this.output.success(`Created repository ${repo.full_name}`);
51773
+ this.output.text(` ${this.output.dim("URL:")} ${repo.links?.html?.href}`);
51774
+ const sshClone = Array.from(repo.links?.clone ?? []).find((c) => c.name === "ssh");
51775
+ if (sshClone?.href) {
51776
+ this.output.text(` ${this.output.dim("Clone:")} git clone ${sshClone.href}`);
51699
51777
  }
51700
51778
  }
51701
51779
  async resolveWorkspace(workspace) {
@@ -51722,27 +51800,30 @@ class ListReposCommand extends BaseCommand {
51722
51800
  this.configService = configService;
51723
51801
  }
51724
51802
  async execute(options, context) {
51725
- const workspace = await this.resolveWorkspace(options.workspace);
51726
- const limit = parseInt(options.limit || "25", 10);
51727
- try {
51728
- const response = await this.repositoriesApi.repositoriesWorkspaceGet({
51729
- workspace
51803
+ const workspace = await this.resolveWorkspace(options.workspace ?? context.globalOptions.workspace);
51804
+ const limit = Number.parseInt(options.limit || "25", 10);
51805
+ const response = await this.repositoriesApi.repositoriesWorkspaceGet({
51806
+ workspace
51807
+ });
51808
+ const repos = Array.from(response.data.values ?? []).slice(0, limit);
51809
+ if (context.globalOptions.json) {
51810
+ this.output.json({
51811
+ workspace,
51812
+ count: repos.length,
51813
+ repositories: repos
51730
51814
  });
51731
- const repos = Array.from(response.data.values ?? []).slice(0, limit);
51732
- if (repos.length === 0) {
51733
- this.output.text("No repositories found");
51734
- return;
51735
- }
51736
- const rows = repos.map((repo) => [
51737
- repo.full_name ?? "",
51738
- repo.is_private ? "private" : "public",
51739
- (repo.description || "").substring(0, 50)
51740
- ]);
51741
- this.output.table(["REPOSITORY", "VISIBILITY", "DESCRIPTION"], rows);
51742
- } catch (error) {
51743
- this.handleError(error, context);
51744
- throw error;
51815
+ return;
51745
51816
  }
51817
+ if (repos.length === 0) {
51818
+ this.output.text("No repositories found");
51819
+ return;
51820
+ }
51821
+ const rows = repos.map((repo) => [
51822
+ repo.full_name ?? "",
51823
+ repo.is_private ? "private" : "public",
51824
+ (repo.description || "").substring(0, 50)
51825
+ ]);
51826
+ this.output.table(["REPOSITORY", "VISIBILITY", "DESCRIPTION"], rows);
51746
51827
  }
51747
51828
  async resolveWorkspace(workspace) {
51748
51829
  if (workspace) {
@@ -51779,36 +51860,35 @@ class ViewRepoCommand extends BaseCommand {
51779
51860
  }
51780
51861
  }
51781
51862
  const repoContext = await this.contextService.requireRepoContext(contextOptions);
51782
- try {
51783
- const response = await this.repositoriesApi.repositoriesWorkspaceRepoSlugGet({
51784
- workspace: repoContext.workspace,
51785
- repoSlug: repoContext.repoSlug
51786
- });
51787
- const repo = response.data;
51788
- this.output.text(source_default.bold(repo.full_name ?? ""));
51789
- if (repo.description) {
51790
- this.output.text(source_default.dim(repo.description));
51791
- }
51792
- this.output.text("");
51793
- this.output.text(` ${source_default.dim("Visibility:")} ${repo.is_private ? "Private" : "Public"}`);
51794
- this.output.text(` ${source_default.dim("Owner:")} ${repo.owner?.display_name ?? "Unknown"}`);
51795
- if (repo.language) {
51796
- this.output.text(` ${source_default.dim("Language:")} ${repo.language}`);
51797
- }
51798
- if (repo.mainbranch) {
51799
- this.output.text(` ${source_default.dim("Default branch:")} ${repo.mainbranch.name}`);
51800
- }
51801
- this.output.text(` ${source_default.dim("Created:")} ${this.output.formatDate(repo.created_on ?? "")}`);
51802
- this.output.text(` ${source_default.dim("Updated:")} ${this.output.formatDate(repo.updated_on ?? "")}`);
51803
- this.output.text("");
51804
- this.output.text(` ${source_default.dim("URL:")} ${repo.links?.html?.href}`);
51805
- const sshClone = Array.from(repo.links?.clone ?? []).find((c) => c.name === "ssh");
51806
- if (sshClone?.href) {
51807
- this.output.text(` ${source_default.dim("SSH:")} ${sshClone.href}`);
51808
- }
51809
- } catch (error) {
51810
- this.handleError(error, context);
51811
- throw error;
51863
+ const response = await this.repositoriesApi.repositoriesWorkspaceRepoSlugGet({
51864
+ workspace: repoContext.workspace,
51865
+ repoSlug: repoContext.repoSlug
51866
+ });
51867
+ const repo = response.data;
51868
+ if (context.globalOptions.json) {
51869
+ this.output.json(repo);
51870
+ return;
51871
+ }
51872
+ this.output.text(this.output.bold(repo.full_name ?? ""));
51873
+ if (repo.description) {
51874
+ this.output.text(this.output.dim(repo.description));
51875
+ }
51876
+ this.output.text("");
51877
+ this.output.text(` ${this.output.dim("Visibility:")} ${repo.is_private ? "Private" : "Public"}`);
51878
+ this.output.text(` ${this.output.dim("Owner:")} ${repo.owner?.display_name ?? "Unknown"}`);
51879
+ if (repo.language) {
51880
+ this.output.text(` ${this.output.dim("Language:")} ${repo.language}`);
51881
+ }
51882
+ if (repo.mainbranch) {
51883
+ this.output.text(` ${this.output.dim("Default branch:")} ${repo.mainbranch.name}`);
51884
+ }
51885
+ this.output.text(` ${this.output.dim("Created:")} ${this.output.formatDate(repo.created_on ?? "")}`);
51886
+ this.output.text(` ${this.output.dim("Updated:")} ${this.output.formatDate(repo.updated_on ?? "")}`);
51887
+ this.output.text("");
51888
+ this.output.text(` ${this.output.dim("URL:")} ${repo.links?.html?.href}`);
51889
+ const sshClone = Array.from(repo.links?.clone ?? []).find((c) => c.name === "ssh");
51890
+ if (sshClone?.href) {
51891
+ this.output.text(` ${this.output.dim("SSH:")} ${sshClone.href}`);
51812
51892
  }
51813
51893
  }
51814
51894
  }
@@ -51836,24 +51916,22 @@ class DeleteRepoCommand extends BaseCommand {
51836
51916
  }
51837
51917
  const repoContext = await this.contextService.requireRepoContext(contextOptions);
51838
51918
  if (!yes) {
51839
- const error = new Error(`This will permanently delete ${repoContext.workspace}/${repoContext.repoSlug}.
51919
+ throw new Error(`This will permanently delete ${repoContext.workspace}/${repoContext.repoSlug}.
51840
51920
  ` + "Use --yes to confirm deletion.");
51841
- this.output.error(error.message);
51842
- if (true) {
51843
- process.exitCode = 1;
51844
- }
51845
- throw error;
51846
51921
  }
51847
- try {
51848
- await this.repositoriesApi.repositoriesWorkspaceRepoSlugDelete({
51922
+ await this.repositoriesApi.repositoriesWorkspaceRepoSlugDelete({
51923
+ workspace: repoContext.workspace,
51924
+ repoSlug: repoContext.repoSlug
51925
+ });
51926
+ if (context.globalOptions.json) {
51927
+ this.output.json({
51928
+ success: true,
51849
51929
  workspace: repoContext.workspace,
51850
51930
  repoSlug: repoContext.repoSlug
51851
51931
  });
51852
- this.output.success(`Deleted repository ${repoContext.workspace}/${repoContext.repoSlug}`);
51853
- } catch (error) {
51854
- this.handleError(error, context);
51855
- throw error;
51932
+ return;
51856
51933
  }
51934
+ this.output.success(`Deleted repository ${repoContext.workspace}/${repoContext.repoSlug}`);
51857
51935
  }
51858
51936
  }
51859
51937
 
@@ -51872,11 +51950,7 @@ class CreatePRCommand extends BaseCommand {
51872
51950
  }
51873
51951
  async execute(options, context) {
51874
51952
  if (!options.title) {
51875
- this.output.error("Pull request title is required. Use --title option.");
51876
- if (true) {
51877
- process.exitCode = 1;
51878
- }
51879
- throw new Error("Pull request title is required");
51953
+ throw new Error("Pull request title is required. Use --title option.");
51880
51954
  }
51881
51955
  const repoContext = await this.contextService.requireRepoContext({
51882
51956
  ...context.globalOptions,
@@ -51906,21 +51980,20 @@ class CreatePRCommand extends BaseCommand {
51906
51980
  if (options.draft) {
51907
51981
  request.draft = true;
51908
51982
  }
51909
- try {
51910
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPost({
51911
- workspace: repoContext.workspace,
51912
- repoSlug: repoContext.repoSlug,
51913
- body: request
51914
- });
51915
- const pr = response.data;
51916
- const links = pr.links;
51917
- this.output.success(`Created pull request #${pr.id}`);
51918
- this.output.text(` ${source_default.dim("Title:")} ${pr.title}`);
51919
- this.output.text(` ${source_default.dim("URL:")} ${links?.html?.href}`);
51920
- } catch (error) {
51921
- this.handleError(error, context);
51922
- throw error;
51983
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPost({
51984
+ workspace: repoContext.workspace,
51985
+ repoSlug: repoContext.repoSlug,
51986
+ body: request
51987
+ });
51988
+ const pr = response.data;
51989
+ const links = pr.links;
51990
+ if (context.globalOptions.json) {
51991
+ this.output.json(pr);
51992
+ return;
51923
51993
  }
51994
+ this.output.success(`Created pull request #${pr.id}`);
51995
+ this.output.text(` ${this.output.dim("Title:")} ${pr.title}`);
51996
+ this.output.text(` ${this.output.dim("URL:")} ${links?.html?.href}`);
51924
51997
  }
51925
51998
  }
51926
51999
 
@@ -51941,34 +52014,39 @@ class ListPRsCommand extends BaseCommand {
51941
52014
  ...options
51942
52015
  });
51943
52016
  const state = options.state || "OPEN";
51944
- try {
51945
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsGet({
52017
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsGet({
52018
+ workspace: repoContext.workspace,
52019
+ repoSlug: repoContext.repoSlug,
52020
+ state
52021
+ });
52022
+ const data = response.data;
52023
+ const values = data.values ? Array.from(data.values) : [];
52024
+ if (context.globalOptions.json) {
52025
+ this.output.json({
51946
52026
  workspace: repoContext.workspace,
51947
52027
  repoSlug: repoContext.repoSlug,
51948
- state
51949
- });
51950
- const data = response.data;
51951
- const values = data.values ? Array.from(data.values) : [];
51952
- if (values.length === 0) {
51953
- this.output.text(`No ${state.toLowerCase()} pull requests found`);
51954
- return;
51955
- }
51956
- const rows = values.map((pr) => {
51957
- const title = pr.draft ? `[DRAFT] ${pr.title}` : pr.title;
51958
- const source = pr.source;
51959
- const destination = pr.destination;
51960
- return [
51961
- `#${pr.id}`,
51962
- this.truncate(title ?? "", 50),
51963
- pr.author?.display_name ?? "Unknown",
51964
- `${source?.branch?.name ?? "unknown"} \u2192 ${destination?.branch?.name ?? "unknown"}`
51965
- ];
52028
+ state,
52029
+ count: values.length,
52030
+ pullRequests: values
51966
52031
  });
51967
- this.output.table(["ID", "TITLE", "AUTHOR", "BRANCHES"], rows);
51968
- } catch (error) {
51969
- this.handleError(error, context);
51970
- throw error;
52032
+ return;
51971
52033
  }
52034
+ if (values.length === 0) {
52035
+ this.output.text(`No ${state.toLowerCase()} pull requests found`);
52036
+ return;
52037
+ }
52038
+ const rows = values.map((pr) => {
52039
+ const title = pr.draft ? `[DRAFT] ${pr.title}` : pr.title;
52040
+ const source = pr.source;
52041
+ const destination = pr.destination;
52042
+ return [
52043
+ `#${pr.id}`,
52044
+ this.truncate(title ?? "", 50),
52045
+ pr.author?.display_name ?? "Unknown",
52046
+ `${source?.branch?.name ?? "unknown"} \u2192 ${destination?.branch?.name ?? "unknown"}`
52047
+ ];
52048
+ });
52049
+ this.output.table(["ID", "TITLE", "AUTHOR", "BRANCHES"], rows);
51972
52050
  }
51973
52051
  truncate(text, maxLength) {
51974
52052
  if (text.length <= maxLength) {
@@ -51994,31 +52072,30 @@ class ViewPRCommand extends BaseCommand {
51994
52072
  ...context.globalOptions,
51995
52073
  ...options
51996
52074
  });
51997
- const prId = parseInt(options.id, 10);
51998
- try {
51999
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52000
- workspace: repoContext.workspace,
52001
- repoSlug: repoContext.repoSlug,
52002
- pullRequestId: prId
52003
- });
52004
- const pr = response.data;
52005
- this.renderHeader(pr);
52006
- this.renderDescription(pr);
52007
- this.renderBranchInfo(pr);
52008
- this.renderMetadata(pr);
52009
- this.renderReviewers(pr);
52010
- this.renderFooter(pr);
52011
- } catch (error) {
52012
- this.handleError(error, context);
52013
- throw error;
52075
+ const prId = Number.parseInt(options.id, 10);
52076
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52077
+ workspace: repoContext.workspace,
52078
+ repoSlug: repoContext.repoSlug,
52079
+ pullRequestId: prId
52080
+ });
52081
+ const pr = response.data;
52082
+ if (context.globalOptions.json) {
52083
+ this.output.json(pr);
52084
+ return;
52014
52085
  }
52086
+ this.renderHeader(pr);
52087
+ this.renderDescription(pr);
52088
+ this.renderBranchInfo(pr);
52089
+ this.renderMetadata(pr);
52090
+ this.renderReviewers(pr);
52091
+ this.renderFooter(pr);
52015
52092
  }
52016
52093
  renderHeader(pr) {
52017
52094
  const stateColor = this.getStateColor(pr.state);
52018
- const draftLabel = pr.draft ? source_default.yellow(" [DRAFT]") : "";
52095
+ const draftLabel = pr.draft ? this.output.yellow(" [DRAFT]") : "";
52019
52096
  this.output.text("");
52020
- this.output.text(`${source_default.bold(`#${pr.id}`)} ${pr.title}${draftLabel} ${stateColor(`[${pr.state}]`)}`);
52021
- this.output.text(source_default.gray("\u2500".repeat(60)));
52097
+ this.output.text(`${this.output.bold(`#${pr.id}`)} ${pr.title}${draftLabel} ${stateColor(`[${pr.state}]`)}`);
52098
+ this.output.text(this.output.gray("\u2500".repeat(60)));
52022
52099
  }
52023
52100
  renderDescription(pr) {
52024
52101
  if (pr.description) {
@@ -52029,75 +52106,75 @@ class ViewPRCommand extends BaseCommand {
52029
52106
  renderBranchInfo(pr) {
52030
52107
  const source = pr.source;
52031
52108
  const destination = pr.destination;
52032
- const sourceBranch = source_default.cyan(source?.branch?.name ?? "unknown");
52033
- const destBranch = source_default.cyan(destination?.branch?.name ?? "unknown");
52034
- const arrow = source_default.gray(" \u2192 ");
52035
- this.output.text(`${source_default.dim("Branch:")} ${sourceBranch}${arrow}${destBranch}`);
52109
+ const sourceBranch = this.output.cyan(source?.branch?.name ?? "unknown");
52110
+ const destBranch = this.output.cyan(destination?.branch?.name ?? "unknown");
52111
+ const arrow = this.output.gray(" \u2192 ");
52112
+ this.output.text(`${this.output.dim("Branch:")} ${sourceBranch}${arrow}${destBranch}`);
52036
52113
  if (source?.commit?.hash || destination?.commit?.hash) {
52037
- const sourceHash = source?.commit?.hash ? source_default.gray(source.commit.hash.slice(0, 7)) : source_default.gray("unknown");
52038
- const destHash = destination?.commit?.hash ? source_default.gray(destination.commit.hash.slice(0, 7)) : source_default.gray("unknown");
52039
- this.output.text(`${source_default.dim("Commits:")} ${sourceHash}${arrow}${destHash}`);
52114
+ const sourceHash = source?.commit?.hash ? this.output.gray(source.commit.hash.slice(0, 7)) : this.output.gray("unknown");
52115
+ const destHash = destination?.commit?.hash ? this.output.gray(destination.commit.hash.slice(0, 7)) : this.output.gray("unknown");
52116
+ this.output.text(`${this.output.dim("Commits:")} ${sourceHash}${arrow}${destHash}`);
52040
52117
  }
52041
52118
  }
52042
52119
  renderMetadata(pr) {
52043
- this.output.text(`${source_default.dim("Author:")} ${pr.author?.display_name ?? "Unknown"}`);
52120
+ this.output.text(`${this.output.dim("Author:")} ${pr.author?.display_name ?? "Unknown"}`);
52044
52121
  if (pr.closed_by) {
52045
52122
  const action = pr.state === "MERGED" ? "Merged" : "Closed";
52046
- this.output.text(`${source_default.dim(action + ":")} ${pr.closed_by.display_name}`);
52123
+ this.output.text(`${this.output.dim(action + ":")} ${pr.closed_by.display_name}`);
52047
52124
  }
52048
52125
  const createdOn = pr.created_on ? this.output.formatDate(pr.created_on) : "Unknown";
52049
52126
  const updatedOn = pr.updated_on ? this.output.formatDate(pr.updated_on) : "Unknown";
52050
- this.output.text(`${source_default.dim("Created:")} ${createdOn}`);
52051
- this.output.text(`${source_default.dim("Updated:")} ${updatedOn}`);
52127
+ this.output.text(`${this.output.dim("Created:")} ${createdOn}`);
52128
+ this.output.text(`${this.output.dim("Updated:")} ${updatedOn}`);
52052
52129
  const mergeCommit = pr.merge_commit;
52053
52130
  if (mergeCommit?.hash) {
52054
- this.output.text(`${source_default.dim("Merge:")} ${source_default.magenta(mergeCommit.hash.slice(0, 7))}`);
52131
+ this.output.text(`${this.output.dim("Merge:")} ${this.output.magenta(mergeCommit.hash.slice(0, 7))}`);
52055
52132
  }
52056
- const closeBranchIndicator = pr.close_source_branch ? source_default.green("\u2713") : source_default.gray("\u2717");
52057
- this.output.text(`${source_default.dim("Close Src:")} ${closeBranchIndicator} ${source_default.gray("(close source branch on merge)")}`);
52058
- this.output.text(`${source_default.dim("Activity:")} ${pr.comment_count ?? 0} comments \xB7 ${pr.task_count ?? 0} tasks`);
52133
+ const closeBranchIndicator = pr.close_source_branch ? this.output.green("\u2713") : this.output.gray("\u2717");
52134
+ this.output.text(`${this.output.dim("Close Src:")} ${closeBranchIndicator} ${this.output.gray("(close source branch on merge)")}`);
52135
+ this.output.text(`${this.output.dim("Activity:")} ${pr.comment_count ?? 0} comments \xB7 ${pr.task_count ?? 0} tasks`);
52059
52136
  }
52060
52137
  renderReviewers(pr) {
52061
52138
  const participants = pr.participants ? Array.from(pr.participants) : [];
52062
52139
  const reviewers = participants.filter((p) => p.role === "REVIEWER");
52063
52140
  if (reviewers.length === 0) {
52064
52141
  this.output.text("");
52065
- this.output.text(source_default.gray("No reviewers assigned"));
52142
+ this.output.text(this.output.gray("No reviewers assigned"));
52066
52143
  return;
52067
52144
  }
52068
52145
  this.output.text("");
52069
- this.output.text(source_default.dim("Reviewers:"));
52146
+ this.output.text(this.output.dim("Reviewers:"));
52070
52147
  for (const reviewer of reviewers) {
52071
52148
  const status = this.getReviewerStatus(reviewer);
52072
- this.output.text(` ${status.icon} ${reviewer.user?.display_name ?? "Unknown"} ${source_default.gray(status.label)}`);
52149
+ this.output.text(` ${status.icon} ${reviewer.user?.display_name ?? "Unknown"} ${this.output.gray(status.label)}`);
52073
52150
  }
52074
52151
  }
52075
52152
  getReviewerStatus(reviewer) {
52076
52153
  if (reviewer.approved) {
52077
- return { icon: source_default.green("\u2713"), label: "approved" };
52154
+ return { icon: this.output.green("\u2713"), label: "approved" };
52078
52155
  }
52079
52156
  if (reviewer.state === "changes_requested") {
52080
- return { icon: source_default.red("\u2717"), label: "changes requested" };
52157
+ return { icon: this.output.red("\u2717"), label: "changes requested" };
52081
52158
  }
52082
- return { icon: source_default.yellow("\u25CB"), label: "pending" };
52159
+ return { icon: this.output.yellow("\u25CB"), label: "pending" };
52083
52160
  }
52084
52161
  renderFooter(pr) {
52085
52162
  const links = pr.links;
52086
52163
  this.output.text("");
52087
- this.output.text(source_default.gray("\u2500".repeat(60)));
52088
- this.output.text(`${source_default.dim("URL:")} ${source_default.blue.underline(links?.html?.href ?? "")}`);
52164
+ this.output.text(this.output.gray("\u2500".repeat(60)));
52165
+ this.output.text(`${this.output.dim("URL:")} ${this.output.underline(this.output.blue(links?.html?.href ?? ""))}`);
52089
52166
  this.output.text("");
52090
52167
  }
52091
52168
  getStateColor(state) {
52092
52169
  switch (state) {
52093
52170
  case "OPEN":
52094
- return source_default.green;
52171
+ return (text) => this.output.green(text);
52095
52172
  case "MERGED":
52096
- return source_default.magenta;
52173
+ return (text) => this.output.magenta(text);
52097
52174
  case "DECLINED":
52098
- return source_default.red;
52175
+ return (text) => this.output.red(text);
52099
52176
  default:
52100
- return source_default.gray;
52177
+ return (text) => this.output.gray(text);
52101
52178
  }
52102
52179
  }
52103
52180
  }
@@ -52123,7 +52200,7 @@ class EditPRCommand extends BaseCommand {
52123
52200
  });
52124
52201
  let prId;
52125
52202
  if (options.id) {
52126
- prId = parseInt(options.id, 10);
52203
+ prId = Number.parseInt(options.id, 10);
52127
52204
  } else {
52128
52205
  const currentBranch = await this.gitService.getCurrentBranch();
52129
52206
  const prsResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsGet({
@@ -52132,17 +52209,12 @@ class EditPRCommand extends BaseCommand {
52132
52209
  state: "OPEN"
52133
52210
  });
52134
52211
  const values = prsResponse.data.values ? Array.from(prsResponse.data.values) : [];
52135
- const matchingPR = values.find((pr) => {
52136
- const source = pr.source;
52212
+ const matchingPR = values.find((pr2) => {
52213
+ const source = pr2.source;
52137
52214
  return source?.branch?.name === currentBranch;
52138
52215
  });
52139
52216
  if (!matchingPR) {
52140
- const error = new Error(`No open pull request found for current branch '${currentBranch}'. Specify a PR ID explicitly.`);
52141
- this.output.error(error.message);
52142
- if (true) {
52143
- process.exitCode = 1;
52144
- }
52145
- throw error;
52217
+ throw new Error(`No open pull request found for current branch '${currentBranch}'. Specify a PR ID explicitly.`);
52146
52218
  }
52147
52219
  prId = matchingPR.id;
52148
52220
  }
@@ -52151,21 +52223,11 @@ class EditPRCommand extends BaseCommand {
52151
52223
  try {
52152
52224
  body = fs.readFileSync(options.bodyFile, "utf-8");
52153
52225
  } catch (err) {
52154
- const error = new Error(`Failed to read file '${options.bodyFile}': ${err instanceof Error ? err.message : "Unknown error"}`);
52155
- this.output.error(error.message);
52156
- if (true) {
52157
- process.exitCode = 1;
52158
- }
52159
- throw error;
52226
+ throw new Error(`Failed to read file '${options.bodyFile}': ${err instanceof Error ? err.message : "Unknown error"}`);
52160
52227
  }
52161
52228
  }
52162
52229
  if (!options.title && !body) {
52163
- const error = new Error("At least one of --title or --body (or --body-file) is required.");
52164
- this.output.error(error.message);
52165
- if (true) {
52166
- process.exitCode = 1;
52167
- }
52168
- throw error;
52230
+ throw new Error("At least one of --title or --body (or --body-file) is required.");
52169
52231
  }
52170
52232
  const request = {
52171
52233
  type: "pullrequest"
@@ -52176,26 +52238,25 @@ class EditPRCommand extends BaseCommand {
52176
52238
  if (body) {
52177
52239
  request.description = body;
52178
52240
  }
52179
- try {
52180
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdPut({
52181
- workspace: repoContext.workspace,
52182
- repoSlug: repoContext.repoSlug,
52183
- pullRequestId: prId,
52184
- body: request
52185
- });
52186
- const pr = response.data;
52187
- const links = pr.links;
52188
- this.output.success(`Updated pull request #${pr.id}`);
52189
- this.output.text(` ${source_default.dim("Title:")} ${pr.title}`);
52190
- if (pr.description) {
52191
- const truncatedDesc = pr.description.length > 100 ? pr.description.substring(0, 100) + "..." : pr.description;
52192
- this.output.text(` ${source_default.dim("Description:")} ${truncatedDesc}`);
52193
- }
52194
- this.output.text(` ${source_default.dim("URL:")} ${links?.html?.href}`);
52195
- } catch (error) {
52196
- this.handleError(error, context);
52197
- throw error;
52241
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdPut({
52242
+ workspace: repoContext.workspace,
52243
+ repoSlug: repoContext.repoSlug,
52244
+ pullRequestId: prId,
52245
+ body: request
52246
+ });
52247
+ const pr = response.data;
52248
+ const links = pr.links;
52249
+ if (context.globalOptions.json) {
52250
+ this.output.json(pr);
52251
+ return;
52198
52252
  }
52253
+ this.output.success(`Updated pull request #${pr.id}`);
52254
+ this.output.text(` ${this.output.dim("Title:")} ${pr.title}`);
52255
+ if (pr.description) {
52256
+ const truncatedDesc = pr.description.length > 100 ? pr.description.substring(0, 100) + "..." : pr.description;
52257
+ this.output.text(` ${this.output.dim("Description:")} ${truncatedDesc}`);
52258
+ }
52259
+ this.output.text(` ${this.output.dim("URL:")} ${links?.html?.href}`);
52199
52260
  }
52200
52261
  }
52201
52262
 
@@ -52215,7 +52276,7 @@ class MergePRCommand extends BaseCommand {
52215
52276
  ...context.globalOptions,
52216
52277
  ...options
52217
52278
  });
52218
- const prId = parseInt(options.id, 10);
52279
+ const prId = Number.parseInt(options.id, 10);
52219
52280
  const request = {
52220
52281
  type: "pullrequest_merge_parameters"
52221
52282
  };
@@ -52228,19 +52289,22 @@ class MergePRCommand extends BaseCommand {
52228
52289
  if (options.strategy) {
52229
52290
  request.merge_strategy = options.strategy;
52230
52291
  }
52231
- try {
52232
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdMergePost({
52233
- workspace: repoContext.workspace,
52234
- repoSlug: repoContext.repoSlug,
52292
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdMergePost({
52293
+ workspace: repoContext.workspace,
52294
+ repoSlug: repoContext.repoSlug,
52295
+ pullRequestId: prId,
52296
+ body: request
52297
+ });
52298
+ const pr = response.data;
52299
+ if (context.globalOptions.json) {
52300
+ this.output.json({
52301
+ success: true,
52235
52302
  pullRequestId: prId,
52236
- body: request
52303
+ pullRequest: pr
52237
52304
  });
52238
- const pr = response.data;
52239
- this.output.success(`Merged pull request #${prId}: ${pr.title}`);
52240
- } catch (error) {
52241
- this.handleError(error, context);
52242
- throw error;
52305
+ return;
52243
52306
  }
52307
+ this.output.success(`Merged pull request #${prId}: ${pr.title}`);
52244
52308
  }
52245
52309
  }
52246
52310
 
@@ -52260,18 +52324,20 @@ class ApprovePRCommand extends BaseCommand {
52260
52324
  ...context.globalOptions,
52261
52325
  ...options
52262
52326
  });
52263
- const prId = parseInt(options.id, 10);
52264
- try {
52265
- await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdApprovePost({
52266
- workspace: repoContext.workspace,
52267
- repoSlug: repoContext.repoSlug,
52327
+ const prId = Number.parseInt(options.id, 10);
52328
+ await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdApprovePost({
52329
+ workspace: repoContext.workspace,
52330
+ repoSlug: repoContext.repoSlug,
52331
+ pullRequestId: prId
52332
+ });
52333
+ if (context.globalOptions.json) {
52334
+ this.output.json({
52335
+ success: true,
52268
52336
  pullRequestId: prId
52269
52337
  });
52270
- this.output.success(`Approved pull request #${prId}`);
52271
- } catch (error) {
52272
- this.handleError(error, context);
52273
- throw error;
52338
+ return;
52274
52339
  }
52340
+ this.output.success(`Approved pull request #${prId}`);
52275
52341
  }
52276
52342
  }
52277
52343
 
@@ -52291,19 +52357,22 @@ class DeclinePRCommand extends BaseCommand {
52291
52357
  ...context.globalOptions,
52292
52358
  ...options
52293
52359
  });
52294
- const prId = parseInt(options.id, 10);
52295
- try {
52296
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdDeclinePost({
52297
- workspace: repoContext.workspace,
52298
- repoSlug: repoContext.repoSlug,
52299
- pullRequestId: prId
52360
+ const prId = Number.parseInt(options.id, 10);
52361
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdDeclinePost({
52362
+ workspace: repoContext.workspace,
52363
+ repoSlug: repoContext.repoSlug,
52364
+ pullRequestId: prId
52365
+ });
52366
+ const pr = response.data;
52367
+ if (context.globalOptions.json) {
52368
+ this.output.json({
52369
+ success: true,
52370
+ pullRequestId: prId,
52371
+ pullRequest: pr
52300
52372
  });
52301
- const pr = response.data;
52302
- this.output.success(`Declined pull request #${prId}: ${pr.title}`);
52303
- } catch (error) {
52304
- this.handleError(error, context);
52305
- throw error;
52373
+ return;
52306
52374
  }
52375
+ this.output.success(`Declined pull request #${prId}: ${pr.title}`);
52307
52376
  }
52308
52377
  }
52309
52378
 
@@ -52323,24 +52392,27 @@ class ReadyPRCommand extends BaseCommand {
52323
52392
  ...context.globalOptions,
52324
52393
  ...options
52325
52394
  });
52326
- const prId = parseInt(options.id, 10);
52327
- try {
52328
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdPut({
52329
- workspace: repoContext.workspace,
52330
- repoSlug: repoContext.repoSlug,
52395
+ const prId = Number.parseInt(options.id, 10);
52396
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdPut({
52397
+ workspace: repoContext.workspace,
52398
+ repoSlug: repoContext.repoSlug,
52399
+ pullRequestId: prId,
52400
+ body: {
52401
+ type: "pullrequest",
52402
+ draft: false
52403
+ }
52404
+ });
52405
+ const pr = response.data;
52406
+ if (context.globalOptions.json) {
52407
+ this.output.json({
52408
+ success: true,
52331
52409
  pullRequestId: prId,
52332
- body: {
52333
- type: "pullrequest",
52334
- draft: false
52335
- }
52410
+ pullRequest: pr
52336
52411
  });
52337
- const pr = response.data;
52338
- this.output.success(`Marked pull request #${prId} as ready for review`);
52339
- this.output.text(` ${pr.title}`);
52340
- } catch (error) {
52341
- this.handleError(error, context);
52342
- throw error;
52412
+ return;
52343
52413
  }
52414
+ this.output.success(`Marked pull request #${prId} as ready for review`);
52415
+ this.output.text(` ${pr.title}`);
52344
52416
  }
52345
52417
  }
52346
52418
 
@@ -52362,32 +52434,48 @@ class CheckoutPRCommand extends BaseCommand {
52362
52434
  ...context.globalOptions,
52363
52435
  ...options
52364
52436
  });
52365
- const prId = parseInt(options.id, 10);
52437
+ const prId = Number.parseInt(options.id, 10);
52438
+ const prResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52439
+ workspace: repoContext.workspace,
52440
+ repoSlug: repoContext.repoSlug,
52441
+ pullRequestId: prId
52442
+ });
52443
+ const pr = prResponse.data;
52444
+ const branchName = pr.source?.branch?.name;
52445
+ const localBranchName = `pr-${prId}`;
52446
+ if (!branchName) {
52447
+ throw new Error("Pull request source branch not found");
52448
+ }
52449
+ await this.gitService.fetch();
52450
+ let checkedOutBranch;
52366
52451
  try {
52367
- const prResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52368
- workspace: repoContext.workspace,
52369
- repoSlug: repoContext.repoSlug,
52370
- pullRequestId: prId
52371
- });
52372
- const pr = prResponse.data;
52373
- const branchName = pr.source?.branch?.name;
52374
- const localBranchName = `pr-${prId}`;
52375
- if (!branchName) {
52376
- throw new Error("Pull request source branch not found");
52452
+ await this.gitService.checkout(branchName);
52453
+ checkedOutBranch = branchName;
52454
+ if (context.globalOptions.json) {
52455
+ this.output.json({
52456
+ success: true,
52457
+ pullRequestId: prId,
52458
+ branch: checkedOutBranch,
52459
+ pullRequest: pr
52460
+ });
52461
+ return;
52377
52462
  }
52378
- await this.gitService.fetch();
52379
- try {
52380
- await this.gitService.checkout(branchName);
52381
- this.output.success(`Checked out PR #${prId} as '${branchName}'`);
52382
- } catch {
52383
- await this.gitService.checkoutNewBranch(localBranchName, `origin/${branchName}`);
52384
- this.output.success(`Checked out PR #${prId} as '${localBranchName}'`);
52463
+ this.output.success(`Checked out PR #${prId} as '${branchName}'`);
52464
+ } catch {
52465
+ await this.gitService.checkoutNewBranch(localBranchName, `origin/${branchName}`);
52466
+ checkedOutBranch = localBranchName;
52467
+ if (context.globalOptions.json) {
52468
+ this.output.json({
52469
+ success: true,
52470
+ pullRequestId: prId,
52471
+ branch: checkedOutBranch,
52472
+ pullRequest: pr
52473
+ });
52474
+ return;
52385
52475
  }
52386
- this.output.text(` Title: ${pr.title}`);
52387
- } catch (error) {
52388
- this.handleError(error, context);
52389
- throw error;
52476
+ this.output.success(`Checked out PR #${prId} as '${localBranchName}'`);
52390
52477
  }
52478
+ this.output.text(` Title: ${pr.title}`);
52391
52479
  }
52392
52480
  }
52393
52481
 
@@ -52415,9 +52503,9 @@ class DiffPRCommand extends BaseCommand {
52415
52503
  });
52416
52504
  let prId;
52417
52505
  if (options.id) {
52418
- prId = parseInt(options.id, 10);
52419
- if (isNaN(prId)) {
52420
- throw new Error("Invalid PR ID");
52506
+ prId = Number.parseInt(options.id, 10);
52507
+ if (Number.isNaN(prId)) {
52508
+ throw new TypeError("Invalid PR ID");
52421
52509
  }
52422
52510
  } else {
52423
52511
  const currentBranch = await this.gitService.getCurrentBranch();
@@ -52433,34 +52521,58 @@ class DiffPRCommand extends BaseCommand {
52433
52521
  prId = pr.id;
52434
52522
  }
52435
52523
  if (options.web) {
52436
- const prResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52437
- workspace: repoContext.workspace,
52438
- repoSlug: repoContext.repoSlug,
52439
- pullRequestId: prId
52440
- });
52441
- const diffUrl = prResponse.data.links?.diff?.href;
52442
- if (!diffUrl) {
52443
- throw new Error("Could not get diff URL");
52524
+ const webUrl = await this.getWebDiffUrl(repoContext.workspace, repoContext.repoSlug, prId);
52525
+ if (context.globalOptions.json) {
52526
+ this.output.json({
52527
+ workspace: repoContext.workspace,
52528
+ repoSlug: repoContext.repoSlug,
52529
+ pullRequestId: prId,
52530
+ mode: "web",
52531
+ url: webUrl
52532
+ });
52533
+ return;
52444
52534
  }
52445
- const webUrl = diffUrl.replace(/api\.bitbucket\.org\/2\.0\/repositories\/(.*?)\/pullrequests\/(\d+)\/diff/, "bitbucket.org/$1/pull-requests/$2/diff");
52446
- await this.openInBrowser(webUrl, context);
52535
+ await this.openInBrowser(webUrl);
52447
52536
  return;
52448
52537
  }
52449
52538
  if (options.stat) {
52450
- await this.showStat(repoContext.workspace, repoContext.repoSlug, prId, context);
52539
+ const statResult = await this.showStat(repoContext.workspace, repoContext.repoSlug, prId, Boolean(context.globalOptions.json));
52540
+ if (context.globalOptions.json) {
52541
+ this.output.json({
52542
+ workspace: repoContext.workspace,
52543
+ repoSlug: repoContext.repoSlug,
52544
+ pullRequestId: prId,
52545
+ mode: "stat",
52546
+ ...statResult
52547
+ });
52548
+ }
52451
52549
  return;
52452
52550
  }
52453
52551
  if (options.nameOnly) {
52454
- await this.showNameOnly(repoContext.workspace, repoContext.repoSlug, prId, context);
52552
+ const files = await this.showNameOnly(repoContext.workspace, repoContext.repoSlug, prId, Boolean(context.globalOptions.json));
52553
+ if (context.globalOptions.json) {
52554
+ this.output.json({
52555
+ workspace: repoContext.workspace,
52556
+ repoSlug: repoContext.repoSlug,
52557
+ pullRequestId: prId,
52558
+ mode: "name-only",
52559
+ files
52560
+ });
52561
+ }
52455
52562
  return;
52456
52563
  }
52457
- await this.showDiff(repoContext.workspace, repoContext.repoSlug, prId, options, context);
52458
- }
52459
- async openInBrowser(url2, context) {
52564
+ const diff = await this.showDiff(repoContext.workspace, repoContext.repoSlug, prId, options, Boolean(context.globalOptions.json));
52460
52565
  if (context.globalOptions.json) {
52461
- this.output.json({ url: url2 });
52462
- return;
52566
+ this.output.json({
52567
+ workspace: repoContext.workspace,
52568
+ repoSlug: repoContext.repoSlug,
52569
+ pullRequestId: prId,
52570
+ mode: "diff",
52571
+ diff
52572
+ });
52463
52573
  }
52574
+ }
52575
+ async openInBrowser(url2) {
52464
52576
  this.output.info(`Opening ${url2} in your browser...`);
52465
52577
  const platform = process.platform;
52466
52578
  let command;
@@ -52473,7 +52585,19 @@ class DiffPRCommand extends BaseCommand {
52473
52585
  }
52474
52586
  await execAsync(command);
52475
52587
  }
52476
- async showStat(workspace, repoSlug, prId, context) {
52588
+ async getWebDiffUrl(workspace, repoSlug, prId) {
52589
+ const prResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52590
+ workspace,
52591
+ repoSlug,
52592
+ pullRequestId: prId
52593
+ });
52594
+ const diffUrl = prResponse.data.links?.diff?.href;
52595
+ if (!diffUrl) {
52596
+ throw new Error("Could not get diff URL");
52597
+ }
52598
+ return diffUrl.replace(/api\.bitbucket\.org\/2\.0\/repositories\/(.*?)\/pullrequests\/(\d+)\/diff/, "bitbucket.org/$1/pull-requests/$2/diff");
52599
+ }
52600
+ async showStat(workspace, repoSlug, prId, useJson) {
52477
52601
  const diffstatResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdDiffstatGet({
52478
52602
  workspace,
52479
52603
  repoSlug,
@@ -52491,21 +52615,35 @@ class DiffPRCommand extends BaseCommand {
52491
52615
  const totalAdditions = files.reduce((sum, f) => sum + f.additions, 0);
52492
52616
  const totalDeletions = files.reduce((sum, f) => sum + f.deletions, 0);
52493
52617
  const filesChanged = files.length;
52618
+ if (useJson) {
52619
+ return {
52620
+ files,
52621
+ filesChanged,
52622
+ totalAdditions,
52623
+ totalDeletions
52624
+ };
52625
+ }
52494
52626
  for (const file of files) {
52495
- const additions = file.additions > 0 ? source_default.green(`+${file.additions}`) : "";
52496
- const deletions = file.deletions > 0 ? source_default.red(`-${file.deletions}`) : "";
52627
+ const additions = file.additions > 0 ? this.output.green(`+${file.additions}`) : "";
52628
+ const deletions = file.deletions > 0 ? this.output.red(`-${file.deletions}`) : "";
52497
52629
  const stats = [additions, deletions].filter(Boolean).join(" ");
52498
52630
  this.output.text(`${file.path} ${stats ? `| ${stats}` : ""}`);
52499
52631
  }
52500
52632
  this.output.text("");
52501
52633
  const summary = [
52502
- `${filesChanged} file${filesChanged !== 1 ? "s" : ""} changed`,
52503
- totalAdditions > 0 ? source_default.green(`${totalAdditions} insertion${totalAdditions !== 1 ? "s" : ""}(+)`) : null,
52504
- totalDeletions > 0 ? source_default.red(`${totalDeletions} deletion${totalDeletions !== 1 ? "s" : ""}(-)`) : null
52634
+ `${filesChanged} file${filesChanged === 1 ? "" : "s"} changed`,
52635
+ totalAdditions > 0 ? this.output.green(`${totalAdditions} insertion${totalAdditions === 1 ? "" : "s"}(+)`) : null,
52636
+ totalDeletions > 0 ? this.output.red(`${totalDeletions} deletion${totalDeletions === 1 ? "" : "s"}(-)`) : null
52505
52637
  ].filter(Boolean).join(", ");
52506
52638
  this.output.text(summary);
52639
+ return {
52640
+ files,
52641
+ filesChanged,
52642
+ totalAdditions,
52643
+ totalDeletions
52644
+ };
52507
52645
  }
52508
- async showNameOnly(workspace, repoSlug, prId, context) {
52646
+ async showNameOnly(workspace, repoSlug, prId, useJson) {
52509
52647
  const diffstatResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdDiffstatGet({
52510
52648
  workspace,
52511
52649
  repoSlug,
@@ -52513,11 +52651,15 @@ class DiffPRCommand extends BaseCommand {
52513
52651
  });
52514
52652
  const diffstat = diffstatResponse.data;
52515
52653
  const fileNames = Array.from(diffstat.values ?? []).map((file) => file.new?.path || file.old?.path || "unknown");
52654
+ if (useJson) {
52655
+ return fileNames;
52656
+ }
52516
52657
  for (const fileName of fileNames) {
52517
52658
  this.output.text(fileName);
52518
52659
  }
52660
+ return fileNames;
52519
52661
  }
52520
- async showDiff(workspace, repoSlug, prId, options, context) {
52662
+ async showDiff(workspace, repoSlug, prId, options, useJson) {
52521
52663
  const diffResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdDiffGet({
52522
52664
  workspace,
52523
52665
  repoSlug,
@@ -52525,8 +52667,12 @@ class DiffPRCommand extends BaseCommand {
52525
52667
  });
52526
52668
  const diff = diffResponse.data;
52527
52669
  const shouldColorize = this.shouldColorize(options.color);
52670
+ if (useJson) {
52671
+ return String(diff);
52672
+ }
52528
52673
  const colorizedDiff = shouldColorize ? this.colorizeDiff(String(diff)) : String(diff);
52529
52674
  this.output.text(colorizedDiff);
52675
+ return String(diff);
52530
52676
  }
52531
52677
  shouldColorize(colorOption) {
52532
52678
  if (!colorOption || colorOption === "auto") {
@@ -52539,15 +52685,15 @@ class DiffPRCommand extends BaseCommand {
52539
52685
  `);
52540
52686
  return lines.map((line) => {
52541
52687
  if (line.startsWith("+") && !line.startsWith("+++")) {
52542
- return source_default.green(line);
52688
+ return this.output.green(line);
52543
52689
  } else if (line.startsWith("-") && !line.startsWith("---")) {
52544
- return source_default.red(line);
52690
+ return this.output.red(line);
52545
52691
  } else if (line.startsWith("@@")) {
52546
- return source_default.cyan(line);
52692
+ return this.output.cyan(line);
52547
52693
  } else if (line.startsWith("diff --git")) {
52548
- return source_default.bold(line);
52694
+ return this.output.bold(line);
52549
52695
  } else if (line.startsWith("index ") || line.startsWith("---") || line.startsWith("+++")) {
52550
- return source_default.dim(line);
52696
+ return this.output.dim(line);
52551
52697
  }
52552
52698
  return line;
52553
52699
  }).join(`
@@ -52571,40 +52717,47 @@ class ActivityPRCommand extends BaseCommand {
52571
52717
  ...context.globalOptions,
52572
52718
  ...options
52573
52719
  });
52574
- const prId = parseInt(options.id, 10);
52575
- const limit = options.limit ? parseInt(options.limit, 10) : 25;
52576
- try {
52577
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdActivityGet({
52720
+ const prId = Number.parseInt(options.id, 10);
52721
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdActivityGet({
52722
+ workspace: repoContext.workspace,
52723
+ repoSlug: repoContext.repoSlug,
52724
+ pullRequestId: prId
52725
+ });
52726
+ const data = response.data;
52727
+ const values = data?.values ? Array.from(data.values) : [];
52728
+ const filterTypes = this.parseTypeFilter(options.type);
52729
+ const activities = filterTypes.length > 0 ? values.filter((activity) => filterTypes.includes(this.getActivityType(activity))) : values;
52730
+ if (context.globalOptions.json) {
52731
+ this.output.json({
52578
52732
  workspace: repoContext.workspace,
52579
52733
  repoSlug: repoContext.repoSlug,
52580
- pullRequestId: prId
52734
+ pullRequestId: prId,
52735
+ filters: {
52736
+ types: filterTypes
52737
+ },
52738
+ count: activities.length,
52739
+ activities
52581
52740
  });
52582
- const data = response.data;
52583
- const values = data?.values ? Array.from(data.values) : [];
52584
- const filterTypes = this.parseTypeFilter(options.type);
52585
- const activities = filterTypes.length > 0 ? values.filter((activity) => filterTypes.includes(this.getActivityType(activity))) : values;
52586
- if (activities.length === 0) {
52587
- if (filterTypes.length > 0) {
52588
- this.output.info("No activity entries matched the requested filter");
52589
- } else {
52590
- this.output.info("No activity found on this pull request");
52591
- }
52592
- return;
52741
+ return;
52742
+ }
52743
+ if (activities.length === 0) {
52744
+ if (filterTypes.length > 0) {
52745
+ this.output.info("No activity entries matched the requested filter");
52746
+ } else {
52747
+ this.output.info("No activity found on this pull request");
52593
52748
  }
52594
- const rows = activities.map((activity) => {
52595
- const activityType = this.getActivityType(activity);
52596
- return [
52597
- activityType.toUpperCase(),
52598
- this.getActorName(activity),
52599
- this.formatActivityDate(activity),
52600
- this.buildActivityDetails(activity, activityType)
52601
- ];
52602
- });
52603
- this.output.table(["TYPE", "ACTOR", "DATE", "DETAILS"], rows);
52604
- } catch (error) {
52605
- this.handleError(error, context);
52606
- throw error;
52749
+ return;
52607
52750
  }
52751
+ const rows = activities.map((activity) => {
52752
+ const activityType = this.getActivityType(activity);
52753
+ return [
52754
+ activityType.toUpperCase(),
52755
+ this.getActorName(activity),
52756
+ this.formatActivityDate(activity),
52757
+ this.buildActivityDetails(activity, activityType)
52758
+ ];
52759
+ });
52760
+ this.output.table(["TYPE", "ACTOR", "DATE", "DETAILS"], rows);
52608
52761
  }
52609
52762
  parseTypeFilter(typeOption) {
52610
52763
  if (!typeOption) {
@@ -52717,24 +52870,27 @@ class CommentPRCommand extends BaseCommand {
52717
52870
  ...context.globalOptions,
52718
52871
  ...options
52719
52872
  });
52720
- const prId = parseInt(options.id, 10);
52721
- try {
52722
- await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsPost({
52723
- workspace: repoContext.workspace,
52724
- repoSlug: repoContext.repoSlug,
52725
- pullRequestId: prId,
52726
- body: {
52727
- type: "pullrequest_comment",
52728
- content: {
52729
- raw: options.message
52730
- }
52873
+ const prId = Number.parseInt(options.id, 10);
52874
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsPost({
52875
+ workspace: repoContext.workspace,
52876
+ repoSlug: repoContext.repoSlug,
52877
+ pullRequestId: prId,
52878
+ body: {
52879
+ type: "pullrequest_comment",
52880
+ content: {
52881
+ raw: options.message
52731
52882
  }
52883
+ }
52884
+ });
52885
+ if (context.globalOptions.json) {
52886
+ this.output.json({
52887
+ success: true,
52888
+ pullRequestId: prId,
52889
+ comment: response.data
52732
52890
  });
52733
- this.output.success(`Added comment to pull request #${prId}`);
52734
- } catch (error) {
52735
- this.handleError(error, context);
52736
- throw error;
52891
+ return;
52737
52892
  }
52893
+ this.output.success(`Added comment to pull request #${prId}`);
52738
52894
  }
52739
52895
  }
52740
52896
 
@@ -52754,34 +52910,36 @@ class ListCommentsPRCommand extends BaseCommand {
52754
52910
  ...context.globalOptions,
52755
52911
  ...options
52756
52912
  });
52757
- const prId = parseInt(options.id, 10);
52758
- const limit = options.limit ? parseInt(options.limit, 10) : 25;
52759
- try {
52760
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsGet({
52761
- workspace: repoContext.workspace,
52762
- repoSlug: repoContext.repoSlug,
52763
- pullRequestId: prId
52764
- });
52765
- const data = response.data;
52766
- const values = data.values ? Array.from(data.values) : [];
52767
- if (values.length === 0) {
52768
- this.output.info("No comments found on this pull request");
52769
- return;
52770
- }
52771
- const rows = values.map((comment) => {
52772
- const content = comment.content?.raw ?? "";
52773
- return [
52774
- comment.id?.toString() ?? "",
52775
- comment.user?.nickname ?? comment.user?.display_name ?? "Unknown",
52776
- comment.deleted ? "[deleted]" : options.truncate === false ? content : content.slice(0, 60) + (content.length > 60 ? "..." : ""),
52777
- this.output.formatDate(comment.created_on ?? "")
52778
- ];
52913
+ const prId = Number.parseInt(options.id, 10);
52914
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsGet({
52915
+ workspace: repoContext.workspace,
52916
+ repoSlug: repoContext.repoSlug,
52917
+ pullRequestId: prId
52918
+ });
52919
+ const data = response.data;
52920
+ const values = data.values ? Array.from(data.values) : [];
52921
+ if (context.globalOptions.json) {
52922
+ this.output.json({
52923
+ pullRequestId: prId,
52924
+ count: values.length,
52925
+ comments: values
52779
52926
  });
52780
- this.output.table(["ID", "Author", "Content", "Date"], rows);
52781
- } catch (error) {
52782
- this.handleError(error, context);
52783
- throw error;
52927
+ return;
52928
+ }
52929
+ if (values.length === 0) {
52930
+ this.output.info("No comments found on this pull request");
52931
+ return;
52784
52932
  }
52933
+ const rows = values.map((comment) => {
52934
+ const content = comment.content?.raw ?? "";
52935
+ return [
52936
+ comment.id?.toString() ?? "",
52937
+ comment.user?.nickname ?? comment.user?.display_name ?? "Unknown",
52938
+ comment.deleted ? "[deleted]" : options.truncate === false ? content : content.slice(0, 60) + (content.length > 60 ? "..." : ""),
52939
+ this.output.formatDate(comment.created_on ?? "")
52940
+ ];
52941
+ });
52942
+ this.output.table(["ID", "Author", "Content", "Date"], rows);
52785
52943
  }
52786
52944
  }
52787
52945
 
@@ -52801,26 +52959,30 @@ class EditCommentPRCommand extends BaseCommand {
52801
52959
  ...context.globalOptions,
52802
52960
  ...options
52803
52961
  });
52804
- const prId = parseInt(options.prId, 10);
52805
- const commentId = parseInt(options.commentId, 10);
52806
- try {
52807
- await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsCommentIdPut({
52808
- workspace: repoContext.workspace,
52809
- repoSlug: repoContext.repoSlug,
52962
+ const prId = Number.parseInt(options.prId, 10);
52963
+ const commentId = Number.parseInt(options.commentId, 10);
52964
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsCommentIdPut({
52965
+ workspace: repoContext.workspace,
52966
+ repoSlug: repoContext.repoSlug,
52967
+ pullRequestId: prId,
52968
+ commentId,
52969
+ body: {
52970
+ type: "pullrequest_comment",
52971
+ content: {
52972
+ raw: options.message
52973
+ }
52974
+ }
52975
+ });
52976
+ if (context.globalOptions.json) {
52977
+ this.output.json({
52978
+ success: true,
52810
52979
  pullRequestId: prId,
52811
52980
  commentId,
52812
- body: {
52813
- type: "pullrequest_comment",
52814
- content: {
52815
- raw: options.message
52816
- }
52817
- }
52981
+ comment: response.data
52818
52982
  });
52819
- this.output.success(`Updated comment #${commentId}`);
52820
- } catch (error) {
52821
- this.handleError(error, context);
52822
- throw error;
52983
+ return;
52823
52984
  }
52985
+ this.output.success(`Updated comment #${commentId} on PR #${prId}`);
52824
52986
  }
52825
52987
  }
52826
52988
 
@@ -52840,20 +53002,23 @@ class DeleteCommentPRCommand extends BaseCommand {
52840
53002
  ...context.globalOptions,
52841
53003
  ...options
52842
53004
  });
52843
- const prId = parseInt(options.prId, 10);
52844
- const commentId = parseInt(options.commentId, 10);
52845
- try {
52846
- await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsCommentIdDelete({
52847
- workspace: repoContext.workspace,
52848
- repoSlug: repoContext.repoSlug,
53005
+ const prId = Number.parseInt(options.prId, 10);
53006
+ const commentId = Number.parseInt(options.commentId, 10);
53007
+ await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsCommentIdDelete({
53008
+ workspace: repoContext.workspace,
53009
+ repoSlug: repoContext.repoSlug,
53010
+ pullRequestId: prId,
53011
+ commentId
53012
+ });
53013
+ if (context.globalOptions.json) {
53014
+ this.output.json({
53015
+ success: true,
52849
53016
  pullRequestId: prId,
52850
53017
  commentId
52851
53018
  });
52852
- this.output.success(`Deleted comment #${commentId} from PR #${prId}`);
52853
- } catch (error) {
52854
- this.handleError(error, context);
52855
- throw error;
53019
+ return;
52856
53020
  }
53021
+ this.output.success(`Deleted comment #${commentId} from PR #${prId}`);
52857
53022
  }
52858
53023
  }
52859
53024
 
@@ -52875,37 +53040,44 @@ class AddReviewerPRCommand extends BaseCommand {
52875
53040
  ...context.globalOptions,
52876
53041
  ...options
52877
53042
  });
52878
- const prId = parseInt(options.id, 10);
52879
- try {
52880
- const userResponse = await this.usersApi.usersSelectedUserGet({
52881
- selectedUser: options.username
52882
- });
52883
- const user = userResponse.data;
52884
- const prResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52885
- workspace: repoContext.workspace,
52886
- repoSlug: repoContext.repoSlug,
52887
- pullRequestId: prId
52888
- });
52889
- const pr = prResponse.data;
52890
- const existingReviewers = pr.reviewers ? Array.from(pr.reviewers) : [];
52891
- const reviewerUuids = existingReviewers.map((r) => r.uuid).filter(Boolean);
52892
- if (!reviewerUuids.includes(user.uuid)) {
52893
- reviewerUuids.push(user.uuid);
53043
+ const prId = Number.parseInt(options.id, 10);
53044
+ const userResponse = await this.usersApi.usersSelectedUserGet({
53045
+ selectedUser: options.username
53046
+ });
53047
+ const user = userResponse.data;
53048
+ const prResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
53049
+ workspace: repoContext.workspace,
53050
+ repoSlug: repoContext.repoSlug,
53051
+ pullRequestId: prId
53052
+ });
53053
+ const pr = prResponse.data;
53054
+ const existingReviewers = pr.reviewers ? Array.from(pr.reviewers) : [];
53055
+ const reviewerUuids = existingReviewers.map((r) => r.uuid).filter(Boolean);
53056
+ if (!reviewerUuids.includes(user.uuid)) {
53057
+ reviewerUuids.push(user.uuid);
53058
+ }
53059
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdPut({
53060
+ workspace: repoContext.workspace,
53061
+ repoSlug: repoContext.repoSlug,
53062
+ pullRequestId: prId,
53063
+ body: {
53064
+ type: "pullrequest",
53065
+ reviewers: reviewerUuids.map((uuid) => ({ uuid }))
52894
53066
  }
52895
- await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdPut({
52896
- workspace: repoContext.workspace,
52897
- repoSlug: repoContext.repoSlug,
53067
+ });
53068
+ if (context.globalOptions.json) {
53069
+ this.output.json({
53070
+ success: true,
52898
53071
  pullRequestId: prId,
52899
- body: {
52900
- type: "pullrequest",
52901
- reviewers: reviewerUuids.map((uuid) => ({ uuid }))
52902
- }
53072
+ reviewer: {
53073
+ username: options.username,
53074
+ uuid: user.uuid
53075
+ },
53076
+ pullRequest: response.data
52903
53077
  });
52904
- this.output.success(`Added ${options.username} as reviewer to pull request #${prId}`);
52905
- } catch (error) {
52906
- this.handleError(error, context);
52907
- throw error;
53078
+ return;
52908
53079
  }
53080
+ this.output.success(`Added ${options.username} as reviewer to pull request #${prId}`);
52909
53081
  }
52910
53082
  }
52911
53083
 
@@ -52927,34 +53099,41 @@ class RemoveReviewerPRCommand extends BaseCommand {
52927
53099
  ...context.globalOptions,
52928
53100
  ...options
52929
53101
  });
52930
- const prId = parseInt(options.id, 10);
52931
- try {
52932
- const userResponse = await this.usersApi.usersSelectedUserGet({
52933
- selectedUser: options.username
52934
- });
52935
- const user = userResponse.data;
52936
- const prResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52937
- workspace: repoContext.workspace,
52938
- repoSlug: repoContext.repoSlug,
52939
- pullRequestId: prId
52940
- });
52941
- const pr = prResponse.data;
52942
- const existingReviewers = pr.reviewers ? Array.from(pr.reviewers) : [];
52943
- const reviewerUuids = existingReviewers.map((r) => r.uuid).filter((uuid) => uuid && uuid !== user.uuid);
52944
- await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdPut({
52945
- workspace: repoContext.workspace,
52946
- repoSlug: repoContext.repoSlug,
53102
+ const prId = Number.parseInt(options.id, 10);
53103
+ const userResponse = await this.usersApi.usersSelectedUserGet({
53104
+ selectedUser: options.username
53105
+ });
53106
+ const user = userResponse.data;
53107
+ const prResponse = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
53108
+ workspace: repoContext.workspace,
53109
+ repoSlug: repoContext.repoSlug,
53110
+ pullRequestId: prId
53111
+ });
53112
+ const pr = prResponse.data;
53113
+ const existingReviewers = pr.reviewers ? Array.from(pr.reviewers) : [];
53114
+ const reviewerUuids = existingReviewers.map((r) => r.uuid).filter((uuid) => uuid && uuid !== user.uuid);
53115
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdPut({
53116
+ workspace: repoContext.workspace,
53117
+ repoSlug: repoContext.repoSlug,
53118
+ pullRequestId: prId,
53119
+ body: {
53120
+ type: "pullrequest",
53121
+ reviewers: reviewerUuids.map((uuid) => ({ uuid }))
53122
+ }
53123
+ });
53124
+ if (context.globalOptions.json) {
53125
+ this.output.json({
53126
+ success: true,
52947
53127
  pullRequestId: prId,
52948
- body: {
52949
- type: "pullrequest",
52950
- reviewers: reviewerUuids.map((uuid) => ({ uuid }))
52951
- }
53128
+ reviewer: {
53129
+ username: options.username,
53130
+ uuid: user.uuid
53131
+ },
53132
+ pullRequest: response.data
52952
53133
  });
52953
- this.output.success(`Removed ${options.username} as reviewer from pull request #${prId}`);
52954
- } catch (error) {
52955
- this.handleError(error, context);
52956
- throw error;
53134
+ return;
52957
53135
  }
53136
+ this.output.success(`Removed ${options.username} as reviewer from pull request #${prId}`);
52958
53137
  }
52959
53138
  }
52960
53139
 
@@ -52974,28 +53153,26 @@ class ListReviewersPRCommand extends BaseCommand {
52974
53153
  ...context.globalOptions,
52975
53154
  ...options
52976
53155
  });
52977
- const prId = parseInt(options.id, 10);
52978
- try {
52979
- const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
52980
- workspace: repoContext.workspace,
52981
- repoSlug: repoContext.repoSlug,
52982
- pullRequestId: prId
53156
+ const prId = Number.parseInt(options.id, 10);
53157
+ const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
53158
+ workspace: repoContext.workspace,
53159
+ repoSlug: repoContext.repoSlug,
53160
+ pullRequestId: prId
53161
+ });
53162
+ const pr = response.data;
53163
+ const reviewers = Array.from(pr.reviewers ?? []);
53164
+ if (context.globalOptions.json) {
53165
+ this.output.json({
53166
+ pullRequestId: prId,
53167
+ count: reviewers.length,
53168
+ reviewers
52983
53169
  });
52984
- const pr = response.data;
52985
- const reviewers = pr.reviewers ?? [];
52986
- if (context.globalOptions.json) {
52987
- this.output.json(reviewers);
52988
- } else if (reviewers.length === 0) {
52989
- this.output.info("No reviewers assigned to this pull request");
52990
- } else {
52991
- this.output.table(["Display Name", "Account ID"], reviewers.map((r) => [
52992
- r.display_name ?? "Unknown",
52993
- r.account_id ?? ""
52994
- ]));
52995
- }
52996
- } catch (error) {
52997
- this.handleError(error, context);
52998
- throw error;
53170
+ return;
53171
+ }
53172
+ if (reviewers.length === 0) {
53173
+ this.output.info("No reviewers assigned to this pull request");
53174
+ } else {
53175
+ this.output.table(["Display Name", "Account ID"], reviewers.map((r) => [r.display_name ?? "Unknown", r.account_id ?? ""]));
52999
53176
  }
53000
53177
  }
53001
53178
  }
@@ -53016,35 +53193,32 @@ class ChecksPRCommand extends BaseCommand {
53016
53193
  ...context.globalOptions,
53017
53194
  ...options
53018
53195
  });
53019
- const prId = parseInt(options.id, 10);
53020
- try {
53021
- const response = await this.commitStatusesApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdStatusesGet({
53196
+ const prId = Number.parseInt(options.id, 10);
53197
+ const response = await this.commitStatusesApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdStatusesGet({
53198
+ workspace: repoContext.workspace,
53199
+ repoSlug: repoContext.repoSlug,
53200
+ pullRequestId: prId
53201
+ });
53202
+ const data = response.data;
53203
+ const statuses = data?.values ? Array.from(data.values) : [];
53204
+ const summary = this.getSummary(statuses);
53205
+ const useJson = options.json || context.globalOptions.json;
53206
+ if (useJson) {
53207
+ this.output.json({
53208
+ pullRequestId: prId,
53022
53209
  workspace: repoContext.workspace,
53023
53210
  repoSlug: repoContext.repoSlug,
53024
- pullRequestId: prId
53211
+ summary,
53212
+ statuses: statuses.map((status) => this.formatStatusForJson(status))
53025
53213
  });
53026
- const data = response.data;
53027
- const statuses = data?.values ? Array.from(data.values) : [];
53028
- const useJson = options.json || context.globalOptions.json;
53029
- if (useJson) {
53030
- this.output.json({
53031
- pullRequestId: prId,
53032
- workspace: repoContext.workspace,
53033
- repoSlug: repoContext.repoSlug,
53034
- statuses: statuses.map((status) => this.formatStatusForJson(status))
53035
- });
53036
- return;
53037
- }
53038
- if (statuses.length === 0) {
53039
- this.output.info("No CI/CD checks found for this pull request");
53040
- return;
53041
- }
53042
- this.renderHeader(prId, statuses.length);
53043
- this.renderStatuses(statuses);
53044
- } catch (error) {
53045
- this.handleError(error, context);
53046
- throw error;
53214
+ return;
53047
53215
  }
53216
+ if (statuses.length === 0) {
53217
+ this.output.info("No CI/CD checks found for this pull request");
53218
+ return;
53219
+ }
53220
+ this.renderHeader(prId, statuses.length);
53221
+ this.renderStatuses(statuses, summary);
53048
53222
  }
53049
53223
  formatStatusForJson(status) {
53050
53224
  return {
@@ -53061,10 +53235,11 @@ class ChecksPRCommand extends BaseCommand {
53061
53235
  }
53062
53236
  renderHeader(prId, count) {
53063
53237
  this.output.text("");
53064
- this.output.text(`${source_default.bold(`Pull Request #${prId}`)} - ${count} check${count === 1 ? "" : "s"}`);
53065
- this.output.text(source_default.gray("-".repeat(60)));
53238
+ const title = this.output.bold("Pull Request #" + prId);
53239
+ this.output.text(`${title} - ${count} check${count === 1 ? "" : "s"}`);
53240
+ this.output.text(this.output.gray("-".repeat(60)));
53066
53241
  }
53067
- renderStatuses(statuses) {
53242
+ renderStatuses(statuses, summary) {
53068
53243
  const rows = statuses.map((status) => {
53069
53244
  const stateIcon = this.getStateIcon(status.state);
53070
53245
  const stateLabel = this.getStateLabel(status.state);
@@ -53072,29 +53247,28 @@ class ChecksPRCommand extends BaseCommand {
53072
53247
  const description = status.description ?? "-";
53073
53248
  return [
53074
53249
  `${stateIcon} ${stateLabel}`,
53075
- source_default.bold(name),
53250
+ this.output.bold(name),
53076
53251
  this.truncate(description, 40),
53077
53252
  status.updated_on ? this.output.formatDate(status.updated_on) : "-"
53078
53253
  ];
53079
53254
  });
53080
53255
  this.output.table(["STATUS", "NAME", "DESCRIPTION", "UPDATED"], rows);
53081
- const summary = this.getSummary(statuses);
53082
53256
  this.output.text("");
53083
- this.output.text(`${source_default.green("OK")} ${summary.successful} successful, ${source_default.red("FAIL")} ${summary.failed} failed, ${source_default.yellow("RUN")} ${summary.pending} pending`);
53257
+ this.output.text(`${this.output.green("OK")} ${summary.successful} successful, ${this.output.red("FAIL")} ${summary.failed} failed, ${this.output.yellow("RUN")} ${summary.pending} pending`);
53084
53258
  this.output.text("");
53085
53259
  }
53086
53260
  getStateIcon(state) {
53087
53261
  switch (state?.toUpperCase()) {
53088
53262
  case "SUCCESSFUL":
53089
- return source_default.green("OK");
53263
+ return this.output.green("OK");
53090
53264
  case "FAILED":
53091
- return source_default.red("FAIL");
53265
+ return this.output.red("FAIL");
53092
53266
  case "INPROGRESS":
53093
- return source_default.yellow("RUN");
53267
+ return this.output.yellow("RUN");
53094
53268
  case "STOPPED":
53095
- return source_default.gray("STOP");
53269
+ return this.output.gray("STOP");
53096
53270
  default:
53097
- return source_default.gray("?");
53271
+ return this.output.gray("?");
53098
53272
  }
53099
53273
  }
53100
53274
  getStateLabel(state) {
@@ -53161,19 +53335,22 @@ class GetConfigCommand extends BaseCommand {
53161
53335
  super(output);
53162
53336
  this.configService = configService;
53163
53337
  }
53164
- async execute(options, _context) {
53338
+ async execute(options, context) {
53165
53339
  const { key } = options;
53166
53340
  if (GetConfigCommand.HIDDEN_KEYS.includes(key)) {
53167
- const error = new Error(`Cannot display '${key}' - use 'bb auth token' to get authentication credentials`);
53168
- this.output.error(error.message);
53169
- throw error;
53341
+ throw new Error(`Cannot display '${key}' - use 'bb auth token' to get authentication credentials`);
53170
53342
  }
53171
53343
  if (!isReadableConfigKey(key)) {
53172
- const error = new Error(`Unknown config key '${key}'. Valid keys: username, defaultWorkspace`);
53173
- this.output.error(error.message);
53174
- throw error;
53344
+ throw new Error(`Unknown config key '${key}'. Valid keys: username, defaultWorkspace`);
53175
53345
  }
53176
53346
  const value = await this.configService.getValue(key);
53347
+ if (context.globalOptions.json) {
53348
+ this.output.json({
53349
+ key,
53350
+ value: value ?? null
53351
+ });
53352
+ return;
53353
+ }
53177
53354
  this.output.text(String(value || ""));
53178
53355
  }
53179
53356
  }
@@ -53188,19 +53365,23 @@ class SetConfigCommand extends BaseCommand {
53188
53365
  super(output);
53189
53366
  this.configService = configService;
53190
53367
  }
53191
- async execute(options, _context) {
53368
+ async execute(options, context) {
53192
53369
  const { key, value } = options;
53193
53370
  if (SetConfigCommand.PROTECTED_KEYS.includes(key)) {
53194
- const error = new Error(`Cannot set '${key}' directly. Use 'bb auth login' to configure authentication.`);
53195
- this.output.error(error.message);
53196
- throw error;
53371
+ throw new Error(`Cannot set '${key}' directly. Use 'bb auth login' to configure authentication.`);
53197
53372
  }
53198
53373
  if (!isSettableConfigKey(key)) {
53199
- const error = new Error(`Unknown config key '${key}'. Valid keys: defaultWorkspace`);
53200
- this.output.error(error.message);
53201
- throw error;
53374
+ throw new Error(`Unknown config key '${key}'. Valid keys: defaultWorkspace`);
53202
53375
  }
53203
53376
  await this.configService.setValue(key, value);
53377
+ if (context.globalOptions.json) {
53378
+ this.output.json({
53379
+ success: true,
53380
+ key,
53381
+ value
53382
+ });
53383
+ return;
53384
+ }
53204
53385
  this.output.success(`Set ${key} = ${value}`);
53205
53386
  }
53206
53387
  }
@@ -53214,14 +53395,21 @@ class ListConfigCommand extends BaseCommand {
53214
53395
  super(output);
53215
53396
  this.configService = configService;
53216
53397
  }
53217
- async execute(_options, _context) {
53398
+ async execute(_options, context) {
53218
53399
  const config = await this.configService.getConfig();
53219
53400
  const displayConfig = {
53220
53401
  username: config.username || "",
53221
53402
  defaultWorkspace: config.defaultWorkspace || "",
53222
53403
  apiToken: config.apiToken ? "********" : ""
53223
53404
  };
53224
- this.output.text(source_default.dim(`Config file: ${this.configService.getConfigPath()}`));
53405
+ if (context.globalOptions.json) {
53406
+ this.output.json({
53407
+ configPath: this.configService.getConfigPath(),
53408
+ config: Object.fromEntries(Object.entries(displayConfig).filter(([, value]) => value !== ""))
53409
+ });
53410
+ return;
53411
+ }
53412
+ this.output.text(this.output.dim(`Config file: ${this.configService.getConfigPath()}`));
53225
53413
  this.output.text("");
53226
53414
  const rows = Object.entries(displayConfig).filter(([, value]) => value !== "").map(([key, value]) => [key, value]);
53227
53415
  if (rows.length === 0) {
@@ -53241,17 +53429,26 @@ class InstallCompletionCommand extends BaseCommand {
53241
53429
  constructor(output) {
53242
53430
  super(output);
53243
53431
  }
53244
- async execute(_options, _context) {
53432
+ async execute(_options, context) {
53245
53433
  try {
53246
53434
  await import_tabtab.default.install({
53247
53435
  name: "bb",
53248
53436
  completer: "bb"
53249
53437
  });
53438
+ if (context.globalOptions.json) {
53439
+ this.output.json({
53440
+ success: true,
53441
+ shellCompletion: {
53442
+ command: "bb",
53443
+ installed: true
53444
+ }
53445
+ });
53446
+ return;
53447
+ }
53250
53448
  this.output.success("Shell completions installed successfully!");
53251
53449
  this.output.text("Restart your shell or source your profile to enable completions.");
53252
53450
  } catch (error) {
53253
- this.output.error(`Failed to install completions: ${error}`);
53254
- throw error;
53451
+ throw new Error(`Failed to install completions: ${error}`);
53255
53452
  }
53256
53453
  }
53257
53454
  }
@@ -53265,15 +53462,24 @@ class UninstallCompletionCommand extends BaseCommand {
53265
53462
  constructor(output) {
53266
53463
  super(output);
53267
53464
  }
53268
- async execute(_options, _context) {
53465
+ async execute(_options, context) {
53269
53466
  try {
53270
53467
  await import_tabtab2.default.uninstall({
53271
53468
  name: "bb"
53272
53469
  });
53470
+ if (context.globalOptions.json) {
53471
+ this.output.json({
53472
+ success: true,
53473
+ shellCompletion: {
53474
+ command: "bb",
53475
+ installed: false
53476
+ }
53477
+ });
53478
+ return;
53479
+ }
53273
53480
  this.output.success("Shell completions uninstalled successfully!");
53274
53481
  } catch (error) {
53275
- this.output.error(`Failed to uninstall completions: ${error}`);
53276
- throw error;
53482
+ throw new Error(`Failed to uninstall completions: ${error}`);
53277
53483
  }
53278
53484
  }
53279
53485
  }
@@ -53281,11 +53487,11 @@ class UninstallCompletionCommand extends BaseCommand {
53281
53487
  // src/bootstrap.ts
53282
53488
  var require2 = createRequire(import.meta.url);
53283
53489
  var pkg = require2("../package.json");
53284
- function bootstrap() {
53490
+ function bootstrap(options = {}) {
53285
53491
  const container = Container.getInstance();
53286
53492
  container.register(ServiceTokens.ConfigService, () => new ConfigService);
53287
53493
  container.register(ServiceTokens.GitService, () => new GitService);
53288
- container.register(ServiceTokens.OutputService, () => new OutputService);
53494
+ container.register(ServiceTokens.OutputService, () => new OutputService({ noColor: options.noColor }));
53289
53495
  container.register(ServiceTokens.PullrequestsApi, () => {
53290
53496
  const configService = container.resolve(ServiceTokens.ConfigService);
53291
53497
  const axiosInstance = createApiClient(configService);
@@ -53529,6 +53735,7 @@ if (process.argv.includes("--get-yargs-completions") || process.env.COMP_LINE) {
53529
53735
  "--help",
53530
53736
  "--version",
53531
53737
  "--json",
53738
+ "--no-color",
53532
53739
  "--workspace",
53533
53740
  "--repo"
53534
53741
  ];
@@ -53549,17 +53756,44 @@ if (process.argv.includes("--get-yargs-completions") || process.env.COMP_LINE) {
53549
53756
  process.exit(0);
53550
53757
  }
53551
53758
  }
53552
- var container = bootstrap();
53759
+ function resolveNoColorSetting(argv, env2) {
53760
+ const hasColorArg = argv.includes("--color");
53761
+ const hasNoColorArg = argv.includes("--no-color");
53762
+ const hasForceColorEnv = env2.FORCE_COLOR !== undefined && env2.FORCE_COLOR !== "0";
53763
+ const hasNoColorEnv = env2.NO_COLOR !== undefined;
53764
+ if (hasColorArg) {
53765
+ return false;
53766
+ }
53767
+ if (hasForceColorEnv) {
53768
+ return false;
53769
+ }
53770
+ if (hasNoColorArg) {
53771
+ return true;
53772
+ }
53773
+ return hasNoColorEnv;
53774
+ }
53775
+ var noColor = resolveNoColorSetting(process.argv, process.env);
53776
+ var container = bootstrap({ noColor });
53553
53777
  function createContext(program2) {
53554
53778
  const opts = program2.opts();
53555
53779
  return {
53556
53780
  globalOptions: {
53557
53781
  json: opts.json,
53782
+ noColor: opts.color === false,
53558
53783
  workspace: opts.workspace,
53559
53784
  repo: opts.repo
53560
53785
  }
53561
53786
  };
53562
53787
  }
53788
+ async function runCommand(token, options, program2, context) {
53789
+ const cmd = container.resolve(token);
53790
+ const resolvedContext = context ?? createContext(program2);
53791
+ try {
53792
+ return await cmd.run(options, resolvedContext);
53793
+ } catch {
53794
+ return;
53795
+ }
53796
+ }
53563
53797
  function withGlobalOptions(options, context) {
53564
53798
  return {
53565
53799
  ...options,
@@ -53568,321 +53802,156 @@ function withGlobalOptions(options, context) {
53568
53802
  };
53569
53803
  }
53570
53804
  var cli = new Command;
53571
- cli.name("bb").description("A command-line interface for Bitbucket Cloud").version(pkg2.version).option("--json", "Output as JSON").option("-w, --workspace <workspace>", "Specify workspace").option("-r, --repo <repo>", "Specify repository").action(async () => {
53805
+ cli.name("bb").description("A command-line interface for Bitbucket Cloud").version(pkg2.version).option("--json", "Output as JSON").option("--no-color", "Disable color output").option("-w, --workspace <workspace>", "Specify workspace").option("-r, --repo <repo>", "Specify repository").action(async () => {
53572
53806
  cli.outputHelp();
53573
53807
  const versionService = container.resolve(ServiceTokens.VersionService);
53574
53808
  const output = container.resolve(ServiceTokens.OutputService);
53575
53809
  try {
53576
53810
  const result = await versionService.checkForUpdate();
53577
53811
  if (result?.updateAvailable) {
53578
- console.log("");
53579
- console.log("\u2500".repeat(50));
53580
- console.log(`\u26A0 A new version is available: ${result.latestVersion} (you have ${result.currentVersion})`);
53581
- console.log(` Run '${versionService.getInstallCommand()}' to update`);
53582
- console.log(` Or disable with 'bb config set skipVersionCheck true'`);
53583
- console.log("\u2500".repeat(50));
53812
+ output.text("");
53813
+ output.text("\u2500".repeat(50));
53814
+ output.text(`\u26A0 A new version is available: ${result.latestVersion} (you have ${result.currentVersion})`);
53815
+ output.text(` Run '${versionService.getInstallCommand()}' to update`);
53816
+ output.text(` Or disable with 'bb config set skipVersionCheck true'`);
53817
+ output.text("\u2500".repeat(50));
53584
53818
  }
53585
53819
  } catch {}
53586
53820
  });
53587
53821
  var authCmd = new Command("auth").description("Authenticate with Bitbucket");
53588
53822
  authCmd.command("login").description("Authenticate with Bitbucket using an API token").option("-u, --username <username>", "Bitbucket username").option("-p, --password <password>", "Bitbucket API token").action(async (options) => {
53589
- try {
53590
- const cmd = container.resolve(ServiceTokens.LoginCommand);
53591
- await cmd.execute(options, createContext(cli));
53592
- } catch {
53593
- process.exit(1);
53594
- }
53823
+ await runCommand(ServiceTokens.LoginCommand, options, cli);
53595
53824
  });
53596
53825
  authCmd.command("logout").description("Log out of Bitbucket").action(async () => {
53597
- try {
53598
- const cmd = container.resolve(ServiceTokens.LogoutCommand);
53599
- await cmd.execute(undefined, createContext(cli));
53600
- } catch {
53601
- process.exit(1);
53602
- }
53826
+ await runCommand(ServiceTokens.LogoutCommand, undefined, cli);
53603
53827
  });
53604
53828
  authCmd.command("status").description("Show authentication status").action(async () => {
53605
- try {
53606
- const cmd = container.resolve(ServiceTokens.StatusCommand);
53607
- await cmd.execute(undefined, createContext(cli));
53608
- } catch {
53609
- process.exit(1);
53610
- }
53829
+ await runCommand(ServiceTokens.StatusCommand, undefined, cli);
53611
53830
  });
53612
53831
  authCmd.command("token").description("Print the current access token").action(async () => {
53613
- try {
53614
- const cmd = container.resolve(ServiceTokens.TokenCommand);
53615
- await cmd.execute(undefined, createContext(cli));
53616
- } catch {
53617
- process.exit(1);
53618
- }
53832
+ await runCommand(ServiceTokens.TokenCommand, undefined, cli);
53619
53833
  });
53620
53834
  cli.addCommand(authCmd);
53621
53835
  var repoCmd = new Command("repo").description("Manage repositories");
53622
53836
  repoCmd.command("clone <repository>").description("Clone a Bitbucket repository").option("-d, --directory <dir>", "Directory to clone into").action(async (repository, options) => {
53623
- try {
53624
- const cmd = container.resolve(ServiceTokens.CloneCommand);
53625
- await cmd.execute({ repository, ...options }, createContext(cli));
53626
- } catch {
53627
- process.exit(1);
53628
- }
53837
+ await runCommand(ServiceTokens.CloneCommand, { repository, ...options }, cli);
53629
53838
  });
53630
53839
  repoCmd.command("create <name>").description("Create a new repository").option("-d, --description <description>", "Repository description").option("--private", "Create a private repository (default)").option("--public", "Create a public repository").option("-p, --project <project>", "Project key").action(async (name, options) => {
53631
- try {
53632
- const cmd = container.resolve(ServiceTokens.CreateRepoCommand);
53633
- const context = createContext(cli);
53634
- await cmd.execute(withGlobalOptions({ name, ...options }, context), context);
53635
- } catch {
53636
- process.exit(1);
53637
- }
53840
+ const context = createContext(cli);
53841
+ await runCommand(ServiceTokens.CreateRepoCommand, withGlobalOptions({ name, ...options }, context), cli, context);
53638
53842
  });
53639
53843
  repoCmd.command("list").description("List repositories").option("--limit <number>", "Maximum number of repositories to list", "25").action(async (options) => {
53640
- try {
53641
- const cmd = container.resolve(ServiceTokens.ListReposCommand);
53642
- const context = createContext(cli);
53643
- await cmd.execute(withGlobalOptions(options, context), context);
53644
- } catch {
53645
- process.exit(1);
53646
- }
53844
+ const context = createContext(cli);
53845
+ await runCommand(ServiceTokens.ListReposCommand, withGlobalOptions(options, context), cli, context);
53647
53846
  });
53648
53847
  repoCmd.command("view [repository]").description("View repository details").action(async (repository, options) => {
53649
- try {
53650
- const cmd = container.resolve(ServiceTokens.ViewRepoCommand);
53651
- const context = createContext(cli);
53652
- await cmd.execute(withGlobalOptions({ repository, ...options }, context), context);
53653
- } catch {
53654
- process.exit(1);
53655
- }
53848
+ const context = createContext(cli);
53849
+ await runCommand(ServiceTokens.ViewRepoCommand, withGlobalOptions({ repository, ...options }, context), cli, context);
53656
53850
  });
53657
53851
  repoCmd.command("delete <repository>").description("Delete a repository").option("-y, --yes", "Skip confirmation prompt").action(async (repository, options) => {
53658
- try {
53659
- const cmd = container.resolve(ServiceTokens.DeleteRepoCommand);
53660
- const context = createContext(cli);
53661
- await cmd.execute(withGlobalOptions({ repository, ...options }, context), context);
53662
- } catch {
53663
- process.exit(1);
53664
- }
53852
+ const context = createContext(cli);
53853
+ await runCommand(ServiceTokens.DeleteRepoCommand, withGlobalOptions({ repository, ...options }, context), cli, context);
53665
53854
  });
53666
53855
  cli.addCommand(repoCmd);
53667
53856
  var prCmd = new Command("pr").description("Manage pull requests");
53668
53857
  prCmd.command("create").description("Create a pull request").option("-t, --title <title>", "Pull request title").option("-b, --body <body>", "Pull request description").option("-s, --source <branch>", "Source branch (default: current branch)").option("-d, --destination <branch>", "Destination branch (default: main)").option("--close-source-branch", "Close source branch after merge").option("--draft", "Create the pull request as draft").action(async (options) => {
53669
- try {
53670
- const cmd = container.resolve(ServiceTokens.CreatePRCommand);
53671
- const context = createContext(cli);
53672
- await cmd.execute(withGlobalOptions(options, context), context);
53673
- } catch {
53674
- process.exit(1);
53675
- }
53858
+ const context = createContext(cli);
53859
+ await runCommand(ServiceTokens.CreatePRCommand, withGlobalOptions(options, context), cli, context);
53676
53860
  });
53677
53861
  prCmd.command("list").description("List pull requests").option("-s, --state <state>", "Filter by state (OPEN, MERGED, DECLINED, SUPERSEDED)", "OPEN").option("--limit <number>", "Maximum number of PRs to list", "25").action(async (options) => {
53678
- try {
53679
- const cmd = container.resolve(ServiceTokens.ListPRsCommand);
53680
- const context = createContext(cli);
53681
- await cmd.execute(withGlobalOptions(options, context), context);
53682
- } catch {
53683
- process.exit(1);
53684
- }
53862
+ const context = createContext(cli);
53863
+ await runCommand(ServiceTokens.ListPRsCommand, withGlobalOptions(options, context), cli, context);
53685
53864
  });
53686
53865
  prCmd.command("view <id>").description("View pull request details").action(async (id, options) => {
53687
- try {
53688
- const cmd = container.resolve(ServiceTokens.ViewPRCommand);
53689
- const context = createContext(cli);
53690
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53691
- } catch {
53692
- process.exit(1);
53693
- }
53866
+ const context = createContext(cli);
53867
+ await runCommand(ServiceTokens.ViewPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53694
53868
  });
53695
53869
  prCmd.command("activity <id>").description("Show pull request activity log").option("--limit <number>", "Maximum number of activity entries", "25").option("--type <types>", "Filter activity by type (comma-separated)").action(async (id, options) => {
53696
- try {
53697
- const cmd = container.resolve(ServiceTokens.ActivityPRCommand);
53698
- const context = createContext(cli);
53699
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53700
- } catch {
53701
- process.exit(1);
53702
- }
53870
+ const context = createContext(cli);
53871
+ await runCommand(ServiceTokens.ActivityPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53703
53872
  });
53704
53873
  prCmd.command("checks <id>").description("Show CI/CD checks and build status for a pull request").option("--json", "Output as JSON").action(async (id, options) => {
53705
- try {
53706
- const cmd = container.resolve(ServiceTokens.ChecksPRCommand);
53707
- const context = createContext(cli);
53708
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53709
- } catch {
53710
- process.exit(1);
53711
- }
53874
+ const context = createContext(cli);
53875
+ await runCommand(ServiceTokens.ChecksPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53712
53876
  });
53713
53877
  prCmd.command("edit [id]").description("Edit a pull request").option("-t, --title <title>", "New pull request title").option("-b, --body <body>", "New pull request description").option("-F, --body-file <file>", "Read description from file").action(async (id, options) => {
53714
- try {
53715
- const cmd = container.resolve(ServiceTokens.EditPRCommand);
53716
- const context = createContext(cli);
53717
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53718
- } catch {
53719
- process.exit(1);
53720
- }
53878
+ const context = createContext(cli);
53879
+ await runCommand(ServiceTokens.EditPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53721
53880
  });
53722
53881
  prCmd.command("merge <id>").description("Merge a pull request").option("-m, --message <message>", "Merge commit message").option("--close-source-branch", "Delete the source branch after merging").option("--strategy <strategy>", "Merge strategy (merge_commit, squash, fast_forward)").action(async (id, options) => {
53723
- try {
53724
- const cmd = container.resolve(ServiceTokens.MergePRCommand);
53725
- const context = createContext(cli);
53726
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53727
- } catch {
53728
- process.exit(1);
53729
- }
53882
+ const context = createContext(cli);
53883
+ await runCommand(ServiceTokens.MergePRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53730
53884
  });
53731
53885
  prCmd.command("approve <id>").description("Approve a pull request").action(async (id, options) => {
53732
- try {
53733
- const cmd = container.resolve(ServiceTokens.ApprovePRCommand);
53734
- const context = createContext(cli);
53735
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53736
- } catch {
53737
- process.exit(1);
53738
- }
53886
+ const context = createContext(cli);
53887
+ await runCommand(ServiceTokens.ApprovePRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53739
53888
  });
53740
53889
  prCmd.command("decline <id>").description("Decline a pull request").action(async (id, options) => {
53741
- try {
53742
- const cmd = container.resolve(ServiceTokens.DeclinePRCommand);
53743
- const context = createContext(cli);
53744
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53745
- } catch {
53746
- process.exit(1);
53747
- }
53890
+ const context = createContext(cli);
53891
+ await runCommand(ServiceTokens.DeclinePRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53748
53892
  });
53749
53893
  prCmd.command("ready <id>").description("Mark a draft pull request as ready for review").action(async (id, options) => {
53750
- try {
53751
- const cmd = container.resolve(ServiceTokens.ReadyPRCommand);
53752
- const context = createContext(cli);
53753
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53754
- } catch {
53755
- process.exit(1);
53756
- }
53894
+ const context = createContext(cli);
53895
+ await runCommand(ServiceTokens.ReadyPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53757
53896
  });
53758
53897
  prCmd.command("checkout <id>").description("Checkout a pull request locally").action(async (id, options) => {
53759
- try {
53760
- const cmd = container.resolve(ServiceTokens.CheckoutPRCommand);
53761
- const context = createContext(cli);
53762
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53763
- } catch {
53764
- process.exit(1);
53765
- }
53898
+ const context = createContext(cli);
53899
+ await runCommand(ServiceTokens.CheckoutPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53766
53900
  });
53767
53901
  prCmd.command("diff [id]").description("View pull request diff").option("--color <when>", "Colorize output (auto, always, never)", "auto").option("--name-only", "Show only names of changed files").option("--stat", "Show diffstat").option("-w, --web", "Open diff in web browser").action(async (id, options) => {
53768
- try {
53769
- const cmd = container.resolve(ServiceTokens.DiffPRCommand);
53770
- const context = createContext(cli);
53771
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53772
- } catch {
53773
- process.exit(1);
53774
- }
53902
+ const context = createContext(cli);
53903
+ await runCommand(ServiceTokens.DiffPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53775
53904
  });
53776
53905
  var prCommentsCmd = new Command("comments").description("Manage pull request comments");
53777
53906
  prCommentsCmd.command("list <id>").description("List comments on a pull request").option("--limit <number>", "Maximum number of comments (default: 25)").option("--no-truncate", "Show full comment content without truncation").action(async (id, options) => {
53778
- try {
53779
- const cmd = container.resolve(ServiceTokens.ListCommentsPRCommand);
53780
- const context = createContext(cli);
53781
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53782
- } catch {
53783
- process.exit(1);
53784
- }
53907
+ const context = createContext(cli);
53908
+ await runCommand(ServiceTokens.ListCommentsPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53785
53909
  });
53786
53910
  prCommentsCmd.command("add <id> <message>").description("Add a comment to a pull request").action(async (id, message, options) => {
53787
- try {
53788
- const cmd = container.resolve(ServiceTokens.CommentPRCommand);
53789
- const context = createContext(cli);
53790
- await cmd.execute(withGlobalOptions({ id, message }, context), context);
53791
- } catch {
53792
- process.exit(1);
53793
- }
53911
+ const context = createContext(cli);
53912
+ await runCommand(ServiceTokens.CommentPRCommand, withGlobalOptions({ id, message }, context), cli, context);
53794
53913
  });
53795
53914
  prCommentsCmd.command("edit <pr-id> <comment-id> <message>").description("Edit a comment on a pull request").action(async (prId, commentId, message, options) => {
53796
- try {
53797
- const cmd = container.resolve(ServiceTokens.EditCommentPRCommand);
53798
- const context = createContext(cli);
53799
- await cmd.execute(withGlobalOptions({ prId, commentId, message }, context), context);
53800
- } catch {
53801
- process.exit(1);
53802
- }
53915
+ const context = createContext(cli);
53916
+ await runCommand(ServiceTokens.EditCommentPRCommand, withGlobalOptions({ prId, commentId, message }, context), cli, context);
53803
53917
  });
53804
53918
  prCommentsCmd.command("delete <pr-id> <comment-id>").description("Delete a comment on a pull request").action(async (prId, commentId, options) => {
53805
- try {
53806
- const cmd = container.resolve(ServiceTokens.DeleteCommentPRCommand);
53807
- const context = createContext(cli);
53808
- await cmd.execute(withGlobalOptions({ prId, commentId }, context), context);
53809
- } catch {
53810
- process.exit(1);
53811
- }
53919
+ const context = createContext(cli);
53920
+ await runCommand(ServiceTokens.DeleteCommentPRCommand, withGlobalOptions({ prId, commentId }, context), cli, context);
53812
53921
  });
53813
53922
  var prReviewersCmd = new Command("reviewers").description("Manage pull request reviewers");
53814
53923
  prReviewersCmd.command("list <id>").description("List reviewers on a pull request").action(async (id, options) => {
53815
- try {
53816
- const cmd = container.resolve(ServiceTokens.ListReviewersPRCommand);
53817
- const context = createContext(cli);
53818
- await cmd.execute(withGlobalOptions({ id, ...options }, context), context);
53819
- } catch {
53820
- process.exit(1);
53821
- }
53924
+ const context = createContext(cli);
53925
+ await runCommand(ServiceTokens.ListReviewersPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
53822
53926
  });
53823
53927
  prReviewersCmd.command("add <id> <username>").description("Add a reviewer to a pull request").action(async (id, username, options) => {
53824
- try {
53825
- const cmd = container.resolve(ServiceTokens.AddReviewerPRCommand);
53826
- const context = createContext(cli);
53827
- await cmd.execute(withGlobalOptions({ id, username, ...options }, context), context);
53828
- } catch {
53829
- process.exit(1);
53830
- }
53928
+ const context = createContext(cli);
53929
+ await runCommand(ServiceTokens.AddReviewerPRCommand, withGlobalOptions({ id, username, ...options }, context), cli, context);
53831
53930
  });
53832
53931
  prReviewersCmd.command("remove <id> <username>").description("Remove a reviewer from a pull request").action(async (id, username, options) => {
53833
- try {
53834
- const cmd = container.resolve(ServiceTokens.RemoveReviewerPRCommand);
53835
- const context = createContext(cli);
53836
- await cmd.execute(withGlobalOptions({ id, username, ...options }, context), context);
53837
- } catch {
53838
- process.exit(1);
53839
- }
53932
+ const context = createContext(cli);
53933
+ await runCommand(ServiceTokens.RemoveReviewerPRCommand, withGlobalOptions({ id, username, ...options }, context), cli, context);
53840
53934
  });
53841
53935
  cli.addCommand(prCmd);
53842
53936
  prCmd.addCommand(prCommentsCmd);
53843
53937
  prCmd.addCommand(prReviewersCmd);
53844
53938
  var configCmd = new Command("config").description("Manage configuration");
53845
53939
  configCmd.command("get <key>").description("Get a configuration value").action(async (key) => {
53846
- try {
53847
- const cmd = container.resolve(ServiceTokens.GetConfigCommand);
53848
- await cmd.execute({ key }, createContext(cli));
53849
- } catch {
53850
- process.exit(1);
53851
- }
53940
+ await runCommand(ServiceTokens.GetConfigCommand, { key }, cli);
53852
53941
  });
53853
53942
  configCmd.command("set <key> <value>").description("Set a configuration value").action(async (key, value) => {
53854
- try {
53855
- const cmd = container.resolve(ServiceTokens.SetConfigCommand);
53856
- await cmd.execute({ key, value }, createContext(cli));
53857
- } catch {
53858
- process.exit(1);
53859
- }
53943
+ await runCommand(ServiceTokens.SetConfigCommand, { key, value }, cli);
53860
53944
  });
53861
53945
  configCmd.command("list").description("List all configuration values").action(async () => {
53862
- try {
53863
- const cmd = container.resolve(ServiceTokens.ListConfigCommand);
53864
- await cmd.execute(undefined, createContext(cli));
53865
- } catch {
53866
- process.exit(1);
53867
- }
53946
+ await runCommand(ServiceTokens.ListConfigCommand, undefined, cli);
53868
53947
  });
53869
53948
  cli.addCommand(configCmd);
53870
53949
  var completionCmd = new Command("completion").description("Shell completion utilities");
53871
53950
  completionCmd.command("install").description("Install shell completions for bash, zsh, or fish").action(async () => {
53872
- try {
53873
- const cmd = container.resolve(ServiceTokens.InstallCompletionCommand);
53874
- await cmd.execute(undefined, createContext(cli));
53875
- } catch {
53876
- process.exit(1);
53877
- }
53951
+ await runCommand(ServiceTokens.InstallCompletionCommand, undefined, cli);
53878
53952
  });
53879
53953
  completionCmd.command("uninstall").description("Uninstall shell completions").action(async () => {
53880
- try {
53881
- const cmd = container.resolve(ServiceTokens.UninstallCompletionCommand);
53882
- await cmd.execute(undefined, createContext(cli));
53883
- } catch {
53884
- process.exit(1);
53885
- }
53954
+ await runCommand(ServiceTokens.UninstallCompletionCommand, undefined, cli);
53886
53955
  });
53887
53956
  cli.addCommand(completionCmd);
53888
53957