@pilatos/bitbucket-cli 1.8.4 → 1.9.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 (2) hide show
  1. package/dist/index.js +63 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -21124,6 +21124,27 @@ class BaseCommand {
21124
21124
  }
21125
21125
  return value;
21126
21126
  }
21127
+ parseIntOption(value, name) {
21128
+ const parsed = Number.parseInt(value, 10);
21129
+ if (Number.isNaN(parsed)) {
21130
+ throw new BBError({
21131
+ code: 5002 /* VALIDATION_INVALID */,
21132
+ message: `--${name} must be a valid integer`,
21133
+ context: { [name]: value }
21134
+ });
21135
+ }
21136
+ return parsed;
21137
+ }
21138
+ parseEnumOption(value, name, allowed) {
21139
+ if (!allowed.includes(value)) {
21140
+ throw new BBError({
21141
+ code: 5002 /* VALIDATION_INVALID */,
21142
+ message: `--${name} must be one of: ${allowed.join(", ")}`,
21143
+ context: { [name]: value }
21144
+ });
21145
+ }
21146
+ return value;
21147
+ }
21127
21148
  }
21128
21149
 
21129
21150
  // src/commands/auth/login.command.ts
@@ -21641,7 +21662,8 @@ class CreateRepoCommand extends BaseCommand {
21641
21662
  this.configService = configService;
21642
21663
  }
21643
21664
  async execute(options, context) {
21644
- const { name, description, project } = options;
21665
+ const { description, project } = options;
21666
+ const name = this.requireOption(options.name, "name");
21645
21667
  const isPublic = options.public === true;
21646
21668
  const workspace = await this.resolveWorkspace(options.workspace);
21647
21669
  const request = {
@@ -21964,12 +21986,14 @@ class CreatePRCommand extends BaseCommand {
21964
21986
  // src/commands/pr/list.command.ts
21965
21987
  class ListPRsCommand extends BaseCommand {
21966
21988
  pullrequestsApi;
21989
+ usersApi;
21967
21990
  contextService;
21968
21991
  name = "list";
21969
21992
  description = "List pull requests";
21970
- constructor(pullrequestsApi, contextService, output) {
21993
+ constructor(pullrequestsApi, usersApi, contextService, output) {
21971
21994
  super(output);
21972
21995
  this.pullrequestsApi = pullrequestsApi;
21996
+ this.usersApi = usersApi;
21973
21997
  this.contextService = contextService;
21974
21998
  }
21975
21999
  async execute(options, context) {
@@ -21977,8 +22001,15 @@ class ListPRsCommand extends BaseCommand {
21977
22001
  ...context.globalOptions,
21978
22002
  ...options
21979
22003
  });
21980
- const state = options.state || "OPEN";
22004
+ const ALLOWED_STATES = [
22005
+ "OPEN",
22006
+ "MERGED",
22007
+ "DECLINED",
22008
+ "SUPERSEDED"
22009
+ ];
22010
+ const state = options.state ? this.parseEnumOption(options.state, "state", ALLOWED_STATES) : "OPEN";
21981
22011
  const limit = parseLimit(options.limit);
22012
+ const reviewerQuery = options.mine ? await this.buildMineFilter() : undefined;
21982
22013
  const values = await collectPages({
21983
22014
  limit,
21984
22015
  fetchPage: async (page, pagelen) => {
@@ -21987,7 +22018,11 @@ class ListPRsCommand extends BaseCommand {
21987
22018
  repoSlug: repoContext.repoSlug,
21988
22019
  state
21989
22020
  }, {
21990
- params: { page, pagelen }
22021
+ params: {
22022
+ page,
22023
+ pagelen,
22024
+ ...reviewerQuery ? { q: reviewerQuery } : {}
22025
+ }
21991
22026
  });
21992
22027
  return response.data;
21993
22028
  }
@@ -21997,6 +22032,9 @@ class ListPRsCommand extends BaseCommand {
21997
22032
  workspace: repoContext.workspace,
21998
22033
  repoSlug: repoContext.repoSlug,
21999
22034
  state,
22035
+ filters: {
22036
+ mine: options.mine === true
22037
+ },
22000
22038
  count: values.length,
22001
22039
  pullRequests: values
22002
22040
  });
@@ -22025,6 +22063,15 @@ class ListPRsCommand extends BaseCommand {
22025
22063
  }
22026
22064
  return text.substring(0, maxLength - 3) + "...";
22027
22065
  }
22066
+ async buildMineFilter() {
22067
+ const response = await this.usersApi.userGet();
22068
+ const userUuid = response.data.uuid;
22069
+ if (!userUuid) {
22070
+ this.output.warning("Could not determine your user UUID. Showing all pull requests.");
22071
+ return;
22072
+ }
22073
+ return `reviewers.uuid="${userUuid}"`;
22074
+ }
22028
22075
  }
22029
22076
 
22030
22077
  // src/commands/pr/view.command.ts
@@ -22975,7 +23022,7 @@ class ListCommentsPRCommand extends BaseCommand {
22975
23022
  ...context.globalOptions,
22976
23023
  ...options
22977
23024
  });
22978
- const prId = Number.parseInt(options.id, 10);
23025
+ const prId = this.parseIntOption(options.id, "id");
22979
23026
  const limit = parseLimit(options.limit);
22980
23027
  const values = await collectPages({
22981
23028
  limit,
@@ -23031,8 +23078,8 @@ class EditCommentPRCommand extends BaseCommand {
23031
23078
  ...context.globalOptions,
23032
23079
  ...options
23033
23080
  });
23034
- const prId = Number.parseInt(options.prId, 10);
23035
- const commentId = Number.parseInt(options.commentId, 10);
23081
+ const prId = this.parseIntOption(options.prId, "pr-id");
23082
+ const commentId = this.parseIntOption(options.commentId, "comment-id");
23036
23083
  const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsCommentIdPut({
23037
23084
  workspace: repoContext.workspace,
23038
23085
  repoSlug: repoContext.repoSlug,
@@ -23074,8 +23121,8 @@ class DeleteCommentPRCommand extends BaseCommand {
23074
23121
  ...context.globalOptions,
23075
23122
  ...options
23076
23123
  });
23077
- const prId = Number.parseInt(options.prId, 10);
23078
- const commentId = Number.parseInt(options.commentId, 10);
23124
+ const prId = this.parseIntOption(options.prId, "pr-id");
23125
+ const commentId = this.parseIntOption(options.commentId, "comment-id");
23079
23126
  await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdCommentsCommentIdDelete({
23080
23127
  workspace: repoContext.workspace,
23081
23128
  repoSlug: repoContext.repoSlug,
@@ -23112,7 +23159,7 @@ class AddReviewerPRCommand extends BaseCommand {
23112
23159
  ...context.globalOptions,
23113
23160
  ...options
23114
23161
  });
23115
- const prId = Number.parseInt(options.id, 10);
23162
+ const prId = this.parseIntOption(options.id, "id");
23116
23163
  const userResponse = await this.usersApi.usersSelectedUserGet({
23117
23164
  selectedUser: options.username
23118
23165
  });
@@ -23171,7 +23218,7 @@ class RemoveReviewerPRCommand extends BaseCommand {
23171
23218
  ...context.globalOptions,
23172
23219
  ...options
23173
23220
  });
23174
- const prId = Number.parseInt(options.id, 10);
23221
+ const prId = this.parseIntOption(options.id, "id");
23175
23222
  const userResponse = await this.usersApi.usersSelectedUserGet({
23176
23223
  selectedUser: options.username
23177
23224
  });
@@ -23225,7 +23272,7 @@ class ListReviewersPRCommand extends BaseCommand {
23225
23272
  ...context.globalOptions,
23226
23273
  ...options
23227
23274
  });
23228
- const prId = Number.parseInt(options.id, 10);
23275
+ const prId = this.parseIntOption(options.id, "id");
23229
23276
  const response = await this.pullrequestsApi.repositoriesWorkspaceRepoSlugPullrequestsPullRequestIdGet({
23230
23277
  workspace: repoContext.workspace,
23231
23278
  repoSlug: repoContext.repoSlug,
@@ -23673,9 +23720,10 @@ function bootstrap(options = {}) {
23673
23720
  });
23674
23721
  container.register(ServiceTokens.ListPRsCommand, () => {
23675
23722
  const pullrequestsApi = container.resolve(ServiceTokens.PullrequestsApi);
23723
+ const usersApi = container.resolve(ServiceTokens.UsersApi);
23676
23724
  const contextService = container.resolve(ServiceTokens.ContextService);
23677
23725
  const output = container.resolve(ServiceTokens.OutputService);
23678
- return new ListPRsCommand(pullrequestsApi, contextService, output);
23726
+ return new ListPRsCommand(pullrequestsApi, usersApi, contextService, output);
23679
23727
  });
23680
23728
  container.register(ServiceTokens.ViewPRCommand, () => {
23681
23729
  const pullrequestsApi = container.resolve(ServiceTokens.PullrequestsApi);
@@ -24061,10 +24109,11 @@ prCmd.command("create").description("Create a pull request").option("-t, --title
24061
24109
  const context = createContext(cli);
24062
24110
  await runCommand(ServiceTokens.CreatePRCommand, withGlobalOptions(options, context), cli, context);
24063
24111
  });
24064
- 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").addHelpText("after", buildHelpText({
24112
+ 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").option("--mine", "Show only PRs where you are a reviewer").addHelpText("after", buildHelpText({
24065
24113
  examples: [
24066
24114
  "bb pr list",
24067
24115
  "bb pr list -s MERGED --limit 10",
24116
+ "bb pr list --mine",
24068
24117
  "bb pr list --json"
24069
24118
  ],
24070
24119
  validValues: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pilatos/bitbucket-cli",
3
- "version": "1.8.4",
3
+ "version": "1.9.1",
4
4
  "description": "A command-line interface for Bitbucket Cloud",
5
5
  "author": "",
6
6
  "license": "MIT",