@allocator-one/harness-cli 1.4.0 → 1.5.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.
@@ -1238,8 +1238,13 @@ async function linkRm(ctx, issue, idOrUrl) {
1238
1238
  async function labelList(ctx) {
1239
1239
  const body = await ctx.client.get("/api/v1/labels");
1240
1240
  const human = body.data.length === 0 ? "No labels.\n" : table(
1241
- ["NAME", "COLOR", "ID"],
1242
- body.data.map((label) => [str3(label["name"]), str3(label["color"]) || "-", str3(label["id"])])
1241
+ ["NAME", "COLOR", "ISSUES", "ID"],
1242
+ body.data.map((label) => [
1243
+ str3(label["name"]),
1244
+ str3(label["color"]) || "-",
1245
+ str3(label["issue_count"] ?? 0),
1246
+ str3(label["id"])
1247
+ ])
1243
1248
  );
1244
1249
  return { json: body.data, human };
1245
1250
  }
@@ -1272,8 +1277,13 @@ async function teamCreate(ctx, opts) {
1272
1277
  async function teamList(ctx) {
1273
1278
  const body = await ctx.client.get("/api/v1/teams");
1274
1279
  const human = body.data.length === 0 ? "No teams.\n" : table(
1275
- ["KEY", "NAME"],
1276
- body.data.map((team) => [str3(team["key"]), str3(team["name"])])
1280
+ ["KEY", "NAME", "ISSUES", "DEFAULT"],
1281
+ body.data.map((team) => [
1282
+ str3(team["key"]),
1283
+ str3(team["name"]),
1284
+ str3(team["issue_count"] ?? 0),
1285
+ team["is_default"] === true ? "yes" : ""
1286
+ ])
1277
1287
  );
1278
1288
  return { json: body.data, human };
1279
1289
  }
@@ -1281,8 +1291,13 @@ async function workflowStates(ctx, team) {
1281
1291
  const key = requiredTeam({ client: ctx.client, config: ctx.config }, team);
1282
1292
  const body = await ctx.client.get(`/api/v1/teams/${key}/workflow_states`);
1283
1293
  const human = body.data.length === 0 ? "No workflow states.\n" : table(
1284
- ["NAME", "TYPE"],
1285
- body.data.map((state) => [str3(state["name"]), str3(state["type"])])
1294
+ ["NAME", "TYPE", "COLOR", "ID"],
1295
+ body.data.map((state) => [
1296
+ str3(state["name"]),
1297
+ str3(state["type"]),
1298
+ str3(state["color"]) || "-",
1299
+ str3(state["id"])
1300
+ ])
1286
1301
  );
1287
1302
  return { json: body.data, human };
1288
1303
  }
@@ -1294,6 +1309,128 @@ async function userList(ctx) {
1294
1309
  );
1295
1310
  return { json: body.data, human };
1296
1311
  }
1312
+ async function teamRename(ctx, key, name) {
1313
+ if (key === void 0 || name === void 0) {
1314
+ throw new UsageError("usage: harness team rename <key> --name <name>");
1315
+ }
1316
+ const body = await ctx.client.patch(`/api/v1/teams/${encodeURIComponent(key)}`, { name });
1317
+ return { json: body.data, human: `Renamed ${str3(body.data["key"])} to ${clean(body.data["name"])}
1318
+ ` };
1319
+ }
1320
+ async function teamSetDefault(ctx, key) {
1321
+ if (key === void 0) throw new UsageError("usage: harness team set-default <key>");
1322
+ const body = await ctx.client.put(`/api/v1/teams/${encodeURIComponent(key)}/default`, {});
1323
+ return {
1324
+ json: body.data,
1325
+ human: `${str3(body.data["key"])} is now the default filing target
1326
+ `
1327
+ };
1328
+ }
1329
+ async function stateAdd(ctx, opts) {
1330
+ const key = requiredTeam({ client: ctx.client, config: ctx.config }, opts.team);
1331
+ if (opts.name === void 0 || opts.type === void 0) {
1332
+ throw new UsageError("usage: harness state add --name <name> --type <type> [--color <color>] [--team <key>]");
1333
+ }
1334
+ let payload = { name: opts.name, type: opts.type };
1335
+ payload = putOpt2(payload, "color", opts.color);
1336
+ const body = await ctx.client.post(`/api/v1/teams/${key}/workflow_states`, payload);
1337
+ return { json: body.data, human: `Added ${clean(body.data["name"])} to ${key}
1338
+ ` };
1339
+ }
1340
+ async function stateUpdate(ctx, id, opts) {
1341
+ const key = requiredTeam({ client: ctx.client, config: ctx.config }, opts.team);
1342
+ if (id === void 0) throw new UsageError("usage: harness state update <id> [--name <name>] [--type <type>] [--color <color>]");
1343
+ if (opts.name === void 0 && opts.type === void 0 && opts.color === void 0) {
1344
+ throw new UsageError("nothing to change \u2014 pass at least one of --name, --type, --color");
1345
+ }
1346
+ let payload = {};
1347
+ payload = putOpt2(payload, "name", opts.name);
1348
+ payload = putOpt2(payload, "type", opts.type);
1349
+ payload = putOpt2(payload, "color", opts.color);
1350
+ const body = await ctx.client.patch(`/api/v1/teams/${key}/workflow_states/${encodeURIComponent(id)}`, payload);
1351
+ return { json: body.data, human: `Updated ${clean(body.data["name"])}
1352
+ ` };
1353
+ }
1354
+ async function stateOrder(ctx, ids, opts) {
1355
+ const key = requiredTeam({ client: ctx.client, config: ctx.config }, opts.team);
1356
+ if (ids === void 0) {
1357
+ throw new UsageError("usage: harness state order <id,id,id> [--team <key>] \u2014 every state id, in the order you want");
1358
+ }
1359
+ const state_ids = ids.split(",").map((id) => id.trim()).filter((id) => id !== "");
1360
+ if (state_ids.length === 0) throw new UsageError("no state ids given");
1361
+ const body = await ctx.client.put(`/api/v1/teams/${key}/workflow_states/order`, { state_ids });
1362
+ const human = table(
1363
+ ["NAME", "TYPE"],
1364
+ body.data.map((state) => [str3(state["name"]), str3(state["type"])])
1365
+ );
1366
+ return { json: body.data, human };
1367
+ }
1368
+ async function stateDelete(ctx, id, opts) {
1369
+ const key = requiredTeam({ client: ctx.client, config: ctx.config }, opts.team);
1370
+ if (id === void 0) throw new UsageError("usage: harness state delete <id> --yes [--team <key>]");
1371
+ requireYes("state delete", id, opts.yes);
1372
+ await ctx.client.delete(`/api/v1/teams/${key}/workflow_states/${encodeURIComponent(id)}`);
1373
+ return { json: { deleted: id }, human: `Deleted workflow state ${id}
1374
+ ` };
1375
+ }
1376
+ async function labelUpdate(ctx, id, opts) {
1377
+ if (id === void 0) throw new UsageError("usage: harness label update <id> [--name <name>] [--color <color>]");
1378
+ if (opts.name === void 0 && opts.color === void 0) {
1379
+ throw new UsageError("nothing to change \u2014 pass --name, --color, or both");
1380
+ }
1381
+ let payload = {};
1382
+ payload = putOpt2(payload, "name", opts.name);
1383
+ payload = putOpt2(payload, "color", opts.color);
1384
+ const body = await ctx.client.patch(`/api/v1/labels/${encodeURIComponent(id)}`, payload);
1385
+ return { json: body.data, human: `Updated label ${clean(body.data["name"])}
1386
+ ` };
1387
+ }
1388
+ async function labelDelete(ctx, id, opts) {
1389
+ if (id === void 0) throw new UsageError("usage: harness label delete <id> --yes");
1390
+ requireYes("label delete", id, opts.yes);
1391
+ await ctx.client.delete(`/api/v1/labels/${encodeURIComponent(id)}`);
1392
+ return { json: { deleted: id }, human: `Deleted label ${id}
1393
+ ` };
1394
+ }
1395
+ async function memberList(ctx) {
1396
+ const body = await ctx.client.get("/api/v1/members");
1397
+ const human = body.data.length === 0 ? "No members.\n" : table(
1398
+ ["NAME", "EMAIL", "RANK", "STANDING", "ID"],
1399
+ body.data.map((member) => [
1400
+ str3(field(member, "user", "name")),
1401
+ str3(field(member, "user", "email")),
1402
+ str3(member["role"]) || "-",
1403
+ str3(member["standing"]),
1404
+ str3(field(member, "user", "id"))
1405
+ ])
1406
+ );
1407
+ return { json: body.data, human };
1408
+ }
1409
+ async function memberAdd(ctx, opts) {
1410
+ if (opts.email === void 0 || opts.role === void 0) {
1411
+ throw new UsageError("usage: harness member add --email <email> --role <admin|staff|collaborator>");
1412
+ }
1413
+ const body = await ctx.client.post("/api/v1/members", { email: opts.email, role: opts.role });
1414
+ return {
1415
+ json: body.data,
1416
+ human: `Added ${str3(field(body.data, "user", "email"))} as ${str3(body.data["role"])}
1417
+ `
1418
+ };
1419
+ }
1420
+ async function memberSetRole(ctx, userId, opts) {
1421
+ if (userId === void 0 || opts.role === void 0) {
1422
+ throw new UsageError("usage: harness member set-role <user-id> --role <admin|staff|collaborator|none>");
1423
+ }
1424
+ const body = await ctx.client.put(`/api/v1/members/${encodeURIComponent(userId)}/role`, { role: opts.role });
1425
+ const rank = str3(body.data["role"]);
1426
+ const human = rank === "" ? `Revoked the rank for ${str3(field(body.data, "user", "email"))}
1427
+ ` : `${str3(field(body.data, "user", "email"))} is now ${rank}
1428
+ `;
1429
+ return { json: body.data, human };
1430
+ }
1431
+ function requireYes(command, id, yes) {
1432
+ if (yes !== true) throw new UsageError(`${command} ${id} is destructive \u2014 pass --yes to confirm`);
1433
+ }
1297
1434
  async function upload(ctx, path2) {
1298
1435
  return attachImage(ctx, path2);
1299
1436
  }
@@ -1586,6 +1723,17 @@ export {
1586
1723
  teamList,
1587
1724
  workflowStates,
1588
1725
  userList,
1726
+ teamRename,
1727
+ teamSetDefault,
1728
+ stateAdd,
1729
+ stateUpdate,
1730
+ stateOrder,
1731
+ stateDelete,
1732
+ labelUpdate,
1733
+ labelDelete,
1734
+ memberList,
1735
+ memberAdd,
1736
+ memberSetRole,
1589
1737
  upload,
1590
1738
  defaultCredentialsPath,
1591
1739
  readCredentials,