pingcode-cli-unofficial 2.1.0 → 2.2.0

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.
@@ -3359,6 +3359,7 @@ function errorPayload(error) {
3359
3359
  const message = error instanceof Error ? error.message : String(error);
3360
3360
  const payload = { kind, message: redactSnippet(redactUrl(message)), exit };
3361
3361
  if (error instanceof PingcodeError && error.code !== void 0) payload.code = error.code;
3362
+ if (error instanceof PingcodeError && error.hint !== void 0) payload.hint = error.hint;
3362
3363
  return payload;
3363
3364
  }
3364
3365
  function printError(error, mode) {
@@ -3425,7 +3426,7 @@ var VERSION;
3425
3426
  var init_version = __esm({
3426
3427
  "src/version.ts"() {
3427
3428
  "use strict";
3428
- VERSION = "2.1.0";
3429
+ VERSION = "2.2.0";
3429
3430
  }
3430
3431
  });
3431
3432
 
@@ -8476,6 +8477,7 @@ function parseWorkItem(raw) {
8476
8477
  if (single !== void 0) versions = [single];
8477
8478
  }
8478
8479
  const properties = typeof record.properties === "object" && record.properties !== null && !Array.isArray(record.properties) ? record.properties : void 0;
8480
+ const sprint = parseRef(record.sprint);
8479
8481
  return {
8480
8482
  ...record,
8481
8483
  id: asString2(record.id) ?? "",
@@ -8486,12 +8488,12 @@ function parseWorkItem(raw) {
8486
8488
  title: asString2(record.title),
8487
8489
  description: asString2(record.description),
8488
8490
  type: parseWorkItemTypeField(record.type),
8489
- state: parseRef(record.state),
8491
+ state: parseWorkItemStateField(record.state),
8490
8492
  priority: parseRef(record.priority),
8491
8493
  assignee: parseRef(record.assignee),
8492
8494
  project: parseRef(record.project),
8493
8495
  parent: parseRef(record.parent),
8494
- sprint: parseRef(record.sprint),
8496
+ sprint,
8495
8497
  board: parseRef(record.board),
8496
8498
  entry: parseRef(record.entry),
8497
8499
  swimlane: parseRef(record.swimlane),
@@ -8511,7 +8513,8 @@ function parseWorkItem(raw) {
8511
8513
  remaining_workload: asNumber(record.remaining_workload),
8512
8514
  properties,
8513
8515
  is_archived: asBooleanFlag(record.is_archived),
8514
- is_deleted: asBooleanFlag(record.is_deleted)
8516
+ is_deleted: asBooleanFlag(record.is_deleted),
8517
+ sprint_id: asString2(record.sprint_id) ?? sprint?.id
8515
8518
  };
8516
8519
  }
8517
8520
  function parseWorkItemType(raw) {
@@ -8527,6 +8530,10 @@ function parseWorkItemTypeField(raw) {
8527
8530
  if (typeof raw === "string" && raw !== "") return raw;
8528
8531
  return parseRef(raw);
8529
8532
  }
8533
+ function parseWorkItemStateField(raw) {
8534
+ if (typeof raw === "string" && raw !== "") return raw;
8535
+ return parseRef(raw);
8536
+ }
8530
8537
  function parseWorkItemState(raw) {
8531
8538
  const record = asRecord(raw);
8532
8539
  return {
@@ -11822,7 +11829,7 @@ function registerTicketCommands(parent) {
11822
11829
  await runGet3(target, command);
11823
11830
  });
11824
11831
  addGlobalOptions(
11825
- group2.command("create").description("create a ticket (--type is required by the API, unlike idea)").requiredOption("--product <name|id>", "product name, identifier or id").requiredOption("--type <name|id>", "ticket type \u2014 list them with `meta ticket-types`").requiredOption("--title <text>", "title, max 255 characters").option("--description <text>", "description").option("--assignee <name|id>", "assignee \u2014 must be a member of this product").option("--priority <name|id>", "priority").option("--channel <name|id>", "submission channel \u2014 can only be set here, never patched").option("--set <key=value>", SET_HELP2, collectValue),
11832
+ group2.command("create").description("create a ticket (--type is required by the API, unlike idea)").requiredOption("--product <name|id>", "product name, identifier or id").requiredOption("--type <name|id>", "ticket type \u2014 list them with `meta ticket-types`").requiredOption("--title <text>", "title, max 255 characters").option("--description <text>", "description").option("--assignee <name|id>", "assignee \u2014 must be a member of this product").option("--priority <name|id>", "priority").option("--channel <name|id>", 'submission channel \u2014 use "internal" for the web default (server-decided)').option("--customer <name|id>", "customer \u5BA2\u6237 \u2014 scoped to this product").option("--set <key=value>", SET_HELP2, collectValue),
11826
11833
  { hidden: true }
11827
11834
  ).action(async (flags, command) => {
11828
11835
  await runCreate3(flags, command);
@@ -11935,12 +11942,31 @@ async function runCreate3(flags, command) {
11935
11942
  const { ctx } = contextFor(command);
11936
11943
  const title = requireFlag(flags.title, "--title");
11937
11944
  const assignments = parseSetFlags(flags.set, SET_HINT3);
11945
+ let internalFallbackUsed = false;
11938
11946
  const resolve = async (attemptCtx) => {
11939
11947
  const product = await resolveProduct(attemptCtx, flags.product);
11940
11948
  const type = await resolveTicketType(attemptCtx, product.id, flags.type);
11941
11949
  const assignee = flags.assignee === void 0 ? void 0 : await resolveProductMember(attemptCtx, product.id, flags.assignee);
11942
11950
  const priority = flags.priority === void 0 ? void 0 : await resolveTicketPriority(attemptCtx, product.id, flags.priority);
11943
- const channel = flags.channel === void 0 ? void 0 : await resolveTicketChannel(attemptCtx, product.id, flags.channel);
11951
+ let channel;
11952
+ if (flags.channel !== void 0) {
11953
+ try {
11954
+ channel = await resolveTicketChannel(attemptCtx, product.id, flags.channel);
11955
+ } catch (raw) {
11956
+ const isInternal = raw instanceof UsageError && typeof flags.channel === "string" && flags.channel.trim().toLowerCase() === "internal";
11957
+ const noMatch = isInternal && raw.message.startsWith("no ticket channel matches");
11958
+ if (noMatch) {
11959
+ channel = void 0;
11960
+ if (!internalFallbackUsed) {
11961
+ internalFallbackUsed = true;
11962
+ errLine(paint.dim(`channel "internal" is the web default \u2014 letting the server decide`));
11963
+ }
11964
+ } else {
11965
+ throw raw;
11966
+ }
11967
+ }
11968
+ }
11969
+ const customer = flags.customer === void 0 ? void 0 : await resolveTicketCustomer(attemptCtx, product.id, flags.customer);
11944
11970
  const properties = await resolveProperties2(attemptCtx, product.id, assignments);
11945
11971
  const input = {
11946
11972
  product_id: product.id,
@@ -11950,10 +11976,11 @@ async function runCreate3(flags, command) {
11950
11976
  ...assignee === void 0 ? {} : { assignee_id: assignee.id },
11951
11977
  ...priority === void 0 ? {} : { priority_id: priority.id },
11952
11978
  ...channel === void 0 ? {} : { channel_id: channel.id },
11979
+ ...customer === void 0 ? {} : { customer_id: customer.id },
11953
11980
  ...properties.value === void 0 ? {} : { properties: properties.value }
11954
11981
  };
11955
11982
  return {
11956
- resolutions: present([product, type, assignee, priority, channel, ...properties.resolutions]),
11983
+ resolutions: present([product, type, assignee, priority, channel, customer, ...properties.resolutions]),
11957
11984
  value: input
11958
11985
  };
11959
11986
  };
@@ -12233,14 +12260,21 @@ function registerProductPlanCommands(parent) {
12233
12260
  }
12234
12261
  function registerProductMetaCommands(parent) {
12235
12262
  const meta = parent.command("meta").description("ids you need before writing: every ship lookup is scoped to one product");
12236
- function productScoped(name, description, load, columns) {
12263
+ function productScoped(name, description, load, columns, onError) {
12237
12264
  addGlobalOptions(
12238
12265
  meta.command(name).description(description).requiredOption("--product <name|id>", "product name, identifier such as SLC, or id"),
12239
12266
  { hidden: true }
12240
12267
  ).action(async (flags, command) => {
12241
12268
  const { ctx } = contextFor(command);
12242
12269
  const resolved = await resolveProduct(ctx, flags.product);
12243
- printCollection(await load(ctx, resolved.id), columns, modeOf(ctx));
12270
+ try {
12271
+ printCollection(await load(ctx, resolved.id), columns, modeOf(ctx));
12272
+ } catch (raw) {
12273
+ if (onError !== void 0) {
12274
+ await onError(raw);
12275
+ }
12276
+ throw raw;
12277
+ }
12244
12278
  });
12245
12279
  }
12246
12280
  productScoped(
@@ -12283,7 +12317,18 @@ function registerProductMetaCommands(parent) {
12283
12317
  "ticket-states",
12284
12318
  "ticket states of a product (values for --state / state_id)",
12285
12319
  listTicketStates,
12286
- SHIP_STATE_COLUMNS
12320
+ SHIP_STATE_COLUMNS,
12321
+ async (raw) => {
12322
+ if (raw instanceof ApiError && raw.status !== void 0 && raw.status >= 500) {
12323
+ throw new ApiError(raw.message, {
12324
+ code: raw.code,
12325
+ status: raw.status,
12326
+ cause: raw,
12327
+ hint: "The endpoint is currently unavailable (server error); creating a ticket does not need it \u2014 the initial state is decided by the server; only `ticket transition` and `list --state` need it."
12328
+ });
12329
+ }
12330
+ throw raw;
12331
+ }
12287
12332
  );
12288
12333
  productScoped(
12289
12334
  "ticket-priorities",
@@ -12381,6 +12426,7 @@ var init_product = __esm({
12381
12426
  "use strict";
12382
12427
  init_ship2();
12383
12428
  init_metadata();
12429
+ init_errors();
12384
12430
  init_paginate();
12385
12431
  init_globals();
12386
12432
  init_common();
@@ -13548,6 +13594,10 @@ function typeLabelOf(type) {
13548
13594
  if (typeof type === "string") return type;
13549
13595
  return refName(type);
13550
13596
  }
13597
+ function stateLabelOf(state) {
13598
+ if (typeof state === "string") return state;
13599
+ return refName(state);
13600
+ }
13551
13601
  function registerWorkItemCommands(parent) {
13552
13602
  const group2 = parent.command("work-item").description("work items (scopes pcp:read:pjm:workitem / pcp:write:pjm:workitem)");
13553
13603
  addGlobalOptions(
@@ -14267,7 +14317,7 @@ function printWorkItem(item, ctx, verb) {
14267
14317
  ["id", item.id],
14268
14318
  ["title", item.title ?? ""],
14269
14319
  ["type", typeLabelOf(item.type)],
14270
- ["state", refName(item.state)],
14320
+ ["state", stateLabelOf(item.state)],
14271
14321
  ["priority", refName(item.priority)],
14272
14322
  ["assignee", refName(item.assignee)],
14273
14323
  ["project", refName(item.project)],
@@ -14578,7 +14628,7 @@ var init_workItem = __esm({
14578
14628
  { header: "IDENTIFIER", value: (item) => item.identifier ?? item.short_id ?? item.id },
14579
14629
  { header: "TITLE", value: (item) => item.title ?? "", flex: true },
14580
14630
  { header: "TYPE", value: (item) => typeLabelOf(item.type) },
14581
- { header: "STATE", value: (item) => refName(item.state) },
14631
+ { header: "STATE", value: (item) => stateLabelOf(item.state) },
14582
14632
  { header: "ASSIGNEE", value: (item) => refName(item.assignee) },
14583
14633
  { header: "END", value: (item) => timestampCell(item.end_at) }
14584
14634
  ];