@argos-ci/cli 6.6.1 → 6.7.1-alpha.1.sha-4c8577c
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.
- package/dist/index.mjs +1459 -56
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -2,23 +2,59 @@ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { Option, program } from "commander";
|
|
5
|
-
import { deploy, finalize, skip, upload } from "@argos-ci/core";
|
|
5
|
+
import { deploy, finalize, skip, upload, uploadMedia } from "@argos-ci/core";
|
|
6
6
|
import ora from "ora";
|
|
7
7
|
import { APIError, createClient, throwAPIError } from "@argos-ci/api-client";
|
|
8
8
|
import { homedir } from "node:os";
|
|
9
9
|
import { createHash, randomBytes } from "node:crypto";
|
|
10
10
|
import { createServer } from "node:http";
|
|
11
11
|
import open from "open";
|
|
12
|
+
//#region src/lib/cli-error.ts
|
|
13
|
+
/**
|
|
14
|
+
* Error whose message is meant to be shown to the user verbatim (prefixed with
|
|
15
|
+
* `Error: `) before the CLI exits with a non-zero code. Throw it — via
|
|
16
|
+
* {@link fail} — instead of calling `process.exit` directly so the failure can
|
|
17
|
+
* be unit-tested and handled in a single place ({@link handleCliError}).
|
|
18
|
+
*/
|
|
19
|
+
var CliError = class extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "CliError";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Abort the current command with a user-facing message.
|
|
27
|
+
*/
|
|
28
|
+
function fail(message) {
|
|
29
|
+
throw new CliError(message);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
12
32
|
//#region src/options.ts
|
|
13
33
|
const parallelNonceOption = new Option("--parallel-nonce <string>", "A unique ID for this parallel build");
|
|
14
34
|
const tokenOption = new Option("--token <token>", "Repository token");
|
|
15
35
|
const projectOption = new Option("--project <slug>", "Argos project slug (account/project), used to disambiguate tokenless authentication when multiple projects are linked to the same repository");
|
|
16
36
|
const buildNameOption = new Option("--build-name <string>", "Name of the build, in case you want to run multiple Argos builds in a single CI job");
|
|
17
37
|
const accountOption = new Option("--account <slug>", "Slug of the account (personal or team) that will own the project");
|
|
38
|
+
const accountSlugOption = new Option("--account <slug>", "Slug of the account (personal or team) to act on. Also ARGOS_ACCOUNT");
|
|
18
39
|
const jsonOption = new Option("--json", "Output machine-readable JSON instead of human-readable text");
|
|
19
40
|
const projectPathOption = new Option("--project <owner/project>", "Project path in owner/project format. Required for build-number references on review and comment commands");
|
|
20
41
|
const changeProjectPathOption = new Option("--project <owner/project>", "Project the change belongs to, in owner/project format. Also ARGOS_PROJECT");
|
|
21
42
|
const testProjectPathOption = new Option("--project <owner/project>", "Project the test belongs to, in owner/project format. Also ARGOS_PROJECT. Optional with a project token, which already identifies its project");
|
|
43
|
+
const mediaProjectPathOption = new Option("--project <owner/project>", "Project the media belongs to, in owner/project format. Also ARGOS_PROJECT. Optional with a project token, which already identifies its project");
|
|
44
|
+
const managedProjectPathOption = new Option("--project <owner/project>", "Project to act on, in owner/project format. Also ARGOS_PROJECT");
|
|
45
|
+
const limitOption = new Option("--limit <number>", "Maximum number of items to fetch, following pagination as needed").default(String(100));
|
|
46
|
+
/** Parse a `--limit` value into a positive integer, or abort. */
|
|
47
|
+
function toLimit(value) {
|
|
48
|
+
const limit = Number(value);
|
|
49
|
+
if (!Number.isInteger(limit) || limit < 1) fail(`--limit must be a positive integer, received "${value}".`);
|
|
50
|
+
return limit;
|
|
51
|
+
}
|
|
52
|
+
/** Parse a `--pr` value into a pull request number, or abort. */
|
|
53
|
+
function toPrNumber(value) {
|
|
54
|
+
const prNumber = Number(value);
|
|
55
|
+
if (!Number.isInteger(prNumber) || prNumber < 1) fail(`--pr must be a positive integer, received "${value}".`);
|
|
56
|
+
return prNumber;
|
|
57
|
+
}
|
|
22
58
|
const METRICS_PERIOD_BY_CHOICE = {
|
|
23
59
|
"24h": "LAST_24_HOURS",
|
|
24
60
|
"3d": "LAST_3_DAYS",
|
|
@@ -142,6 +178,13 @@ function unwrap(result) {
|
|
|
142
178
|
if (result.data === void 0 || result.data === null) throw new APIError("Unexpected empty response from API.", { status: result.response.status });
|
|
143
179
|
return result.data;
|
|
144
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Like {@link unwrap} for endpoints that answer `204 No Content`: it only
|
|
183
|
+
* checks the request succeeded, since there is no body to return.
|
|
184
|
+
*/
|
|
185
|
+
function unwrapEmpty(result) {
|
|
186
|
+
if (!result.response.ok) throwAPIError(result.error, result.response);
|
|
187
|
+
}
|
|
145
188
|
//#endregion
|
|
146
189
|
//#region src/lib/format.ts
|
|
147
190
|
/** Render a scalar, using `-` for empty values. */
|
|
@@ -149,6 +192,10 @@ function formatValue(value) {
|
|
|
149
192
|
if (value === null || value === void 0 || value === "") return "-";
|
|
150
193
|
return String(value);
|
|
151
194
|
}
|
|
195
|
+
/** Render a flag as `yes` / `no`. */
|
|
196
|
+
function formatBoolean(value) {
|
|
197
|
+
return value ? "yes" : "no";
|
|
198
|
+
}
|
|
152
199
|
function formatUser(user) {
|
|
153
200
|
if (!user) return "-";
|
|
154
201
|
return user.name ? `${user.name} (@${user.slug})` : `@${user.slug}`;
|
|
@@ -160,7 +207,7 @@ function formatMe(user) {
|
|
|
160
207
|
`Name: ${formatValue(user.name)}`
|
|
161
208
|
].join("\n");
|
|
162
209
|
}
|
|
163
|
-
function
|
|
210
|
+
function formatCreatedProject(project) {
|
|
164
211
|
return [
|
|
165
212
|
`Created project ${project.account.slug}/${project.name}.`,
|
|
166
213
|
`ID: ${project.id}`,
|
|
@@ -169,6 +216,27 @@ function formatProject(project) {
|
|
|
169
216
|
`Default base branch: ${formatValue(project.defaultBaseBranch)}`
|
|
170
217
|
].join("\n");
|
|
171
218
|
}
|
|
219
|
+
function formatProject(project) {
|
|
220
|
+
return [
|
|
221
|
+
`Project ${project.account.slug}/${project.name}`,
|
|
222
|
+
`ID: ${project.id}`,
|
|
223
|
+
`Visibility: ${project.private ? "private" : "public"}`,
|
|
224
|
+
`Default base branch: ${formatValue(project.defaultBaseBranch)}`,
|
|
225
|
+
`Auto-approved branches: ${formatValue(project.autoApprovedBranchGlob)}`,
|
|
226
|
+
`Summary check: ${project.summaryCheck}`,
|
|
227
|
+
`PR comment: ${formatBoolean(project.prCommentEnabled)}`,
|
|
228
|
+
`Default user level: ${formatValue(project.defaultUserLevel)}`,
|
|
229
|
+
`Ignore changes: ${formatIgnoreConfig(project.ignoreConfig)}`,
|
|
230
|
+
`Deployments: ${formatBoolean(project.deploymentEnabled)} (${project.deploymentAuth}, production branches ${formatValue(project.deploymentProductionBranchGlob)})`,
|
|
231
|
+
`GitHub Actions OIDC: ${formatBoolean(project.githubActionsOidcEnabled)}`,
|
|
232
|
+
`Tokenless auth: ${formatBoolean(project.tokenlessAuthEnabled)}`
|
|
233
|
+
].join("\n");
|
|
234
|
+
}
|
|
235
|
+
function formatIgnoreConfig(config) {
|
|
236
|
+
if (!config.enabled) return "disabled";
|
|
237
|
+
const autoIgnore = config.autoIgnore;
|
|
238
|
+
return autoIgnore ? `enabled, auto-ignore after ${autoIgnore.changes} occurrences` : "enabled, auto-ignore off";
|
|
239
|
+
}
|
|
172
240
|
function formatStats(stats) {
|
|
173
241
|
if (!stats) return "-";
|
|
174
242
|
return [
|
|
@@ -349,13 +417,25 @@ function formatReactions(reactions) {
|
|
|
349
417
|
if (reactions.length === 0) return null;
|
|
350
418
|
return reactions.map((r) => `${r.emoji} ${r.count}`).join(" ");
|
|
351
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* What a comment points at: the diff or the spot on the media, and the upload that
|
|
422
|
+
* spot describes.
|
|
423
|
+
*
|
|
424
|
+
* Shared by the single-comment and list renderings, because a pin a listing does
|
|
425
|
+
* not print is a review an agent cannot act on.
|
|
426
|
+
*/
|
|
427
|
+
function formatCommentTarget(comment) {
|
|
428
|
+
const lines = [];
|
|
429
|
+
const anchor = formatAnchor(comment.anchor);
|
|
430
|
+
if (comment.screenshotDiffId) lines.push(`Diff: ${comment.screenshotDiffId}${anchor ? ` (${anchor})` : ""}`);
|
|
431
|
+
else if (anchor) lines.push(`Pinned: ${anchor}`);
|
|
432
|
+
if (comment.mediaVersionId) lines.push(`Media version: ${comment.mediaVersionId}`);
|
|
433
|
+
return lines;
|
|
434
|
+
}
|
|
352
435
|
function formatComment(comment) {
|
|
353
436
|
const lines = [`Comment #${comment.id}`, `Author: ${formatUser(comment.author)}`];
|
|
354
437
|
if (comment.threadId) lines.push(`Reply to: ${comment.threadId}`);
|
|
355
|
-
|
|
356
|
-
const anchor = formatAnchor(comment.anchor);
|
|
357
|
-
lines.push(`Diff: ${comment.screenshotDiffId}${anchor ? ` (${anchor})` : ""}`);
|
|
358
|
-
}
|
|
438
|
+
lines.push(...formatCommentTarget(comment));
|
|
359
439
|
if (comment.pending) lines.push("Pending: draft (only visible to you)");
|
|
360
440
|
if (comment.resolvedAt) lines.push(`Resolved: ${comment.resolvedAt}`);
|
|
361
441
|
const reactions = formatReactions(comment.reactions);
|
|
@@ -377,31 +457,243 @@ function formatComments(comments) {
|
|
|
377
457
|
].filter(Boolean);
|
|
378
458
|
return [
|
|
379
459
|
`#${comment.id} [${tags.join(", ")}] ${formatUser(comment.author)}`,
|
|
460
|
+
...formatCommentTarget(comment).map((line) => indent(line)),
|
|
380
461
|
indent(comment.text),
|
|
381
462
|
""
|
|
382
463
|
];
|
|
383
464
|
})
|
|
384
465
|
].slice(0, -1).join("\n");
|
|
385
466
|
}
|
|
386
|
-
|
|
387
|
-
|
|
467
|
+
function formatAccount(account) {
|
|
468
|
+
const lines = [
|
|
469
|
+
`Account ${account.slug} (${account.type})`,
|
|
470
|
+
`ID: ${account.id}`,
|
|
471
|
+
`Name: ${formatValue(account.name)}`,
|
|
472
|
+
`Plan: ${formatValue(account.plan?.name)}`,
|
|
473
|
+
`Period: ${formatValue(account.periodStartDate)} → ${formatValue(account.periodEndDate)}`,
|
|
474
|
+
`Screenshots: ${account.currentPeriodScreenshots} / ${account.includedScreenshots} (${Math.round(account.consumptionRatio * 100)}%)`
|
|
475
|
+
];
|
|
476
|
+
if (account.additionalScreenshotsCost > 0) lines.push(`Additional screenshots cost: ${account.additionalScreenshotsCost}`);
|
|
477
|
+
if (account.defaultUserLevel) lines.push(`Default user level: ${account.defaultUserLevel}`);
|
|
478
|
+
return lines.join("\n");
|
|
479
|
+
}
|
|
480
|
+
function formatMembers(members) {
|
|
481
|
+
if (members.length === 0) return "No members found.";
|
|
482
|
+
return [
|
|
483
|
+
`Members (${members.length})`,
|
|
484
|
+
"",
|
|
485
|
+
...members.map((member) => `${formatUser(member.user)} [${member.level}] · user ${member.user.id}`)
|
|
486
|
+
].join("\n");
|
|
487
|
+
}
|
|
488
|
+
function formatMember(member) {
|
|
489
|
+
return [
|
|
490
|
+
`Member ${formatUser(member.user)}`,
|
|
491
|
+
`Level: ${member.level}`,
|
|
492
|
+
`User ID: ${member.user.id}`
|
|
493
|
+
].join("\n");
|
|
494
|
+
}
|
|
495
|
+
function formatInvites(invites) {
|
|
496
|
+
if (invites.length === 0) return "No pending invites found.";
|
|
497
|
+
return [
|
|
498
|
+
`Invites (${invites.length})`,
|
|
499
|
+
"",
|
|
500
|
+
...invites.map((invite) => `${invite.email} [${invite.level}${invite.expired ? ", expired" : ""}] · ${invite.id} · expires ${invite.expiresAt}`)
|
|
501
|
+
].join("\n");
|
|
502
|
+
}
|
|
503
|
+
function formatInviteLink(link) {
|
|
504
|
+
return `Invite link: ${link.inviteLink}`;
|
|
505
|
+
}
|
|
506
|
+
function formatDomains(domains) {
|
|
507
|
+
if (domains.length === 0) return "No email domains found.";
|
|
508
|
+
return [
|
|
509
|
+
`Email domains (${domains.length})`,
|
|
510
|
+
"",
|
|
511
|
+
...domains.map((domain) => `${domain.domain} · added ${domain.createdAt}`)
|
|
512
|
+
].join("\n");
|
|
513
|
+
}
|
|
514
|
+
function formatDomain(domain) {
|
|
515
|
+
return [`Domain ${domain.domain}`, `Added: ${domain.createdAt}`].join("\n");
|
|
516
|
+
}
|
|
517
|
+
function formatContributors(contributors) {
|
|
518
|
+
if (contributors.length === 0) return "No contributors found.";
|
|
519
|
+
return [
|
|
520
|
+
`Contributors (${contributors.length})`,
|
|
521
|
+
"",
|
|
522
|
+
...contributors.map((contributor) => `${formatUser(contributor.user)} [${contributor.level}] · user ${contributor.user.id}`)
|
|
523
|
+
].join("\n");
|
|
524
|
+
}
|
|
525
|
+
function formatContributor(contributor) {
|
|
526
|
+
return [
|
|
527
|
+
`Contributor ${formatUser(contributor.user)}`,
|
|
528
|
+
`Level: ${contributor.level}`,
|
|
529
|
+
`User ID: ${contributor.user.id}`
|
|
530
|
+
].join("\n");
|
|
531
|
+
}
|
|
532
|
+
function formatDeployments(deployments) {
|
|
533
|
+
if (deployments.length === 0) return "No deployments found.";
|
|
534
|
+
return [
|
|
535
|
+
`Deployments (${deployments.length})`,
|
|
536
|
+
"",
|
|
537
|
+
...deployments.flatMap((deployment) => [
|
|
538
|
+
`${deployment.id} [${deployment.status}, ${deployment.environment}]`,
|
|
539
|
+
` Branch: ${formatValue(deployment.branch)}`,
|
|
540
|
+
` Commit: ${formatValue(deployment.commitSha)}`,
|
|
541
|
+
` Date: ${deployment.createdAt}`,
|
|
542
|
+
` URL: ${deployment.url}`,
|
|
543
|
+
""
|
|
544
|
+
])
|
|
545
|
+
].slice(0, -1).join("\n");
|
|
546
|
+
}
|
|
547
|
+
function formatProjectDomain(domain) {
|
|
548
|
+
return `Deployment domain: ${formatValue(domain.domain)}`;
|
|
549
|
+
}
|
|
550
|
+
function formatIgnoredChanges(changes) {
|
|
551
|
+
if (changes.length === 0) return "No ignored changes found.";
|
|
552
|
+
return [
|
|
553
|
+
`Ignored changes (${changes.length})`,
|
|
554
|
+
"",
|
|
555
|
+
...changes.flatMap((change) => [
|
|
556
|
+
change.id,
|
|
557
|
+
` Test: ${change.test.name} (${change.test.buildName})`,
|
|
558
|
+
` Test ID: ${change.test.id}`,
|
|
559
|
+
""
|
|
560
|
+
])
|
|
561
|
+
].slice(0, -1).join("\n");
|
|
562
|
+
}
|
|
563
|
+
function formatTests(tests) {
|
|
564
|
+
if (tests.length === 0) return "No tests found.";
|
|
565
|
+
return [
|
|
566
|
+
`Tests (${tests.length})`,
|
|
567
|
+
"",
|
|
568
|
+
...tests.flatMap((test) => [
|
|
569
|
+
`${test.name} (${test.buildName})`,
|
|
570
|
+
` ID: ${test.id}`,
|
|
571
|
+
` Flakiness: ${formatFlakiness(test.metrics)}`,
|
|
572
|
+
` Changes: ${test.metrics.changes} over ${test.metrics.total} builds`,
|
|
573
|
+
""
|
|
574
|
+
])
|
|
575
|
+
].slice(0, -1).join("\n");
|
|
576
|
+
}
|
|
577
|
+
function formatReviewers(data) {
|
|
578
|
+
if (data.reviewers.length === 0) return "No reviewers requested.";
|
|
579
|
+
return [
|
|
580
|
+
`Requested reviewers (${data.reviewers.length})`,
|
|
581
|
+
"",
|
|
582
|
+
...data.reviewers.map((user) => `${formatUser(user)} · user ${user.id}`)
|
|
583
|
+
].join("\n");
|
|
584
|
+
}
|
|
585
|
+
function formatSubscription(subscription) {
|
|
586
|
+
return subscription.subscribed ? "Subscribed: you will receive notifications." : "Unsubscribed: you will no longer receive notifications.";
|
|
587
|
+
}
|
|
588
|
+
/** One line per condition, rendering the `not` and `glob` wrappers inline. */
|
|
589
|
+
function formatConditions(conditions) {
|
|
590
|
+
return conditions.map((condition) => {
|
|
591
|
+
if ("not" in condition) {
|
|
592
|
+
const inner = condition.not;
|
|
593
|
+
return "glob" in inner ? `not ${inner.glob.type} matches ${inner.glob.value}` : `not ${inner.type} is ${formatValue(inner.value)}`;
|
|
594
|
+
}
|
|
595
|
+
if ("glob" in condition) return `${condition.glob.type} matches ${condition.glob.value}`;
|
|
596
|
+
return `${condition.type} is ${formatValue(condition.value)}`;
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
function formatAutomationRule(rule) {
|
|
600
|
+
const lines = [
|
|
601
|
+
`Rule ${rule.name} [${rule.active ? "active" : "inactive"}]`,
|
|
602
|
+
`ID: ${rule.id}`,
|
|
603
|
+
`Events: ${rule.events.join(", ")}`
|
|
604
|
+
];
|
|
605
|
+
const conditions = formatConditions(rule.conditions);
|
|
606
|
+
lines.push(conditions.length > 0 ? `Conditions: ${conditions.join(" AND ")}` : "Conditions: none");
|
|
607
|
+
lines.push(`Actions: ${rule.actions.map((action) => action.action).join(", ")}`);
|
|
608
|
+
lines.push(`Updated: ${rule.updatedAt}`);
|
|
609
|
+
return lines.join("\n");
|
|
610
|
+
}
|
|
611
|
+
function formatAutomationRules(rules) {
|
|
612
|
+
if (rules.length === 0) return "No automation rules found.";
|
|
613
|
+
return [
|
|
614
|
+
`Automation rules (${rules.length})`,
|
|
615
|
+
"",
|
|
616
|
+
...rules.flatMap((rule) => [
|
|
617
|
+
`${rule.name} [${rule.active ? "active" : "inactive"}]`,
|
|
618
|
+
` ID: ${rule.id}`,
|
|
619
|
+
` Events: ${rule.events.join(", ")}`,
|
|
620
|
+
` Actions: ${rule.actions.map((action) => action.action).join(", ")}`,
|
|
621
|
+
""
|
|
622
|
+
])
|
|
623
|
+
].slice(0, -1).join("\n");
|
|
624
|
+
}
|
|
625
|
+
/** Format bytes the way a file listing does. */
|
|
626
|
+
function formatMediaSize(bytes) {
|
|
627
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
628
|
+
const kb = bytes / 1024;
|
|
629
|
+
if (kb < 1024) return `${Math.round(kb)} KB`;
|
|
630
|
+
const mb = kb / 1024;
|
|
631
|
+
return mb < 10 ? `${mb.toFixed(1)} MB` : `${Math.round(mb)} MB`;
|
|
632
|
+
}
|
|
633
|
+
/** Content type, size, dimensions — the same middle line everywhere media prints. */
|
|
634
|
+
function formatMediaDetails(media) {
|
|
635
|
+
return [
|
|
636
|
+
media.contentType,
|
|
637
|
+
formatMediaSize(media.sizeBytes),
|
|
638
|
+
media.width && media.height ? `${media.width}x${media.height}` : null
|
|
639
|
+
].filter((part) => Boolean(part)).join(" · ");
|
|
640
|
+
}
|
|
388
641
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* {@link fail} — instead of calling `process.exit` directly so the failure can
|
|
392
|
-
* be unit-tested and handled in a single place ({@link handleCliError}).
|
|
642
|
+
* Where a media stands: attached to a pull request and listed in its comment, or
|
|
643
|
+
* waiting on one to open for its branch.
|
|
393
644
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
};
|
|
645
|
+
function formatMediaStage(media) {
|
|
646
|
+
if (media.stage === "published") return media.prNumber ? `published to PR #${media.prNumber}` : "published";
|
|
647
|
+
return media.branch ? `staged on ${media.branch}` : "staged";
|
|
648
|
+
}
|
|
400
649
|
/**
|
|
401
|
-
*
|
|
650
|
+
* Format one media.
|
|
651
|
+
*
|
|
652
|
+
* The Markdown embed comes last and on its own line: it is what a caller copies,
|
|
653
|
+
* and burying it between fields makes it harder to select.
|
|
402
654
|
*/
|
|
403
|
-
function
|
|
404
|
-
|
|
655
|
+
function formatMedia(media) {
|
|
656
|
+
return [
|
|
657
|
+
media.state ? `${media.name} (${media.state})` : media.name,
|
|
658
|
+
` ID: ${media.id}`,
|
|
659
|
+
` ${formatMediaStage(media)}`,
|
|
660
|
+
` ${formatMediaDetails(media)} · ${media.visibility} · ${media.status}`,
|
|
661
|
+
media.versionCount > 1 ? ` Version: ${media.version} (${media.versionCount} uploaded)` : null,
|
|
662
|
+
media.description ? ` Description: ${media.description}` : null,
|
|
663
|
+
media.expiresAt ? ` Expires: ${media.expiresAt}` : null,
|
|
664
|
+
` URL: ${media.url}`,
|
|
665
|
+
` File: ${media.fileUrl}`,
|
|
666
|
+
` Markdown: ${media.markdown}`
|
|
667
|
+
].filter((line) => line !== null).join("\n");
|
|
668
|
+
}
|
|
669
|
+
function formatMediaList(list) {
|
|
670
|
+
if (list.length === 0) return "No media found.";
|
|
671
|
+
return [
|
|
672
|
+
`Media (${list.length})`,
|
|
673
|
+
"",
|
|
674
|
+
...list.map(formatMedia)
|
|
675
|
+
].join("\n");
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Format a media's versions.
|
|
679
|
+
*
|
|
680
|
+
* The id leads each entry because that is what this listing is for: a comment
|
|
681
|
+
* records the `mediaVersionId` its author was looking at, and matching it here is
|
|
682
|
+
* how feedback written on an earlier upload gets read against the right file.
|
|
683
|
+
*/
|
|
684
|
+
function formatMediaVersions(versions) {
|
|
685
|
+
if (versions.length === 0) return "No versions found.";
|
|
686
|
+
return [
|
|
687
|
+
`Versions (${versions.length})`,
|
|
688
|
+
"",
|
|
689
|
+
...versions.flatMap((version) => [
|
|
690
|
+
`#${version.number} · ${formatMediaDetails(version)} · ${version.createdAt}`,
|
|
691
|
+
` ID: ${version.id}`,
|
|
692
|
+
` File: ${version.fileUrl}`,
|
|
693
|
+
version.expiresAt ? ` Expires: ${version.expiresAt}` : null,
|
|
694
|
+
""
|
|
695
|
+
])
|
|
696
|
+
].filter((line) => line !== null).slice(0, -1).join("\n");
|
|
405
697
|
}
|
|
406
698
|
//#endregion
|
|
407
699
|
//#region src/lib/oauth.ts
|
|
@@ -669,11 +961,22 @@ function parseProjectPathOrFail(slug) {
|
|
|
669
961
|
//#endregion
|
|
670
962
|
//#region src/lib/target.ts
|
|
671
963
|
/**
|
|
964
|
+
* Resolve the API token if there is one, preferring an explicit token
|
|
965
|
+
* (`--token` / `ARGOS_TOKEN`) over the one stored by `argos login`.
|
|
966
|
+
*
|
|
967
|
+
* Returns `undefined` rather than failing, for the commands that have another way
|
|
968
|
+
* in: `media upload` falls back to CI tokenless authentication, which needs to be
|
|
969
|
+
* reached with no token in hand.
|
|
970
|
+
*/
|
|
971
|
+
async function resolveOptionalToken(options) {
|
|
972
|
+
return options.token || process.env["ARGOS_TOKEN"] || await getAccessToken() || void 0;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
672
975
|
* Resolve the API token, preferring an explicit token (`--token` /
|
|
673
976
|
* `ARGOS_TOKEN`) over the one stored by `argos login`.
|
|
674
977
|
*/
|
|
675
978
|
async function resolveToken(options) {
|
|
676
|
-
const token =
|
|
979
|
+
const token = await resolveOptionalToken(options);
|
|
677
980
|
if (!token) fail("No Argos token found. Use --token, set ARGOS_TOKEN, or run `argos login`.");
|
|
678
981
|
return token;
|
|
679
982
|
}
|
|
@@ -743,6 +1046,20 @@ async function resolveProjectTarget(options, { auth }) {
|
|
|
743
1046
|
project: project.name
|
|
744
1047
|
};
|
|
745
1048
|
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Resolve an account-scoped command target: an authenticated client and the
|
|
1051
|
+
* account slug, taken from `--account <slug>` or the `ARGOS_ACCOUNT`
|
|
1052
|
+
* environment variable. Account endpoints all act as a user, so the token must
|
|
1053
|
+
* be a personal access token scoped to that account.
|
|
1054
|
+
*/
|
|
1055
|
+
async function resolveAccountTarget(options) {
|
|
1056
|
+
const accountSlug = options.account || process.env["ARGOS_ACCOUNT"];
|
|
1057
|
+
if (!accountSlug) fail("An account is required. Use --account <slug> or set ARGOS_ACCOUNT.");
|
|
1058
|
+
return {
|
|
1059
|
+
client: createApiClient(await resolveToken(options)),
|
|
1060
|
+
accountSlug
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
746
1063
|
//#endregion
|
|
747
1064
|
//#region src/lib/run.ts
|
|
748
1065
|
const USER_AUTH_HINT = "Ensure your token is a personal access token with access to this project. Project tokens (ARGOS_TOKEN in CI) can read build data but cannot perform review or comment actions.";
|
|
@@ -853,11 +1170,45 @@ function registerBuildSnapshots(build) {
|
|
|
853
1170
|
});
|
|
854
1171
|
}
|
|
855
1172
|
//#endregion
|
|
1173
|
+
//#region src/commands/build/subscription.ts
|
|
1174
|
+
/** Register `build subscribe` / `build unsubscribe`; both act as a user. */
|
|
1175
|
+
function defineBuildSubscription(opts) {
|
|
1176
|
+
return (build) => {
|
|
1177
|
+
build.command(opts.name).description(opts.description).argument("<buildReference>", "Build number or Argos build URL").addOption(tokenOption).addOption(projectPathOption).addOption(jsonOption).action((reference, options) => runBuildAction({
|
|
1178
|
+
reference,
|
|
1179
|
+
options,
|
|
1180
|
+
auth: "user",
|
|
1181
|
+
handler: opts.perform,
|
|
1182
|
+
format: formatSubscription
|
|
1183
|
+
}));
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
const registerBuildSubscribe = defineBuildSubscription({
|
|
1187
|
+
name: "subscribe",
|
|
1188
|
+
description: "Subscribe to a build's notifications — new comments, reviews, and status changes",
|
|
1189
|
+
perform: async ({ client, owner, project, buildNumber }) => unwrap(await client.POST("/projects/{owner}/{project}/builds/{buildNumber}/subscription", { params: { path: {
|
|
1190
|
+
owner,
|
|
1191
|
+
project,
|
|
1192
|
+
buildNumber
|
|
1193
|
+
} } }))
|
|
1194
|
+
});
|
|
1195
|
+
const registerBuildUnsubscribe = defineBuildSubscription({
|
|
1196
|
+
name: "unsubscribe",
|
|
1197
|
+
description: "Stop receiving notifications about a build. Argos will not auto-subscribe you to it again",
|
|
1198
|
+
perform: async ({ client, owner, project, buildNumber }) => unwrap(await client.DELETE("/projects/{owner}/{project}/builds/{buildNumber}/subscription", { params: { path: {
|
|
1199
|
+
owner,
|
|
1200
|
+
project,
|
|
1201
|
+
buildNumber
|
|
1202
|
+
} } }))
|
|
1203
|
+
});
|
|
1204
|
+
//#endregion
|
|
856
1205
|
//#region src/commands/build/index.ts
|
|
857
1206
|
function buildCommand(program) {
|
|
858
1207
|
const build = program.command("build").description("Inspect Argos builds");
|
|
859
1208
|
registerBuildGet(build);
|
|
860
1209
|
registerBuildSnapshots(build);
|
|
1210
|
+
registerBuildSubscribe(build);
|
|
1211
|
+
registerBuildUnsubscribe(build);
|
|
861
1212
|
}
|
|
862
1213
|
//#endregion
|
|
863
1214
|
//#region src/lib/body.ts
|
|
@@ -941,12 +1292,57 @@ function registerReviewList(review) {
|
|
|
941
1292
|
}));
|
|
942
1293
|
}
|
|
943
1294
|
//#endregion
|
|
1295
|
+
//#region src/commands/review/reviewer.ts
|
|
1296
|
+
function registerReviewReviewer(review) {
|
|
1297
|
+
const reviewer = review.command("reviewer").description("List, request, and cancel review requests on a build");
|
|
1298
|
+
reviewer.command("list").description("List the users currently requested to review a build").argument("<buildReference>", "Build number or Argos build URL").addOption(tokenOption).addOption(projectPathOption).addOption(jsonOption).action((reference, options) => runBuildAction({
|
|
1299
|
+
reference,
|
|
1300
|
+
options,
|
|
1301
|
+
auth: "user",
|
|
1302
|
+
handler: async ({ client, owner, project, buildNumber }) => unwrap(await client.GET("/projects/{owner}/{project}/builds/{buildNumber}/reviewers", { params: { path: {
|
|
1303
|
+
owner,
|
|
1304
|
+
project,
|
|
1305
|
+
buildNumber
|
|
1306
|
+
} } })),
|
|
1307
|
+
format: formatReviewers
|
|
1308
|
+
}));
|
|
1309
|
+
reviewer.command("add").description("Request users to review a build. Users already requested are left untouched and not notified again").argument("<buildReference>", "Build number or Argos build URL").argument("<userIds...>", "User IDs to request, taken from `argos account member list` or `argos whoami`").addOption(tokenOption).addOption(projectPathOption).addOption(jsonOption).action((reference, userIds, options) => runBuildAction({
|
|
1310
|
+
reference,
|
|
1311
|
+
options,
|
|
1312
|
+
auth: "user",
|
|
1313
|
+
handler: async ({ client, owner, project, buildNumber }) => unwrap(await client.POST("/projects/{owner}/{project}/builds/{buildNumber}/reviewers", {
|
|
1314
|
+
params: { path: {
|
|
1315
|
+
owner,
|
|
1316
|
+
project,
|
|
1317
|
+
buildNumber
|
|
1318
|
+
} },
|
|
1319
|
+
body: { userIds }
|
|
1320
|
+
})),
|
|
1321
|
+
format: formatReviewers
|
|
1322
|
+
}));
|
|
1323
|
+
reviewer.command("remove").description("Cancel the review requests standing on a build").argument("<buildReference>", "Build number or Argos build URL").argument("<userIds...>", "User IDs whose review request to cancel").addOption(tokenOption).addOption(projectPathOption).addOption(jsonOption).action((reference, userIds, options) => runBuildAction({
|
|
1324
|
+
reference,
|
|
1325
|
+
options,
|
|
1326
|
+
auth: "user",
|
|
1327
|
+
handler: async ({ client, owner, project, buildNumber }) => unwrap(await client.DELETE("/projects/{owner}/{project}/builds/{buildNumber}/reviewers", {
|
|
1328
|
+
params: { path: {
|
|
1329
|
+
owner,
|
|
1330
|
+
project,
|
|
1331
|
+
buildNumber
|
|
1332
|
+
} },
|
|
1333
|
+
body: { userIds }
|
|
1334
|
+
})),
|
|
1335
|
+
format: formatReviewers
|
|
1336
|
+
}));
|
|
1337
|
+
}
|
|
1338
|
+
//#endregion
|
|
944
1339
|
//#region src/commands/review/index.ts
|
|
945
1340
|
function reviewCommand(program) {
|
|
946
1341
|
const review = program.command("review").description("List, submit, and dismiss build reviews");
|
|
947
1342
|
registerReviewList(review);
|
|
948
1343
|
registerReviewCreate(review);
|
|
949
1344
|
registerReviewDismiss(review);
|
|
1345
|
+
registerReviewReviewer(review);
|
|
950
1346
|
}
|
|
951
1347
|
//#endregion
|
|
952
1348
|
//#region src/lib/anchor.ts
|
|
@@ -1401,7 +1797,7 @@ function createProjectCommand(program) {
|
|
|
1401
1797
|
output(unwrap(await createApiClient(await resolveToken(options)).POST("/projects", { body: {
|
|
1402
1798
|
name,
|
|
1403
1799
|
accountSlug
|
|
1404
|
-
} })), options,
|
|
1800
|
+
} })), options, formatCreatedProject);
|
|
1405
1801
|
} catch (error) {
|
|
1406
1802
|
handleCliError(error, "user");
|
|
1407
1803
|
}
|
|
@@ -1493,6 +1889,48 @@ const registerChangeIgnore = defineChangeAction({
|
|
|
1493
1889
|
} }))
|
|
1494
1890
|
});
|
|
1495
1891
|
//#endregion
|
|
1892
|
+
//#region src/lib/pagination.ts
|
|
1893
|
+
/** Largest page the API serves. */
|
|
1894
|
+
const MAX_PER_PAGE = 100;
|
|
1895
|
+
/**
|
|
1896
|
+
* Walk a paginated endpoint until `limit` items have been collected, the server
|
|
1897
|
+
* runs out of results, or its reported total is reached.
|
|
1898
|
+
*
|
|
1899
|
+
* `fetchPage` receives the page number and the size to request, both already
|
|
1900
|
+
* stringified — every paginated Argos endpoint takes them as query strings.
|
|
1901
|
+
*/
|
|
1902
|
+
async function fetchPages(limit, fetchPage) {
|
|
1903
|
+
const perPage = String(Math.min(MAX_PER_PAGE, limit));
|
|
1904
|
+
const results = [];
|
|
1905
|
+
for (let page = 1;; page++) {
|
|
1906
|
+
const data = await fetchPage({
|
|
1907
|
+
page: String(page),
|
|
1908
|
+
perPage
|
|
1909
|
+
});
|
|
1910
|
+
results.push(...data.results);
|
|
1911
|
+
if (results.length >= limit || results.length >= data.pageInfo.total || data.results.length === 0) break;
|
|
1912
|
+
}
|
|
1913
|
+
return results.slice(0, limit);
|
|
1914
|
+
}
|
|
1915
|
+
//#endregion
|
|
1916
|
+
//#region src/commands/change/list.ts
|
|
1917
|
+
function registerChangeList(change) {
|
|
1918
|
+
change.command("list").description("List the changes currently ignored in a project, most recently ignored first").addOption(limitOption).addOption(tokenOption).addOption(changeProjectPathOption).addOption(jsonOption).action(async (options) => {
|
|
1919
|
+
try {
|
|
1920
|
+
const { client, owner, project } = await resolveProjectTarget(options, { auth: "project" });
|
|
1921
|
+
output(await fetchPages(toLimit(options.limit), async (pagination) => unwrap(await client.GET("/projects/{owner}/{project}/ignored-changes", { params: {
|
|
1922
|
+
path: {
|
|
1923
|
+
owner,
|
|
1924
|
+
project
|
|
1925
|
+
},
|
|
1926
|
+
query: pagination
|
|
1927
|
+
} }))), options, formatIgnoredChanges);
|
|
1928
|
+
} catch (error) {
|
|
1929
|
+
handleCliError(error, "project");
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
//#endregion
|
|
1496
1934
|
//#region src/commands/change/unignore.ts
|
|
1497
1935
|
const registerChangeUnignore = defineChangeAction({
|
|
1498
1936
|
name: "unignore",
|
|
@@ -1510,45 +1948,362 @@ const registerChangeUnignore = defineChangeAction({
|
|
|
1510
1948
|
//#region src/commands/change/index.ts
|
|
1511
1949
|
function changeCommand(program) {
|
|
1512
1950
|
const change = program.command("change").description("Ignore or unignore flaky test changes");
|
|
1951
|
+
registerChangeList(change);
|
|
1513
1952
|
registerChangeIgnore(change);
|
|
1514
1953
|
registerChangeUnignore(change);
|
|
1515
1954
|
}
|
|
1516
1955
|
//#endregion
|
|
1517
|
-
//#region src/commands/
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
/** Fetch every change of a test, following pagination. */
|
|
1521
|
-
async function fetchAllChanges(target, testId, options) {
|
|
1522
|
-
const { client, owner, project } = target;
|
|
1523
|
-
const results = [];
|
|
1524
|
-
for (let page = 1;; page++) {
|
|
1525
|
-
const data = unwrap(await client.GET("/projects/{owner}/{project}/tests/{testId}/changes", { params: {
|
|
1526
|
-
path: {
|
|
1527
|
-
owner,
|
|
1528
|
-
project,
|
|
1529
|
-
testId
|
|
1530
|
-
},
|
|
1531
|
-
query: {
|
|
1532
|
-
page: String(page),
|
|
1533
|
-
perPage: String(PER_PAGE),
|
|
1534
|
-
metricsPeriod: options.metricsPeriod,
|
|
1535
|
-
...options.ignored ? { ignored: options.ignored } : {}
|
|
1536
|
-
}
|
|
1537
|
-
} }));
|
|
1538
|
-
results.push(...data.results);
|
|
1539
|
-
if (results.length >= data.pageInfo.total || data.results.length === 0) break;
|
|
1540
|
-
}
|
|
1541
|
-
return results;
|
|
1542
|
-
}
|
|
1543
|
-
function registerTestChanges(test) {
|
|
1544
|
-
test.command("changes").description("List the distinct changes a test produced over a period, most frequent first").argument("<testId>", "Test ID, taken from a diff's `test.id` (see `argos build snapshots`)").addOption(ignoredOption).addOption(tokenOption).addOption(testProjectPathOption).addOption(metricsPeriodOption).addOption(jsonOption).action(async (testId, options) => {
|
|
1956
|
+
//#region src/commands/media/comment/create.ts
|
|
1957
|
+
function registerMediaCommentCreate(comment) {
|
|
1958
|
+
comment.command("create").description("Post a comment (or reply) on a media").argument("<mediaId>", "ID of the media").option("--body <markdown>", "Markdown body of the comment").option("--body-file <path>", "Read the comment body from a Markdown file").option("--reply-to <threadId>", "Reply to an existing thread (its root comment ID)").option("--anchor-point <x,y>", "Pin the comment to a spot on the media, in normalized 0-1 coordinates").addOption(tokenOption).addOption(jsonOption).action(async (mediaId, options) => {
|
|
1545
1959
|
try {
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1960
|
+
const body = await resolveBody(options, { required: true });
|
|
1961
|
+
const anchor = parseAnchor(options);
|
|
1962
|
+
if (anchor && options.replyTo) fail("--anchor-point cannot be used with --reply-to.");
|
|
1963
|
+
output(unwrap(await createApiClient(await resolveToken(options)).POST("/media/{mediaId}/comments", {
|
|
1964
|
+
params: { path: { mediaId } },
|
|
1965
|
+
body: {
|
|
1966
|
+
body,
|
|
1967
|
+
threadId: options.replyTo,
|
|
1968
|
+
anchor
|
|
1969
|
+
}
|
|
1970
|
+
})), options, formatComment);
|
|
1550
1971
|
} catch (error) {
|
|
1551
|
-
handleCliError(error, "
|
|
1972
|
+
handleCliError(error, "user");
|
|
1973
|
+
}
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
//#endregion
|
|
1977
|
+
//#region src/commands/media/comment/_action.ts
|
|
1978
|
+
/**
|
|
1979
|
+
* Register a `media comment <name> <mediaId> <commentId>` command that runs
|
|
1980
|
+
* `perform` and prints the returned comment.
|
|
1981
|
+
*
|
|
1982
|
+
* The media equivalent of the build `defineCommentAction`, and simpler than it:
|
|
1983
|
+
* a media comment is addressed by the media's own id, so there is no project
|
|
1984
|
+
* path to resolve and no build reference to parse.
|
|
1985
|
+
*/
|
|
1986
|
+
function defineMediaCommentAction(opts) {
|
|
1987
|
+
return (comment) => {
|
|
1988
|
+
comment.command(opts.name).description(opts.description).argument("<mediaId>", "ID of the media").argument("<commentId>", "ID of the comment").addOption(tokenOption).addOption(jsonOption).action(async (mediaId, commentId, options) => {
|
|
1989
|
+
try {
|
|
1990
|
+
const client = createApiClient(await resolveToken(options));
|
|
1991
|
+
output(await opts.perform({
|
|
1992
|
+
client,
|
|
1993
|
+
mediaId,
|
|
1994
|
+
commentId
|
|
1995
|
+
}), options, formatComment);
|
|
1996
|
+
} catch (error) {
|
|
1997
|
+
handleCliError(error, "user");
|
|
1998
|
+
}
|
|
1999
|
+
});
|
|
2000
|
+
};
|
|
2001
|
+
}
|
|
2002
|
+
//#endregion
|
|
2003
|
+
//#region src/commands/media/comment/delete.ts
|
|
2004
|
+
const registerMediaCommentDelete = defineMediaCommentAction({
|
|
2005
|
+
name: "delete",
|
|
2006
|
+
description: "Delete a comment on a media (author only)",
|
|
2007
|
+
perform: async ({ client, mediaId, commentId }) => unwrap(await client.DELETE("/media/{mediaId}/comments/{commentId}", { params: { path: {
|
|
2008
|
+
mediaId,
|
|
2009
|
+
commentId
|
|
2010
|
+
} } }))
|
|
2011
|
+
});
|
|
2012
|
+
//#endregion
|
|
2013
|
+
//#region src/commands/media/comment/edit.ts
|
|
2014
|
+
function registerMediaCommentEdit(comment) {
|
|
2015
|
+
comment.command("edit").description("Update the body of a comment on a media (author only)").argument("<mediaId>", "ID of the media").argument("<commentId>", "ID of the comment").option("--body <markdown>", "New Markdown body of the comment").option("--body-file <path>", "Read the new body from a Markdown file").addOption(tokenOption).addOption(jsonOption).action(async (mediaId, commentId, options) => {
|
|
2016
|
+
try {
|
|
2017
|
+
const body = await resolveBody(options, { required: true });
|
|
2018
|
+
output(unwrap(await createApiClient(await resolveToken(options)).PATCH("/media/{mediaId}/comments/{commentId}", {
|
|
2019
|
+
params: { path: {
|
|
2020
|
+
mediaId,
|
|
2021
|
+
commentId
|
|
2022
|
+
} },
|
|
2023
|
+
body: { body }
|
|
2024
|
+
})), options, formatComment);
|
|
2025
|
+
} catch (error) {
|
|
2026
|
+
handleCliError(error, "user");
|
|
2027
|
+
}
|
|
2028
|
+
});
|
|
2029
|
+
}
|
|
2030
|
+
//#endregion
|
|
2031
|
+
//#region src/commands/media/comment/get.ts
|
|
2032
|
+
const registerMediaCommentGet = defineMediaCommentAction({
|
|
2033
|
+
name: "get",
|
|
2034
|
+
description: "Show a single comment on a media",
|
|
2035
|
+
perform: async ({ client, mediaId, commentId }) => unwrap(await client.GET("/media/{mediaId}/comments/{commentId}", { params: { path: {
|
|
2036
|
+
mediaId,
|
|
2037
|
+
commentId
|
|
2038
|
+
} } }))
|
|
2039
|
+
});
|
|
2040
|
+
//#endregion
|
|
2041
|
+
//#region src/commands/media/comment/list.ts
|
|
2042
|
+
function registerMediaCommentList(comment) {
|
|
2043
|
+
comment.command("list").description("List the open comment threads on a media — the feedback still to act on").argument("<mediaId>", "ID of the media").addOption(new Option("--all", "Include threads that are already resolved (by default only open ones are listed)")).addOption(tokenOption).addOption(jsonOption).action(async (mediaId, options) => {
|
|
2044
|
+
try {
|
|
2045
|
+
const result = unwrap(await createApiClient(await resolveToken(options)).GET("/media/{mediaId}/comments", { params: { path: { mediaId } } }));
|
|
2046
|
+
output(options.all ? result : selectOpenThreads(result), options, formatComments);
|
|
2047
|
+
} catch (error) {
|
|
2048
|
+
handleCliError(error, "user");
|
|
2049
|
+
}
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Drop resolved threads, replies included.
|
|
2054
|
+
*
|
|
2055
|
+
* `resolvedAt` is only set on a thread's root comment, so a reply has to be judged
|
|
2056
|
+
* by the thread it belongs to — otherwise answers to settled feedback come back
|
|
2057
|
+
* without the comment that settled it.
|
|
2058
|
+
*/
|
|
2059
|
+
function selectOpenThreads(comments) {
|
|
2060
|
+
const resolved = new Set(comments.filter((comment) => comment.resolvedAt !== null).map((comment) => comment.id));
|
|
2061
|
+
return comments.filter((comment) => comment.resolvedAt === null && !(comment.threadId !== null && resolved.has(comment.threadId)));
|
|
2062
|
+
}
|
|
2063
|
+
//#endregion
|
|
2064
|
+
//#region src/commands/media/comment/react.ts
|
|
2065
|
+
function registerMediaCommentReact(comment) {
|
|
2066
|
+
comment.command("react").description("Add an emoji reaction to a comment on a media").argument("<mediaId>", "ID of the media").argument("<commentId>", "ID of the comment").argument("<emoji>", "Emoji to react with").addOption(tokenOption).addOption(jsonOption).action(async (mediaId, commentId, emoji, options) => {
|
|
2067
|
+
try {
|
|
2068
|
+
output(unwrap(await createApiClient(await resolveToken(options)).POST("/media/{mediaId}/comments/{commentId}/reactions", {
|
|
2069
|
+
params: { path: {
|
|
2070
|
+
mediaId,
|
|
2071
|
+
commentId
|
|
2072
|
+
} },
|
|
2073
|
+
body: { emoji }
|
|
2074
|
+
})), options, formatComment);
|
|
2075
|
+
} catch (error) {
|
|
2076
|
+
handleCliError(error, "user");
|
|
2077
|
+
}
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
//#endregion
|
|
2081
|
+
//#region src/commands/media/comment/resolve.ts
|
|
2082
|
+
const registerMediaCommentResolve = defineMediaCommentAction({
|
|
2083
|
+
name: "resolve",
|
|
2084
|
+
description: "Mark a comment thread as resolved — what to call once you have acted on the feedback",
|
|
2085
|
+
perform: async ({ client, mediaId, commentId }) => unwrap(await client.POST("/media/{mediaId}/comments/{commentId}/resolve", { params: { path: {
|
|
2086
|
+
mediaId,
|
|
2087
|
+
commentId
|
|
2088
|
+
} } }))
|
|
2089
|
+
});
|
|
2090
|
+
//#endregion
|
|
2091
|
+
//#region src/commands/media/comment/subscribe.ts
|
|
2092
|
+
const registerMediaCommentSubscribe = defineMediaCommentAction({
|
|
2093
|
+
name: "subscribe",
|
|
2094
|
+
description: "Subscribe to a comment thread's notifications",
|
|
2095
|
+
perform: async ({ client, mediaId, commentId }) => unwrap(await client.POST("/media/{mediaId}/comments/{commentId}/subscription", { params: { path: {
|
|
2096
|
+
mediaId,
|
|
2097
|
+
commentId
|
|
2098
|
+
} } }))
|
|
2099
|
+
});
|
|
2100
|
+
//#endregion
|
|
2101
|
+
//#region src/commands/media/comment/unreact.ts
|
|
2102
|
+
function registerMediaCommentUnreact(comment) {
|
|
2103
|
+
comment.command("unreact").description("Remove one of your emoji reactions from a comment on a media").argument("<mediaId>", "ID of the media").argument("<commentId>", "ID of the comment").argument("<emoji>", "Emoji reaction to remove").addOption(tokenOption).addOption(jsonOption).action(async (mediaId, commentId, emoji, options) => {
|
|
2104
|
+
try {
|
|
2105
|
+
output(unwrap(await createApiClient(await resolveToken(options)).DELETE("/media/{mediaId}/comments/{commentId}/reactions", { params: {
|
|
2106
|
+
path: {
|
|
2107
|
+
mediaId,
|
|
2108
|
+
commentId
|
|
2109
|
+
},
|
|
2110
|
+
query: { emoji }
|
|
2111
|
+
} })), options, formatComment);
|
|
2112
|
+
} catch (error) {
|
|
2113
|
+
handleCliError(error, "user");
|
|
2114
|
+
}
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
//#endregion
|
|
2118
|
+
//#region src/commands/media/comment/unresolve.ts
|
|
2119
|
+
const registerMediaCommentUnresolve = defineMediaCommentAction({
|
|
2120
|
+
name: "unresolve",
|
|
2121
|
+
description: "Reopen a resolved comment thread",
|
|
2122
|
+
perform: async ({ client, mediaId, commentId }) => unwrap(await client.POST("/media/{mediaId}/comments/{commentId}/unresolve", { params: { path: {
|
|
2123
|
+
mediaId,
|
|
2124
|
+
commentId
|
|
2125
|
+
} } }))
|
|
2126
|
+
});
|
|
2127
|
+
//#endregion
|
|
2128
|
+
//#region src/commands/media/comment/unsubscribe.ts
|
|
2129
|
+
const registerMediaCommentUnsubscribe = defineMediaCommentAction({
|
|
2130
|
+
name: "unsubscribe",
|
|
2131
|
+
description: "Stop receiving notifications for a comment thread",
|
|
2132
|
+
perform: async ({ client, mediaId, commentId }) => unwrap(await client.DELETE("/media/{mediaId}/comments/{commentId}/subscription", { params: { path: {
|
|
2133
|
+
mediaId,
|
|
2134
|
+
commentId
|
|
2135
|
+
} } }))
|
|
2136
|
+
});
|
|
2137
|
+
//#endregion
|
|
2138
|
+
//#region src/commands/media/comment/index.ts
|
|
2139
|
+
function registerMediaComment(media) {
|
|
2140
|
+
const comment = media.command("comment").description("List, post, and act on the comments left on a media — the feedback a human pinned to a spot on your screenshot");
|
|
2141
|
+
registerMediaCommentList(comment);
|
|
2142
|
+
registerMediaCommentCreate(comment);
|
|
2143
|
+
registerMediaCommentGet(comment);
|
|
2144
|
+
registerMediaCommentEdit(comment);
|
|
2145
|
+
registerMediaCommentDelete(comment);
|
|
2146
|
+
registerMediaCommentResolve(comment);
|
|
2147
|
+
registerMediaCommentUnresolve(comment);
|
|
2148
|
+
registerMediaCommentReact(comment);
|
|
2149
|
+
registerMediaCommentUnreact(comment);
|
|
2150
|
+
registerMediaCommentSubscribe(comment);
|
|
2151
|
+
registerMediaCommentUnsubscribe(comment);
|
|
2152
|
+
}
|
|
2153
|
+
//#endregion
|
|
2154
|
+
//#region src/commands/media/delete.ts
|
|
2155
|
+
function registerMediaDelete(media) {
|
|
2156
|
+
media.command("delete").argument("<mediaId>", "ID of the media").description("Delete a media. Any share link or pull request embed pointing at it stops working").addOption(tokenOption).action(async (mediaId, options) => {
|
|
2157
|
+
try {
|
|
2158
|
+
unwrapEmpty(await createApiClient(await resolveToken(options)).DELETE("/media/{mediaId}", { params: { path: { mediaId } } }));
|
|
2159
|
+
console.log(`Media ${mediaId} deleted.`);
|
|
2160
|
+
} catch (error) {
|
|
2161
|
+
handleCliError(error, "project");
|
|
2162
|
+
}
|
|
2163
|
+
});
|
|
2164
|
+
}
|
|
2165
|
+
//#endregion
|
|
2166
|
+
//#region src/commands/media/get.ts
|
|
2167
|
+
function registerMediaGet(media) {
|
|
2168
|
+
media.command("get").argument("<mediaId>", "ID of the media").description("Show a media's share URL, Markdown embed and details").addOption(tokenOption).addOption(jsonOption).action(async (mediaId, options) => {
|
|
2169
|
+
try {
|
|
2170
|
+
output(unwrap(await createApiClient(await resolveToken(options)).GET("/media/{mediaId}", { params: { path: { mediaId } } })), options, formatMedia);
|
|
2171
|
+
} catch (error) {
|
|
2172
|
+
handleCliError(error, "project");
|
|
2173
|
+
}
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
//#endregion
|
|
2177
|
+
//#region src/commands/media/list.ts
|
|
2178
|
+
function registerMediaList(media) {
|
|
2179
|
+
media.command("list").description("List a project's uploaded media, most recent first. A project token lists its own project").addOption(new Option("--branch <branch>", "Only media uploaded for this branch, staged and published alike. The way to find everything uploaded for the work in hand")).addOption(new Option("--pr <number>", "Only media published to this pull request")).addOption(new Option("--stage <stage>", "Restrict to media with no pull request yet, or to media published to one").choices(["staged", "published"])).addOption(new Option("--search <query>", "Match media on their name")).addOption(new Option("--type <type>", "Restrict to images or videos").choices(["image", "video"])).addOption(limitOption).addOption(tokenOption).addOption(mediaProjectPathOption).addOption(jsonOption).action(async (options) => {
|
|
2180
|
+
try {
|
|
2181
|
+
const prNumber = options.pr === void 0 ? void 0 : toPrNumber(options.pr);
|
|
2182
|
+
const { client, owner, project } = await resolveProjectTarget(options, { auth: "project" });
|
|
2183
|
+
output(await fetchPages(toLimit(options.limit), async (pagination) => unwrap(await client.GET("/projects/{owner}/{project}/media", { params: {
|
|
2184
|
+
path: {
|
|
2185
|
+
owner,
|
|
2186
|
+
project
|
|
2187
|
+
},
|
|
2188
|
+
query: {
|
|
2189
|
+
...pagination,
|
|
2190
|
+
...options.branch ? { branch: options.branch } : {},
|
|
2191
|
+
...prNumber === void 0 ? {} : { prNumber },
|
|
2192
|
+
...options.stage ? { stage: options.stage } : {},
|
|
2193
|
+
...options.search ? { search: options.search } : {},
|
|
2194
|
+
...options.type ? { type: options.type } : {}
|
|
2195
|
+
}
|
|
2196
|
+
} }))), options, formatMediaList);
|
|
2197
|
+
} catch (error) {
|
|
2198
|
+
handleCliError(error, "project");
|
|
2199
|
+
}
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
//#endregion
|
|
2203
|
+
//#region src/commands/media/update.ts
|
|
2204
|
+
function registerMediaUpdate(media) {
|
|
2205
|
+
media.command("update").argument("<mediaId>", "ID of the media").description("Change a staged media's name, description or branch. Fixed once the media is published to a pull request").addOption(new Option("--name <name>", "Rename the media")).addOption(new Option("--description <text>", "Prose shown under the media in the pull request comment")).addOption(new Option("--no-description", "Remove the description")).addOption(new Option("--branch <branch>", "Branch to publish the media from, once a pull request opens for it")).addOption(new Option("--no-branch", "Detach the media from its branch, so no pull request will publish it")).addOption(tokenOption).addOption(jsonOption).action(async (mediaId, options) => {
|
|
2206
|
+
try {
|
|
2207
|
+
const body = {
|
|
2208
|
+
...options.name ? { name: options.name } : {},
|
|
2209
|
+
...options.description === void 0 ? {} : { description: options.description || null },
|
|
2210
|
+
...options.branch === void 0 ? {} : { branch: options.branch || null }
|
|
2211
|
+
};
|
|
2212
|
+
if (Object.keys(body).length === 0) fail("Nothing to update. Pass --name, --description or --branch (or --no-description / --no-branch to clear one).");
|
|
2213
|
+
output(unwrap(await createApiClient(await resolveToken(options)).PATCH("/media/{mediaId}", {
|
|
2214
|
+
params: { path: { mediaId } },
|
|
2215
|
+
body
|
|
2216
|
+
})), options, formatMedia);
|
|
2217
|
+
} catch (error) {
|
|
2218
|
+
handleCliError(error, "project");
|
|
2219
|
+
}
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
//#endregion
|
|
2223
|
+
//#region src/commands/media/upload.ts
|
|
2224
|
+
function registerMediaUpload(media) {
|
|
2225
|
+
media.command("upload").argument("<files...>", "Image or video files to upload").description("Upload images or videos and print their share URLs and Markdown embeds").addOption(tokenOption).addOption(mediaProjectPathOption).addOption(new Option("--branch <branch>", "Branch the media belongs to. Use this when the pull request does not exist yet: Argos publishes the media and comments on the pull request by itself once one opens for that branch")).addOption(new Option("--pr <number>", "Pull request to publish the media to. Argos keeps one comment on it listing every media uploaded, edited in place")).addOption(new Option("--state <state>", "Which half of a before/after pair these files are. Inferred from a file name ending in -before or -after").choices(["before", "after"])).addOption(new Option("--description <text>", "Prose shown under the media in the pull request comment")).addOption(new Option("--visibility <visibility>", "Who can open the share page. Defaults to the most private option your plan allows").choices(["team", "public"])).addOption(new Option("--no-compress", "Upload images exactly as they are instead of converting them to WebP")).addOption(jsonOption).action(async (files, options) => {
|
|
2226
|
+
const spinner = options.json ? null : ora(files.length === 1 ? "Uploading media" : `Uploading ${files.length} files`).start();
|
|
2227
|
+
try {
|
|
2228
|
+
const results = await uploadMedia({
|
|
2229
|
+
files,
|
|
2230
|
+
token: await resolveOptionalToken(options),
|
|
2231
|
+
apiBaseUrl: getApiBaseUrl(),
|
|
2232
|
+
project: options.project,
|
|
2233
|
+
branch: options.branch,
|
|
2234
|
+
prNumber: options.pr === void 0 ? void 0 : toPrNumber(options.pr),
|
|
2235
|
+
state: options.state,
|
|
2236
|
+
description: options.description,
|
|
2237
|
+
visibility: options.visibility,
|
|
2238
|
+
compress: options.compress
|
|
2239
|
+
});
|
|
2240
|
+
spinner?.stop();
|
|
2241
|
+
output(results, options, formatMediaList);
|
|
2242
|
+
} catch (error) {
|
|
2243
|
+
spinner?.stop();
|
|
2244
|
+
handleCliError(error, "project");
|
|
2245
|
+
}
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
//#endregion
|
|
2249
|
+
//#region src/commands/media/versions.ts
|
|
2250
|
+
function registerMediaVersions(media) {
|
|
2251
|
+
media.command("versions").argument("<mediaId>", "ID of the media").description("List a media's uploaded versions, newest first. Use it to resolve the version a comment was written against").addOption(tokenOption).addOption(jsonOption).action(async (mediaId, options) => {
|
|
2252
|
+
try {
|
|
2253
|
+
output(unwrap(await createApiClient(await resolveToken(options)).GET("/media/{mediaId}/versions", { params: { path: { mediaId } } })), options, formatMediaVersions);
|
|
2254
|
+
} catch (error) {
|
|
2255
|
+
handleCliError(error, "project");
|
|
2256
|
+
}
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
//#endregion
|
|
2260
|
+
//#region src/commands/media/index.ts
|
|
2261
|
+
function mediaCommand(program) {
|
|
2262
|
+
const media = program.command("media").description("Upload standalone images and videos to Argos and get shareable links to paste into pull requests");
|
|
2263
|
+
registerMediaUpload(media);
|
|
2264
|
+
registerMediaList(media);
|
|
2265
|
+
registerMediaGet(media);
|
|
2266
|
+
registerMediaUpdate(media);
|
|
2267
|
+
registerMediaDelete(media);
|
|
2268
|
+
registerMediaVersions(media);
|
|
2269
|
+
registerMediaComment(media);
|
|
2270
|
+
}
|
|
2271
|
+
//#endregion
|
|
2272
|
+
//#region src/commands/test/changes.ts
|
|
2273
|
+
const PER_PAGE = 100;
|
|
2274
|
+
const ignoredOption = new Option("--ignored <boolean>", "Only the changes currently ignored (`true`) or only the ones still under review (`false`)").choices(["true", "false"]);
|
|
2275
|
+
/** Fetch every change of a test, following pagination. */
|
|
2276
|
+
async function fetchAllChanges(target, testId, options) {
|
|
2277
|
+
const { client, owner, project } = target;
|
|
2278
|
+
const results = [];
|
|
2279
|
+
for (let page = 1;; page++) {
|
|
2280
|
+
const data = unwrap(await client.GET("/projects/{owner}/{project}/tests/{testId}/changes", { params: {
|
|
2281
|
+
path: {
|
|
2282
|
+
owner,
|
|
2283
|
+
project,
|
|
2284
|
+
testId
|
|
2285
|
+
},
|
|
2286
|
+
query: {
|
|
2287
|
+
page: String(page),
|
|
2288
|
+
perPage: String(PER_PAGE),
|
|
2289
|
+
metricsPeriod: options.metricsPeriod,
|
|
2290
|
+
...options.ignored ? { ignored: options.ignored } : {}
|
|
2291
|
+
}
|
|
2292
|
+
} }));
|
|
2293
|
+
results.push(...data.results);
|
|
2294
|
+
if (results.length >= data.pageInfo.total || data.results.length === 0) break;
|
|
2295
|
+
}
|
|
2296
|
+
return results;
|
|
2297
|
+
}
|
|
2298
|
+
function registerTestChanges(test) {
|
|
2299
|
+
test.command("changes").description("List the distinct changes a test produced over a period, most frequent first").argument("<testId>", "Test ID, taken from a diff's `test.id` (see `argos build snapshots`)").addOption(ignoredOption).addOption(tokenOption).addOption(testProjectPathOption).addOption(metricsPeriodOption).addOption(jsonOption).action(async (testId, options) => {
|
|
2300
|
+
try {
|
|
2301
|
+
output(await fetchAllChanges(await resolveProjectTarget(options, { auth: "project" }), testId, {
|
|
2302
|
+
metricsPeriod: toMetricsPeriod(options.metricsPeriod),
|
|
2303
|
+
ignored: options.ignored
|
|
2304
|
+
}), options, formatTestChanges);
|
|
2305
|
+
} catch (error) {
|
|
2306
|
+
handleCliError(error, "project");
|
|
1552
2307
|
}
|
|
1553
2308
|
});
|
|
1554
2309
|
}
|
|
@@ -1786,12 +2541,656 @@ function registerTestGet(test) {
|
|
|
1786
2541
|
});
|
|
1787
2542
|
}
|
|
1788
2543
|
//#endregion
|
|
2544
|
+
//#region src/commands/test/list.ts
|
|
2545
|
+
function registerTestList(test) {
|
|
2546
|
+
test.command("list").description("List the tests currently running in a project, flakiest first — the project's flakiness backlog").option("--build-name <name>", "Restrict to the tests of a single build name").option("--search <query>", "Match tests on their name").addOption(limitOption).addOption(tokenOption).addOption(testProjectPathOption).addOption(metricsPeriodOption).addOption(jsonOption).action(async (options) => {
|
|
2547
|
+
try {
|
|
2548
|
+
const { client, owner, project } = await resolveProjectTarget(options, { auth: "project" });
|
|
2549
|
+
output(await fetchPages(toLimit(options.limit), async (pagination) => unwrap(await client.GET("/projects/{owner}/{project}/tests", { params: {
|
|
2550
|
+
path: {
|
|
2551
|
+
owner,
|
|
2552
|
+
project
|
|
2553
|
+
},
|
|
2554
|
+
query: {
|
|
2555
|
+
...pagination,
|
|
2556
|
+
metricsPeriod: toMetricsPeriod(options.metricsPeriod),
|
|
2557
|
+
...options.buildName ? { buildName: options.buildName } : {},
|
|
2558
|
+
...options.search ? { search: options.search } : {}
|
|
2559
|
+
}
|
|
2560
|
+
} }))), options, formatTests);
|
|
2561
|
+
} catch (error) {
|
|
2562
|
+
handleCliError(error, "project");
|
|
2563
|
+
}
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
//#endregion
|
|
2567
|
+
//#region src/commands/test/subscription.ts
|
|
2568
|
+
/**
|
|
2569
|
+
* Register `test subscribe` / `test unsubscribe`. Both act as a user, so they
|
|
2570
|
+
* need a personal access token, and the project comes from `--project` or
|
|
2571
|
+
* `ARGOS_PROJECT` since a test id does not carry the account slug.
|
|
2572
|
+
*/
|
|
2573
|
+
function defineTestSubscription(opts) {
|
|
2574
|
+
return (test) => {
|
|
2575
|
+
test.command(opts.name).description(opts.description).argument("<testId>", "Test ID, taken from a diff's `test.id` (see `argos build snapshots`)").addOption(tokenOption).addOption(testProjectPathOption).addOption(jsonOption).action(async (testId, options) => {
|
|
2576
|
+
try {
|
|
2577
|
+
const { client, owner, project } = await resolveProjectTarget(options, { auth: "user" });
|
|
2578
|
+
output(await opts.perform({
|
|
2579
|
+
client,
|
|
2580
|
+
owner,
|
|
2581
|
+
project,
|
|
2582
|
+
testId
|
|
2583
|
+
}), options, formatSubscription);
|
|
2584
|
+
} catch (error) {
|
|
2585
|
+
handleCliError(error, "user");
|
|
2586
|
+
}
|
|
2587
|
+
});
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
const registerTestSubscribe = defineTestSubscription({
|
|
2591
|
+
name: "subscribe",
|
|
2592
|
+
description: "Subscribe to a test's notifications — its new comments and the changes it produces",
|
|
2593
|
+
perform: async ({ client, owner, project, testId }) => unwrap(await client.POST("/projects/{owner}/{project}/tests/{testId}/subscription", { params: { path: {
|
|
2594
|
+
owner,
|
|
2595
|
+
project,
|
|
2596
|
+
testId
|
|
2597
|
+
} } }))
|
|
2598
|
+
});
|
|
2599
|
+
const registerTestUnsubscribe = defineTestSubscription({
|
|
2600
|
+
name: "unsubscribe",
|
|
2601
|
+
description: "Stop receiving notifications about a test. Argos will not auto-subscribe you to it again",
|
|
2602
|
+
perform: async ({ client, owner, project, testId }) => unwrap(await client.DELETE("/projects/{owner}/{project}/tests/{testId}/subscription", { params: { path: {
|
|
2603
|
+
owner,
|
|
2604
|
+
project,
|
|
2605
|
+
testId
|
|
2606
|
+
} } }))
|
|
2607
|
+
});
|
|
2608
|
+
//#endregion
|
|
1789
2609
|
//#region src/commands/test/index.ts
|
|
1790
2610
|
function testCommand(program) {
|
|
1791
2611
|
const test = program.command("test").description("Inspect a test's flakiness and the changes that keep coming back");
|
|
2612
|
+
registerTestList(test);
|
|
1792
2613
|
registerTestGet(test);
|
|
1793
2614
|
registerTestChanges(test);
|
|
1794
2615
|
registerTestComment(test);
|
|
2616
|
+
registerTestSubscribe(test);
|
|
2617
|
+
registerTestUnsubscribe(test);
|
|
2618
|
+
}
|
|
2619
|
+
//#endregion
|
|
2620
|
+
//#region src/commands/account/_run.ts
|
|
2621
|
+
/**
|
|
2622
|
+
* Run an account-scoped command end to end: resolve the account target, run the
|
|
2623
|
+
* handler, print the result, and turn any failure into a clean CLI error.
|
|
2624
|
+
*
|
|
2625
|
+
* Every account endpoint acts as a user, so failures get the personal access
|
|
2626
|
+
* token hint.
|
|
2627
|
+
*/
|
|
2628
|
+
async function runAccountAction(opts) {
|
|
2629
|
+
try {
|
|
2630
|
+
const target = await resolveAccountTarget(opts.options);
|
|
2631
|
+
output(await opts.handler(target), opts.options, opts.format);
|
|
2632
|
+
} catch (error) {
|
|
2633
|
+
handleCliError(error, "user");
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
//#endregion
|
|
2637
|
+
//#region src/commands/account/domain/index.ts
|
|
2638
|
+
function registerAccountDomain(account) {
|
|
2639
|
+
const domain = account.command("domain").description("Manage the email domains a team is open to: anyone signing up with a verified address on one joins automatically");
|
|
2640
|
+
domain.command("list").description("List the email domains a team is open to").addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((options) => runAccountAction({
|
|
2641
|
+
options,
|
|
2642
|
+
handler: async ({ client, accountSlug }) => unwrap(await client.GET("/accounts/{accountSlug}/domains", { params: { path: { accountSlug } } })),
|
|
2643
|
+
format: formatDomains
|
|
2644
|
+
}));
|
|
2645
|
+
domain.command("add").description("Open a team to an email domain. You must hold a verified address on it; public email providers are refused").argument("<domain>", "Email domain, e.g. acme.com").addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((value, options) => runAccountAction({
|
|
2646
|
+
options,
|
|
2647
|
+
handler: async ({ client, accountSlug }) => unwrap(await client.POST("/accounts/{accountSlug}/domains", {
|
|
2648
|
+
params: { path: { accountSlug } },
|
|
2649
|
+
body: { domain: value }
|
|
2650
|
+
})),
|
|
2651
|
+
format: formatDomain
|
|
2652
|
+
}));
|
|
2653
|
+
domain.command("remove").description("Close a team to an email domain. Members who already joined through it stay").argument("<domain>", "Email domain to remove").addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((value, options) => runAccountAction({
|
|
2654
|
+
options,
|
|
2655
|
+
handler: async ({ client, accountSlug }) => {
|
|
2656
|
+
unwrapEmpty(await client.DELETE("/accounts/{accountSlug}/domains/{domain}", { params: { path: {
|
|
2657
|
+
accountSlug,
|
|
2658
|
+
domain: value
|
|
2659
|
+
} } }));
|
|
2660
|
+
return {
|
|
2661
|
+
removed: true,
|
|
2662
|
+
domain: value
|
|
2663
|
+
};
|
|
2664
|
+
},
|
|
2665
|
+
format: ({ domain: removed }) => `Closed the team to ${removed}. Existing members keep their access.`
|
|
2666
|
+
}));
|
|
2667
|
+
}
|
|
2668
|
+
//#endregion
|
|
2669
|
+
//#region src/commands/account/get.ts
|
|
2670
|
+
function registerAccountGet(account) {
|
|
2671
|
+
account.command("get").description("Fetch an account with its plan and current-period usage").addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((options) => runAccountAction({
|
|
2672
|
+
options,
|
|
2673
|
+
handler: async ({ client, accountSlug }) => unwrap(await client.GET("/accounts/{accountSlug}", { params: { path: { accountSlug } } })),
|
|
2674
|
+
format: formatAccount
|
|
2675
|
+
}));
|
|
2676
|
+
}
|
|
2677
|
+
//#endregion
|
|
2678
|
+
//#region src/commands/account/invite/cancel.ts
|
|
2679
|
+
function registerInviteCancel(invite) {
|
|
2680
|
+
invite.command("cancel").description("Cancel a pending invite, invalidating its link").argument("<inviteId>", "Invite ID, taken from `argos account invite list`").addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((inviteId, options) => runAccountAction({
|
|
2681
|
+
options,
|
|
2682
|
+
handler: async ({ client, accountSlug }) => {
|
|
2683
|
+
unwrapEmpty(await client.DELETE("/accounts/{accountSlug}/invites/{inviteId}", { params: { path: {
|
|
2684
|
+
accountSlug,
|
|
2685
|
+
inviteId
|
|
2686
|
+
} } }));
|
|
2687
|
+
return {
|
|
2688
|
+
cancelled: true,
|
|
2689
|
+
inviteId
|
|
2690
|
+
};
|
|
2691
|
+
},
|
|
2692
|
+
format: ({ inviteId }) => `Cancelled invite ${inviteId}.`
|
|
2693
|
+
}));
|
|
2694
|
+
}
|
|
2695
|
+
//#endregion
|
|
2696
|
+
//#region src/commands/account/invite/create.ts
|
|
2697
|
+
const TEAM_USER_LEVELS$1 = [
|
|
2698
|
+
"owner",
|
|
2699
|
+
"member",
|
|
2700
|
+
"contributor"
|
|
2701
|
+
];
|
|
2702
|
+
function registerInviteCreate(invite) {
|
|
2703
|
+
invite.command("create").description("Invite people to a team by email. Re-inviting a pending address refreshes its invite").argument("<emails...>", "Email addresses to invite").addOption(new Option("--level <level>", "Role to give the invited people").choices(TEAM_USER_LEVELS$1).default("member")).addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((emails, options) => runAccountAction({
|
|
2704
|
+
options,
|
|
2705
|
+
handler: async ({ client, accountSlug }) => unwrap(await client.POST("/accounts/{accountSlug}/invites", {
|
|
2706
|
+
params: { path: { accountSlug } },
|
|
2707
|
+
body: { members: emails.map((email) => ({
|
|
2708
|
+
email,
|
|
2709
|
+
level: options.level
|
|
2710
|
+
})) }
|
|
2711
|
+
})),
|
|
2712
|
+
format: formatInvites
|
|
2713
|
+
}));
|
|
2714
|
+
}
|
|
2715
|
+
//#endregion
|
|
2716
|
+
//#region src/commands/account/invite/list.ts
|
|
2717
|
+
function registerInviteList(invite) {
|
|
2718
|
+
invite.command("list").description("List a team's pending invites, most recent first").option("--search <query>", "Match invites on their email address").addOption(limitOption).addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((options) => runAccountAction({
|
|
2719
|
+
options,
|
|
2720
|
+
handler: ({ client, accountSlug }) => fetchPages(toLimit(options.limit), async (pagination) => unwrap(await client.GET("/accounts/{accountSlug}/invites", { params: {
|
|
2721
|
+
path: { accountSlug },
|
|
2722
|
+
query: {
|
|
2723
|
+
...pagination,
|
|
2724
|
+
...options.search ? { search: options.search } : {}
|
|
2725
|
+
}
|
|
2726
|
+
} }))),
|
|
2727
|
+
format: formatInvites
|
|
2728
|
+
}));
|
|
2729
|
+
}
|
|
2730
|
+
//#endregion
|
|
2731
|
+
//#region src/commands/account/invite/reset-link.ts
|
|
2732
|
+
function registerInviteResetLink(invite) {
|
|
2733
|
+
invite.command("reset-link").description("Rotate the team's shared invite link, invalidating the previous one").addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((options) => runAccountAction({
|
|
2734
|
+
options,
|
|
2735
|
+
handler: async ({ client, accountSlug }) => unwrap(await client.POST("/accounts/{accountSlug}/invite-link/reset", { params: { path: { accountSlug } } })),
|
|
2736
|
+
format: formatInviteLink
|
|
2737
|
+
}));
|
|
2738
|
+
}
|
|
2739
|
+
//#endregion
|
|
2740
|
+
//#region src/commands/account/invite/index.ts
|
|
2741
|
+
function registerAccountInvite(account) {
|
|
2742
|
+
const invite = account.command("invite").description("Invite people to a team and manage pending invitations");
|
|
2743
|
+
registerInviteList(invite);
|
|
2744
|
+
registerInviteCreate(invite);
|
|
2745
|
+
registerInviteCancel(invite);
|
|
2746
|
+
registerInviteResetLink(invite);
|
|
2747
|
+
}
|
|
2748
|
+
//#endregion
|
|
2749
|
+
//#region src/commands/account/member/list.ts
|
|
2750
|
+
const ORDER_BY_CHOICES = [
|
|
2751
|
+
"date",
|
|
2752
|
+
"name-asc",
|
|
2753
|
+
"name-desc"
|
|
2754
|
+
];
|
|
2755
|
+
function registerMemberList(member) {
|
|
2756
|
+
member.command("list").description("List a team's members and their roles").option("--search <query>", "Match members on their name, slug, or email").option("--levels <levels>", "Restrict to the given roles, comma-separated (e.g. owner,member)").addOption(new Option("--order-by <order>", "Ordering of the results").choices(ORDER_BY_CHOICES)).addOption(limitOption).addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((options) => runAccountAction({
|
|
2757
|
+
options,
|
|
2758
|
+
handler: ({ client, accountSlug }) => fetchPages(toLimit(options.limit), async (pagination) => unwrap(await client.GET("/accounts/{accountSlug}/members", { params: {
|
|
2759
|
+
path: { accountSlug },
|
|
2760
|
+
query: {
|
|
2761
|
+
...pagination,
|
|
2762
|
+
...options.search ? { search: options.search } : {},
|
|
2763
|
+
...options.levels ? { levels: options.levels } : {},
|
|
2764
|
+
...options.orderBy ? { orderBy: options.orderBy } : {}
|
|
2765
|
+
}
|
|
2766
|
+
} }))),
|
|
2767
|
+
format: formatMembers
|
|
2768
|
+
}));
|
|
2769
|
+
}
|
|
2770
|
+
//#endregion
|
|
2771
|
+
//#region src/commands/account/member/remove.ts
|
|
2772
|
+
function registerMemberRemove(member) {
|
|
2773
|
+
member.command("remove").description("Remove a member from a team. The last member cannot be removed; removing the second-to-last one promotes the survivor to owner").argument("<userId>", "User ID, taken from `argos account member list`").addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((userId, options) => runAccountAction({
|
|
2774
|
+
options,
|
|
2775
|
+
handler: async ({ client, accountSlug }) => {
|
|
2776
|
+
unwrapEmpty(await client.DELETE("/accounts/{accountSlug}/members/{userId}", { params: { path: {
|
|
2777
|
+
accountSlug,
|
|
2778
|
+
userId
|
|
2779
|
+
} } }));
|
|
2780
|
+
return {
|
|
2781
|
+
removed: true,
|
|
2782
|
+
userId
|
|
2783
|
+
};
|
|
2784
|
+
},
|
|
2785
|
+
format: ({ userId }) => `Removed user ${userId} from the team.`
|
|
2786
|
+
}));
|
|
2787
|
+
}
|
|
2788
|
+
//#endregion
|
|
2789
|
+
//#region src/commands/account/member/set-level.ts
|
|
2790
|
+
const TEAM_USER_LEVELS = [
|
|
2791
|
+
"owner",
|
|
2792
|
+
"member",
|
|
2793
|
+
"contributor"
|
|
2794
|
+
];
|
|
2795
|
+
function registerMemberSetLevel(member) {
|
|
2796
|
+
member.command("set-level").description("Change a team member's role").argument("<userId>", "User ID, taken from `argos account member list`").addOption(new Option("--level <level>", "Role to give the member").choices(TEAM_USER_LEVELS).makeOptionMandatory()).addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((userId, options) => runAccountAction({
|
|
2797
|
+
options,
|
|
2798
|
+
handler: async ({ client, accountSlug }) => unwrap(await client.PATCH("/accounts/{accountSlug}/members/{userId}", {
|
|
2799
|
+
params: { path: {
|
|
2800
|
+
accountSlug,
|
|
2801
|
+
userId
|
|
2802
|
+
} },
|
|
2803
|
+
body: { level: options.level }
|
|
2804
|
+
})),
|
|
2805
|
+
format: formatMember
|
|
2806
|
+
}));
|
|
2807
|
+
}
|
|
2808
|
+
//#endregion
|
|
2809
|
+
//#region src/commands/account/member/index.ts
|
|
2810
|
+
function registerAccountMember(account) {
|
|
2811
|
+
const member = account.command("member").description("List a team's members, change their role, or remove them");
|
|
2812
|
+
registerMemberList(member);
|
|
2813
|
+
registerMemberSetLevel(member);
|
|
2814
|
+
registerMemberRemove(member);
|
|
2815
|
+
}
|
|
2816
|
+
//#endregion
|
|
2817
|
+
//#region src/commands/account/update.ts
|
|
2818
|
+
const DEFAULT_USER_LEVELS = ["member", "contributor"];
|
|
2819
|
+
function registerAccountUpdate(account) {
|
|
2820
|
+
account.command("update").description("Change the role given to users joining a team through its invite link or a verified email domain").addOption(new Option("--default-user-level <level>", "Role given to users that join the team automatically").choices(DEFAULT_USER_LEVELS).makeOptionMandatory()).addOption(accountSlugOption).addOption(tokenOption).addOption(jsonOption).action((options) => runAccountAction({
|
|
2821
|
+
options,
|
|
2822
|
+
handler: async ({ client, accountSlug }) => unwrap(await client.PATCH("/accounts/{accountSlug}", {
|
|
2823
|
+
params: { path: { accountSlug } },
|
|
2824
|
+
body: { defaultUserLevel: options.defaultUserLevel }
|
|
2825
|
+
})),
|
|
2826
|
+
format: formatAccount
|
|
2827
|
+
}));
|
|
2828
|
+
}
|
|
2829
|
+
//#endregion
|
|
2830
|
+
//#region src/commands/account/index.ts
|
|
2831
|
+
function accountCommand(program) {
|
|
2832
|
+
const account = program.command("account").description("Inspect an account's plan and usage, and manage a team's members, invites, and email domains");
|
|
2833
|
+
registerAccountGet(account);
|
|
2834
|
+
registerAccountUpdate(account);
|
|
2835
|
+
registerAccountMember(account);
|
|
2836
|
+
registerAccountInvite(account);
|
|
2837
|
+
registerAccountDomain(account);
|
|
2838
|
+
}
|
|
2839
|
+
//#endregion
|
|
2840
|
+
//#region src/commands/project/_run.ts
|
|
2841
|
+
/**
|
|
2842
|
+
* Run a project-scoped command end to end: resolve the project target, run the
|
|
2843
|
+
* handler, print the result, and turn any failure into a clean CLI error.
|
|
2844
|
+
*
|
|
2845
|
+
* `auth` follows {@link resolveProjectTarget}: `project` lets a project token
|
|
2846
|
+
* fall back to its own project, `user` requires an explicit project path.
|
|
2847
|
+
*/
|
|
2848
|
+
async function runProjectAction(opts) {
|
|
2849
|
+
try {
|
|
2850
|
+
const target = await resolveProjectTarget(opts.options, { auth: opts.auth });
|
|
2851
|
+
output(await opts.handler(target), opts.options, opts.format);
|
|
2852
|
+
} catch (error) {
|
|
2853
|
+
handleCliError(error, opts.auth);
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
//#endregion
|
|
2857
|
+
//#region src/commands/project/contributor.ts
|
|
2858
|
+
const PROJECT_USER_LEVELS$1 = [
|
|
2859
|
+
"admin",
|
|
2860
|
+
"reviewer",
|
|
2861
|
+
"viewer"
|
|
2862
|
+
];
|
|
2863
|
+
function registerProjectContributor(project) {
|
|
2864
|
+
const contributor = project.command("contributor").description("Manage the users explicitly granted access to a project. Team owners and members already reach every project");
|
|
2865
|
+
contributor.command("list").description("List a project's contributors and their access level").addOption(limitOption).addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((options) => runProjectAction({
|
|
2866
|
+
options,
|
|
2867
|
+
auth: "user",
|
|
2868
|
+
handler: ({ client, owner, project: name }) => fetchPages(toLimit(options.limit), async (pagination) => unwrap(await client.GET("/projects/{owner}/{project}/contributors", { params: {
|
|
2869
|
+
path: {
|
|
2870
|
+
owner,
|
|
2871
|
+
project: name
|
|
2872
|
+
},
|
|
2873
|
+
query: pagination
|
|
2874
|
+
} }))),
|
|
2875
|
+
format: formatContributors
|
|
2876
|
+
}));
|
|
2877
|
+
contributor.command("set").description("Grant a user access to a project, or change the level they already hold").argument("<userId>", "User ID, taken from `argos account member list` or `argos project contributor list`").addOption(new Option("--level <level>", "Access level to grant").choices(PROJECT_USER_LEVELS$1).makeOptionMandatory()).addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((userId, options) => runProjectAction({
|
|
2878
|
+
options,
|
|
2879
|
+
auth: "user",
|
|
2880
|
+
handler: async ({ client, owner, project: name }) => unwrap(await client.PUT("/projects/{owner}/{project}/contributors/{userId}", {
|
|
2881
|
+
params: { path: {
|
|
2882
|
+
owner,
|
|
2883
|
+
project: name,
|
|
2884
|
+
userId
|
|
2885
|
+
} },
|
|
2886
|
+
body: { level: options.level }
|
|
2887
|
+
})),
|
|
2888
|
+
format: formatContributor
|
|
2889
|
+
}));
|
|
2890
|
+
contributor.command("remove").description("Revoke a user's access to a project. Removing yourself never needs administrator access").argument("<userId>", "User ID of the contributor to remove").addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((userId, options) => runProjectAction({
|
|
2891
|
+
options,
|
|
2892
|
+
auth: "user",
|
|
2893
|
+
handler: async ({ client, owner, project: name }) => {
|
|
2894
|
+
unwrapEmpty(await client.DELETE("/projects/{owner}/{project}/contributors/{userId}", { params: { path: {
|
|
2895
|
+
owner,
|
|
2896
|
+
project: name,
|
|
2897
|
+
userId
|
|
2898
|
+
} } }));
|
|
2899
|
+
return {
|
|
2900
|
+
removed: true,
|
|
2901
|
+
userId
|
|
2902
|
+
};
|
|
2903
|
+
},
|
|
2904
|
+
format: ({ userId: removed }) => `Revoked access for user ${removed}.`
|
|
2905
|
+
}));
|
|
2906
|
+
}
|
|
2907
|
+
//#endregion
|
|
2908
|
+
//#region src/commands/project/deployments.ts
|
|
2909
|
+
const ENVIRONMENTS = ["preview", "production"];
|
|
2910
|
+
function registerProjectDeployments(project) {
|
|
2911
|
+
project.command("deployments").description("List a project's deployments, most recent first").addOption(new Option("--environment <environment>", "Restrict to one environment. Use production to see what is live right now").choices(ENVIRONMENTS)).addOption(limitOption).addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((options) => runProjectAction({
|
|
2912
|
+
options,
|
|
2913
|
+
auth: "project",
|
|
2914
|
+
handler: ({ client, owner, project: name }) => fetchPages(toLimit(options.limit), async (pagination) => unwrap(await client.GET("/projects/{owner}/{project}/deployments", { params: {
|
|
2915
|
+
path: {
|
|
2916
|
+
owner,
|
|
2917
|
+
project: name
|
|
2918
|
+
},
|
|
2919
|
+
query: {
|
|
2920
|
+
...pagination,
|
|
2921
|
+
...options.environment ? { environment: options.environment } : {}
|
|
2922
|
+
}
|
|
2923
|
+
} }))),
|
|
2924
|
+
format: formatDeployments
|
|
2925
|
+
}));
|
|
2926
|
+
}
|
|
2927
|
+
//#endregion
|
|
2928
|
+
//#region src/commands/project/domain.ts
|
|
2929
|
+
function registerProjectDomain(project) {
|
|
2930
|
+
const domain = project.command("domain").description("Read or set the domain a project's production deployments are served on");
|
|
2931
|
+
domain.command("get").description("Get a project's production deployment domain").addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((options) => runProjectAction({
|
|
2932
|
+
options,
|
|
2933
|
+
auth: "project",
|
|
2934
|
+
handler: async ({ client, owner, project: name }) => unwrap(await client.GET("/projects/{owner}/{project}/domain", { params: { path: {
|
|
2935
|
+
owner,
|
|
2936
|
+
project: name
|
|
2937
|
+
} } })),
|
|
2938
|
+
format: formatProjectDomain
|
|
2939
|
+
}));
|
|
2940
|
+
domain.command("set").description("Set a project's production deployment domain. Only domains under the Argos deployments domain are accepted").argument("<domain>", "Full domain, e.g. acme-web.argos-ci.live").addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((value, options) => runProjectAction({
|
|
2941
|
+
options,
|
|
2942
|
+
auth: "user",
|
|
2943
|
+
handler: async ({ client, owner, project: name }) => unwrap(await client.PUT("/projects/{owner}/{project}/domain", {
|
|
2944
|
+
params: { path: {
|
|
2945
|
+
owner,
|
|
2946
|
+
project: name
|
|
2947
|
+
} },
|
|
2948
|
+
body: { domain: value }
|
|
2949
|
+
})),
|
|
2950
|
+
format: formatProjectDomain
|
|
2951
|
+
}));
|
|
2952
|
+
}
|
|
2953
|
+
//#endregion
|
|
2954
|
+
//#region src/commands/project/get.ts
|
|
2955
|
+
function registerProjectGet(project) {
|
|
2956
|
+
project.command("get").description("Fetch a project and its settings").addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((options) => runProjectAction({
|
|
2957
|
+
options,
|
|
2958
|
+
auth: "project",
|
|
2959
|
+
handler: async ({ client, owner, project: name }) => unwrap(await client.GET("/projects/{owner}/{project}", { params: { path: {
|
|
2960
|
+
owner,
|
|
2961
|
+
project: name
|
|
2962
|
+
} } })),
|
|
2963
|
+
format: formatProject
|
|
2964
|
+
}));
|
|
2965
|
+
}
|
|
2966
|
+
//#endregion
|
|
2967
|
+
//#region src/commands/project/transfer.ts
|
|
2968
|
+
function registerProjectTransfer(project) {
|
|
2969
|
+
project.command("transfer").description("Move a project to another account. You must administer the project and the account receiving it").addOption(new Option("--to <slug>", "Slug of the account that will own the project").makeOptionMandatory()).option("--name <name>", "Name to give the project on the target account. Defaults to its current name, which must be free there").addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((options) => runProjectAction({
|
|
2970
|
+
options,
|
|
2971
|
+
auth: "user",
|
|
2972
|
+
handler: async ({ client, owner, project: name }) => unwrap(await client.POST("/projects/{owner}/{project}/transfer", {
|
|
2973
|
+
params: { path: {
|
|
2974
|
+
owner,
|
|
2975
|
+
project: name
|
|
2976
|
+
} },
|
|
2977
|
+
body: {
|
|
2978
|
+
targetAccountSlug: options.to,
|
|
2979
|
+
...options.name ? { name: options.name } : {}
|
|
2980
|
+
}
|
|
2981
|
+
})),
|
|
2982
|
+
format: formatProject
|
|
2983
|
+
}));
|
|
2984
|
+
}
|
|
2985
|
+
//#endregion
|
|
2986
|
+
//#region src/commands/project/update.ts
|
|
2987
|
+
const BOOLEAN_CHOICES = ["true", "false"];
|
|
2988
|
+
const SUMMARY_CHECKS = [
|
|
2989
|
+
"always",
|
|
2990
|
+
"never",
|
|
2991
|
+
"auto"
|
|
2992
|
+
];
|
|
2993
|
+
const DEPLOYMENT_AUTHS = [
|
|
2994
|
+
"public",
|
|
2995
|
+
"domain-private",
|
|
2996
|
+
"private"
|
|
2997
|
+
];
|
|
2998
|
+
const PROJECT_USER_LEVELS = [
|
|
2999
|
+
"admin",
|
|
3000
|
+
"reviewer",
|
|
3001
|
+
"viewer"
|
|
3002
|
+
];
|
|
3003
|
+
function toBoolean(value) {
|
|
3004
|
+
return value === "true";
|
|
3005
|
+
}
|
|
3006
|
+
/** An empty string resets a nullable setting to its inherited default. */
|
|
3007
|
+
function toNullable(value) {
|
|
3008
|
+
return value === "" ? null : value;
|
|
3009
|
+
}
|
|
3010
|
+
/**
|
|
3011
|
+
* Build the `ignoreConfig` object. The API takes it whole, so a command that
|
|
3012
|
+
* touches only one of its two settings has to read the other back from the
|
|
3013
|
+
* project first.
|
|
3014
|
+
*/
|
|
3015
|
+
async function resolveIgnoreConfig(options, load) {
|
|
3016
|
+
if (!options.ignoreChanges && !options.autoIgnoreAfter) return;
|
|
3017
|
+
const current = await load();
|
|
3018
|
+
const enabled = options.ignoreChanges ? toBoolean(options.ignoreChanges) : current?.enabled ?? true;
|
|
3019
|
+
if (!options.autoIgnoreAfter) return {
|
|
3020
|
+
enabled,
|
|
3021
|
+
autoIgnore: current?.autoIgnore ?? null
|
|
3022
|
+
};
|
|
3023
|
+
if (options.autoIgnoreAfter === "off") return {
|
|
3024
|
+
enabled,
|
|
3025
|
+
autoIgnore: null
|
|
3026
|
+
};
|
|
3027
|
+
const changes = Number(options.autoIgnoreAfter);
|
|
3028
|
+
if (!Number.isInteger(changes) || changes < 1) fail(`--auto-ignore-after must be a positive integer or "off", received "${options.autoIgnoreAfter}".`);
|
|
3029
|
+
return {
|
|
3030
|
+
enabled,
|
|
3031
|
+
autoIgnore: { changes }
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
/** Map the flags onto the request body, leaving untouched settings out. */
|
|
3035
|
+
async function buildBody(options, load) {
|
|
3036
|
+
const body = {};
|
|
3037
|
+
if (options.name !== void 0) body.name = options.name;
|
|
3038
|
+
if (options.defaultBaseBranch !== void 0) body.defaultBaseBranch = toNullable(options.defaultBaseBranch);
|
|
3039
|
+
if (options.autoApprovedBranchGlob !== void 0) body.autoApprovedBranchGlob = toNullable(options.autoApprovedBranchGlob);
|
|
3040
|
+
if (options.deploymentProductionBranchGlob !== void 0) body.deploymentProductionBranchGlob = toNullable(options.deploymentProductionBranchGlob);
|
|
3041
|
+
if (options.private !== void 0) body.private = options.private === "inherit" ? null : toBoolean(options.private);
|
|
3042
|
+
if (options.summaryCheck !== void 0) body.summaryCheck = options.summaryCheck;
|
|
3043
|
+
if (options.defaultUserLevel !== void 0) body.defaultUserLevel = options.defaultUserLevel === "none" ? null : options.defaultUserLevel;
|
|
3044
|
+
if (options.deployments !== void 0) body.deploymentEnabled = toBoolean(options.deployments);
|
|
3045
|
+
if (options.deploymentAuth !== void 0) body.deploymentAuth = options.deploymentAuth;
|
|
3046
|
+
if (options.githubActionsOidc !== void 0) body.githubActionsOidcEnabled = toBoolean(options.githubActionsOidc);
|
|
3047
|
+
if (options.tokenlessAuth !== void 0) body.tokenlessAuthEnabled = toBoolean(options.tokenlessAuth);
|
|
3048
|
+
const ignoreConfig = await resolveIgnoreConfig(options, load);
|
|
3049
|
+
if (ignoreConfig !== void 0) body.ignoreConfig = ignoreConfig;
|
|
3050
|
+
return body;
|
|
3051
|
+
}
|
|
3052
|
+
/** Read the project's current ignore settings, to patch them partially. */
|
|
3053
|
+
async function loadIgnoreConfig(client, owner, project) {
|
|
3054
|
+
return unwrap(await client.GET("/projects/{owner}/{project}", { params: { path: {
|
|
3055
|
+
owner,
|
|
3056
|
+
project
|
|
3057
|
+
} } })).ignoreConfig;
|
|
3058
|
+
}
|
|
3059
|
+
function registerProjectUpdate(project) {
|
|
3060
|
+
project.command("update").description("Update a project's settings. Only the settings you pass are changed").option("--name <name>", "Rename the project").option("--default-base-branch <branch>", "Branch used as the baseline when no better one applies. Pass an empty string to fall back to the repository default").option("--auto-approved-branch-glob <glob>", "Glob matching the branches whose builds are approved automatically. Pass an empty string to fall back to the default base branch").option("--deployment-production-branch-glob <glob>", "Glob matching the branches whose deployments count as production. Pass an empty string to fall back to the repository default").addOption(new Option("--private <value>", "Force the project's privacy, or inherit it from the linked repository").choices([...BOOLEAN_CHOICES, "inherit"])).addOption(new Option("--summary-check <mode>", "When to post the summary check on a pull request").choices(SUMMARY_CHECKS)).addOption(new Option("--default-user-level <level>", "Access given to team members that are not contributors on this project").choices([...PROJECT_USER_LEVELS, "none"])).addOption(new Option("--ignore-changes <value>", "Whether changes can be ignored on this project").choices(BOOLEAN_CHOICES)).option("--auto-ignore-after <changes>", "Ignore a change automatically once it has reappeared this many times, or \"off\"").addOption(new Option("--deployments <value>", "Whether deployments are served for this project").choices(BOOLEAN_CHOICES)).addOption(new Option("--deployment-auth <mode>", "Who can reach the project's deployments").choices(DEPLOYMENT_AUTHS)).addOption(new Option("--github-actions-oidc <value>", "Whether builds can authenticate with a GitHub Actions OIDC token").choices(BOOLEAN_CHOICES)).addOption(new Option("--tokenless-auth <value>", "Whether builds from forked pull requests can be uploaded without a token").choices(BOOLEAN_CHOICES)).addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((options) => runProjectAction({
|
|
3061
|
+
options,
|
|
3062
|
+
auth: "user",
|
|
3063
|
+
handler: async ({ client, owner, project: name }) => {
|
|
3064
|
+
const body = await buildBody(options, () => loadIgnoreConfig(client, owner, name));
|
|
3065
|
+
if (Object.keys(body).length === 0) fail("Nothing to update. Pass at least one setting — run `argos project update --help` for the list.");
|
|
3066
|
+
return unwrap(await client.PATCH("/projects/{owner}/{project}", {
|
|
3067
|
+
params: { path: {
|
|
3068
|
+
owner,
|
|
3069
|
+
project: name
|
|
3070
|
+
} },
|
|
3071
|
+
body
|
|
3072
|
+
}));
|
|
3073
|
+
},
|
|
3074
|
+
format: formatProject
|
|
3075
|
+
}));
|
|
3076
|
+
}
|
|
3077
|
+
//#endregion
|
|
3078
|
+
//#region src/commands/project/index.ts
|
|
3079
|
+
function projectCommand(program) {
|
|
3080
|
+
const project = program.command("project").description("Inspect and configure a project: settings, contributors, deployments, and its deployment domain");
|
|
3081
|
+
registerProjectGet(project);
|
|
3082
|
+
registerProjectUpdate(project);
|
|
3083
|
+
registerProjectTransfer(project);
|
|
3084
|
+
registerProjectContributor(project);
|
|
3085
|
+
registerProjectDeployments(project);
|
|
3086
|
+
registerProjectDomain(project);
|
|
3087
|
+
}
|
|
3088
|
+
//#endregion
|
|
3089
|
+
//#region src/commands/automation/_definition.ts
|
|
3090
|
+
/**
|
|
3091
|
+
* Resolve an automation rule definition from the mutually-exclusive
|
|
3092
|
+
* `--definition` (inline JSON) and `--definition-file` (path) options.
|
|
3093
|
+
*
|
|
3094
|
+
* The definition is passed through as-is: events, conditions and actions are
|
|
3095
|
+
* validated by the API, which owns their schemas.
|
|
3096
|
+
*/
|
|
3097
|
+
async function resolveDefinition(options) {
|
|
3098
|
+
const { definition, definitionFile } = options;
|
|
3099
|
+
if (definition !== void 0 && definitionFile !== void 0) fail("Use either --definition or --definition-file, not both.");
|
|
3100
|
+
let raw;
|
|
3101
|
+
if (definition !== void 0) raw = definition;
|
|
3102
|
+
else if (definitionFile !== void 0) try {
|
|
3103
|
+
raw = await readFile(definitionFile, "utf8");
|
|
3104
|
+
} catch (error) {
|
|
3105
|
+
fail(`Failed to read --definition-file "${definitionFile}": ${error instanceof Error ? error.message : String(error)}`);
|
|
3106
|
+
}
|
|
3107
|
+
else fail("A rule definition is required. Use --definition <json> or --definition-file <path>.");
|
|
3108
|
+
try {
|
|
3109
|
+
return JSON.parse(raw);
|
|
3110
|
+
} catch (error) {
|
|
3111
|
+
fail(`Invalid rule definition JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
//#endregion
|
|
3115
|
+
//#region src/commands/automation/index.ts
|
|
3116
|
+
const ACTIVE_CHOICES = ["true", "false"];
|
|
3117
|
+
const definitionOption = new Option("--definition <json>", "Rule definition as JSON: name, events, conditions, actions");
|
|
3118
|
+
const definitionFileOption = new Option("--definition-file <path>", "Read the rule definition from a JSON file");
|
|
3119
|
+
const EXAMPLE_DEFINITION = `Example definition:
|
|
3120
|
+
{
|
|
3121
|
+
"name": "Notify on regressions",
|
|
3122
|
+
"events": ["build.completed"],
|
|
3123
|
+
"conditions": [{ "type": "build-conclusion", "value": "changes-detected" }],
|
|
3124
|
+
"actions": [{ "type": "sendSlackMessage", "payload": { "name": "argos-alerts" } }]
|
|
3125
|
+
}`;
|
|
3126
|
+
function automationCommand(program) {
|
|
3127
|
+
const automation = program.command("automation").description("List and manage a project's automation rules — the actions Argos runs when a build event matches");
|
|
3128
|
+
automation.command("list").description("List a project's automation rules, most recent first").addOption(new Option("--active <value>", "Restrict to rules that still fire, or to deactivated ones").choices(ACTIVE_CHOICES)).addOption(limitOption).addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((options) => runProjectAction({
|
|
3129
|
+
options,
|
|
3130
|
+
auth: "user",
|
|
3131
|
+
handler: ({ client, owner, project }) => fetchPages(toLimit(options.limit), async (pagination) => unwrap(await client.GET("/projects/{owner}/{project}/automation-rules", { params: {
|
|
3132
|
+
path: {
|
|
3133
|
+
owner,
|
|
3134
|
+
project
|
|
3135
|
+
},
|
|
3136
|
+
query: {
|
|
3137
|
+
...pagination,
|
|
3138
|
+
...options.active ? { active: options.active } : {}
|
|
3139
|
+
}
|
|
3140
|
+
} }))),
|
|
3141
|
+
format: formatAutomationRules
|
|
3142
|
+
}));
|
|
3143
|
+
automation.command("get").description("Fetch a single automation rule").argument("<ruleId>", "Rule ID, taken from `argos automation list`").addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((ruleId, options) => runProjectAction({
|
|
3144
|
+
options,
|
|
3145
|
+
auth: "user",
|
|
3146
|
+
handler: async ({ client, owner, project }) => unwrap(await client.GET("/projects/{owner}/{project}/automation-rules/{ruleId}", { params: { path: {
|
|
3147
|
+
owner,
|
|
3148
|
+
project,
|
|
3149
|
+
ruleId
|
|
3150
|
+
} } })),
|
|
3151
|
+
format: formatAutomationRule
|
|
3152
|
+
}));
|
|
3153
|
+
automation.command("create").description("Create an automation rule on a project").addHelpText("after", `\n${EXAMPLE_DEFINITION}\n`).addOption(definitionOption).addOption(definitionFileOption).addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((options) => runProjectAction({
|
|
3154
|
+
options,
|
|
3155
|
+
auth: "user",
|
|
3156
|
+
handler: async ({ client, owner, project }) => {
|
|
3157
|
+
const body = await resolveDefinition(options);
|
|
3158
|
+
return unwrap(await client.POST("/projects/{owner}/{project}/automation-rules", {
|
|
3159
|
+
params: { path: {
|
|
3160
|
+
owner,
|
|
3161
|
+
project
|
|
3162
|
+
} },
|
|
3163
|
+
body
|
|
3164
|
+
}));
|
|
3165
|
+
},
|
|
3166
|
+
format: formatAutomationRule
|
|
3167
|
+
}));
|
|
3168
|
+
automation.command("update").description("Replace an automation rule's definition. Send the events, conditions and actions you want the rule to end up with").argument("<ruleId>", "Rule ID, taken from `argos automation list`").addHelpText("after", `\n${EXAMPLE_DEFINITION}\n`).addOption(definitionOption).addOption(definitionFileOption).addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((ruleId, options) => runProjectAction({
|
|
3169
|
+
options,
|
|
3170
|
+
auth: "user",
|
|
3171
|
+
handler: async ({ client, owner, project }) => {
|
|
3172
|
+
const body = await resolveDefinition(options);
|
|
3173
|
+
return unwrap(await client.PUT("/projects/{owner}/{project}/automation-rules/{ruleId}", {
|
|
3174
|
+
params: { path: {
|
|
3175
|
+
owner,
|
|
3176
|
+
project,
|
|
3177
|
+
ruleId
|
|
3178
|
+
} },
|
|
3179
|
+
body
|
|
3180
|
+
}));
|
|
3181
|
+
},
|
|
3182
|
+
format: formatAutomationRule
|
|
3183
|
+
}));
|
|
3184
|
+
automation.command("deactivate").description("Stop a rule from firing. Rules are never deleted — a deactivated one keeps its run history").argument("<ruleId>", "Rule ID, taken from `argos automation list`").addOption(managedProjectPathOption).addOption(tokenOption).addOption(jsonOption).action((ruleId, options) => runProjectAction({
|
|
3185
|
+
options,
|
|
3186
|
+
auth: "user",
|
|
3187
|
+
handler: async ({ client, owner, project }) => unwrap(await client.POST("/projects/{owner}/{project}/automation-rules/{ruleId}/deactivate", { params: { path: {
|
|
3188
|
+
owner,
|
|
3189
|
+
project,
|
|
3190
|
+
ruleId
|
|
3191
|
+
} } })),
|
|
3192
|
+
format: formatAutomationRule
|
|
3193
|
+
}));
|
|
1795
3194
|
}
|
|
1796
3195
|
//#endregion
|
|
1797
3196
|
//#region src/index.ts
|
|
@@ -1812,7 +3211,11 @@ whoamiCommand(program);
|
|
|
1812
3211
|
createProjectCommand(program);
|
|
1813
3212
|
analyticsCommand(program);
|
|
1814
3213
|
changeCommand(program);
|
|
3214
|
+
mediaCommand(program);
|
|
1815
3215
|
testCommand(program);
|
|
3216
|
+
accountCommand(program);
|
|
3217
|
+
projectCommand(program);
|
|
3218
|
+
automationCommand(program);
|
|
1816
3219
|
if (!process.argv.slice(2).length) program.outputHelp();
|
|
1817
3220
|
else program.parse(process.argv);
|
|
1818
3221
|
//#endregion
|