@botiverse/stamp-cli 0.3.14 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/bin/launch.js +124 -0
- package/bin/stamp-staging.js +3 -0
- package/bin/stamp.js +3 -0
- package/package.json +16 -13
- package/README.md +0 -225
- package/bin/stamp-staging.mjs +0 -15
- package/bin/stamp.mjs +0 -65
- package/lib/agent-login.mjs +0 -208
- package/lib/agent-refresh.mjs +0 -192
- package/lib/auth.mjs +0 -202
- package/lib/client.mjs +0 -92
- package/lib/commands/changelog.mjs +0 -58
- package/lib/commands/identity.mjs +0 -12
- package/lib/commands/key.mjs +0 -104
- package/lib/commands/knownhosts.mjs +0 -150
- package/lib/commands/pr.mjs +0 -298
- package/lib/commands/queue.mjs +0 -67
- package/lib/commands/receipt.mjs +0 -33
- package/lib/commands/repo.mjs +0 -130
- package/lib/commands/search.mjs +0 -63
- package/lib/commands/session.mjs +0 -71
- package/lib/commands/subscribe.mjs +0 -35
- package/lib/errors.mjs +0 -47
- package/lib/expiry.mjs +0 -27
- package/lib/flags.mjs +0 -26
- package/lib/locale.mjs +0 -385
- package/lib/main.mjs +0 -124
- package/lib/pr/close.mjs +0 -56
- package/lib/pr/comment.mjs +0 -45
- package/lib/pr/create.mjs +0 -165
- package/lib/pr/edit.mjs +0 -54
- package/lib/pr/queue.mjs +0 -32
- package/lib/pr/read.mjs +0 -473
- package/lib/pr/review.mjs +0 -88
- package/lib/pr/verdict.mjs +0 -66
- package/lib/pr/write.mjs +0 -180
- package/lib/queue/setup.mjs +0 -143
- package/lib/receipt/list.mjs +0 -54
- package/lib/repo/clone.mjs +0 -101
- package/lib/repo/identities.mjs +0 -45
- package/lib/repo/ssh.mjs +0 -326
- package/lib/update-check.mjs +0 -50
package/lib/commands/pr.mjs
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import { formatAutoMerge, isAutoMergeArgs, parsePRAutoMergeArgs, validatePRAutoMergeResult } from "../pr/write.mjs";
|
|
2
|
-
import { formatVerdictLine } from "../pr/verdict.mjs";
|
|
3
|
-
import { parsePRQueueArgs, validatePRQueueResult } from "../pr/queue.mjs";
|
|
4
|
-
import { t, prefix } from "../locale.mjs";
|
|
5
|
-
import { ApiError, NetworkError } from "../client.mjs";
|
|
6
|
-
import { AgentError, printGatewayError } from "../errors.mjs";
|
|
7
|
-
import { publishWaitMs, pullRequestDraft, pullRequestNextLines, stampPullRequestPage, pullRequestInput, pullRequestNeedsReceipt, pullRequestRecovery, waitForPublishedReceipt } from "../pr/create.mjs";
|
|
8
|
-
import { parsePRCommentArgs, validatePRCommentResult } from "../pr/comment.mjs";
|
|
9
|
-
import { parsePREditArgs, validatePREditResult } from "../pr/edit.mjs";
|
|
10
|
-
import { parsePRCloseArgs, validatePRCloseResult } from "../pr/close.mjs";
|
|
11
|
-
import { formatPRReview, reviewBrief } from "../pr/review.mjs";
|
|
12
|
-
import { parsePRApproveArgs, parsePRMergeArgs, parsePRUnapproveArgs, validatePRApproveResult, validatePRMergeResult, validatePRUnapproveResult } from "../pr/write.mjs";
|
|
13
|
-
import {
|
|
14
|
-
formatPRChecks,
|
|
15
|
-
formatPRDetail,
|
|
16
|
-
formatPRDiff,
|
|
17
|
-
formatPRList,
|
|
18
|
-
formatPRListSections,
|
|
19
|
-
parsePRDiffArgs,
|
|
20
|
-
parsePRListArgs,
|
|
21
|
-
parsePRTargetArgs,
|
|
22
|
-
prChecksExitCode,
|
|
23
|
-
prDetailPath,
|
|
24
|
-
PR_SECTIONS,
|
|
25
|
-
prDiffPath,
|
|
26
|
-
prSection,
|
|
27
|
-
safeInline,
|
|
28
|
-
validatePRDetail,
|
|
29
|
-
validatePRDiff,
|
|
30
|
-
validatePRListResponse,
|
|
31
|
-
} from "../pr/read.mjs";
|
|
32
|
-
|
|
33
|
-
function sectionLabels(locale) {
|
|
34
|
-
const labels = {};
|
|
35
|
-
for (const name of Object.values(PR_SECTIONS)) labels[`prSection_${name}`] = t(locale, `prSection_${name}`);
|
|
36
|
-
return labels;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// instanceLine names the Stamp instance a command talked to: approvals and
|
|
40
|
-
// merges are per instance, and prod and staging otherwise read the same.
|
|
41
|
-
function instanceLine(ctx) {
|
|
42
|
-
let host = "";
|
|
43
|
-
try { host = new URL(ctx.auth?.apiBase).host; } catch { /* no instance to name */ }
|
|
44
|
-
return host ? t(ctx.locale, "prInstance", { host }) : "";
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function outInstance(ctx) {
|
|
48
|
-
const line = instanceLine(ctx);
|
|
49
|
-
if (line) ctx.out(line);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function writeCommand(ctx, run) {
|
|
53
|
-
try {
|
|
54
|
-
await run();
|
|
55
|
-
} catch (e) {
|
|
56
|
-
// A refusal is where "which instance?" matters most (an approval made on
|
|
57
|
-
// the other one), so it is named there too.
|
|
58
|
-
const instance = ctx.nameInstance ? instanceLine(ctx) : "";
|
|
59
|
-
if (instance && !(e instanceof AgentError)) ctx.err(`${prefix()}${instance}`);
|
|
60
|
-
if (e instanceof NetworkError) {
|
|
61
|
-
// The request left the machine, so whether the write landed is unknown:
|
|
62
|
-
// keep the uncertainty contract and add what we know about the transport.
|
|
63
|
-
ctx.err(`${prefix()}${t(ctx.locale, ctx.unknownKey)}`);
|
|
64
|
-
ctx.err(`${prefix()}${t(ctx.locale, e.code, e.details)}`);
|
|
65
|
-
return ctx.exit(1);
|
|
66
|
-
}
|
|
67
|
-
if (e instanceof AgentError) throw e;
|
|
68
|
-
if (e instanceof ApiError && e.status >= 400 && e.status < 500) {
|
|
69
|
-
ctx.err(`${prefix()}${e.message}`);
|
|
70
|
-
printGatewayError(e, ctx.err);
|
|
71
|
-
} else {
|
|
72
|
-
ctx.err(`${prefix()}${t(ctx.locale, ctx.unknownKey)}`);
|
|
73
|
-
if (e instanceof ApiError) printGatewayError(e, ctx.err);
|
|
74
|
-
}
|
|
75
|
-
return ctx.exit(1);
|
|
76
|
-
}
|
|
77
|
-
return ctx.exit(0);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export async function run(ctx) {
|
|
81
|
-
const { args, api, emit, out, err, locale, exit } = ctx;
|
|
82
|
-
const sub = args.shift();
|
|
83
|
-
if (sub === "queue") {
|
|
84
|
-
ctx.unknownKey = "prQueueOutcomeUnknown";
|
|
85
|
-
return writeCommand(ctx, async () => {
|
|
86
|
-
const input = parsePRQueueArgs(args);
|
|
87
|
-
const result = validatePRQueueResult(await api(input.method, input.path, input.body), input);
|
|
88
|
-
emit(result, () => out(t(locale, "prQueueReceipt", { repository: result.repository, number: result.number, id: result.requestId, state: result.receipt.state, reason: result.receipt.reason || "—", landing: result.receipt.landingSha || "—", queued: String(result.receipt.notificationQueued) })));
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (sub === "comment") {
|
|
92
|
-
ctx.rejectKey = "prCommentRejected";
|
|
93
|
-
ctx.unknownKey = "prCommentOutcomeUnknown";
|
|
94
|
-
return writeCommand(ctx, async () => {
|
|
95
|
-
const input = parsePRCommentArgs(args);
|
|
96
|
-
const result = validatePRCommentResult(await api("POST", input.path, input.body), input.target);
|
|
97
|
-
emit(result, () => out(t(locale, "prCommentCreated", { url: result.url, actor: result.actorLogin })));
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
if (sub === "approve") {
|
|
101
|
-
ctx.rejectKey = "prApproveRejected";
|
|
102
|
-
ctx.unknownKey = "prApproveOutcomeUnknown";
|
|
103
|
-
ctx.nameInstance = true;
|
|
104
|
-
return writeCommand(ctx, async () => {
|
|
105
|
-
const input = parsePRApproveArgs(args);
|
|
106
|
-
const result = validatePRApproveResult(await api(input.method, input.path, input.body), input.target);
|
|
107
|
-
emit(result, () => {
|
|
108
|
-
out(result.recordedBy === "stamp"
|
|
109
|
-
? t(locale, "prApprovedByStamp", { actor: result.reviewer, repository: result.repository, number: result.number, head: result.approvedHead })
|
|
110
|
-
: t(locale, "prApproved", { actor: result.reviewerLogin, repository: result.repository, number: result.number }));
|
|
111
|
-
outInstance(ctx);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
if (sub === "unapprove") {
|
|
116
|
-
ctx.rejectKey = "prUnapproveRejected";
|
|
117
|
-
ctx.unknownKey = "prUnapproveOutcomeUnknown";
|
|
118
|
-
return writeCommand(ctx, async () => {
|
|
119
|
-
const input = parsePRUnapproveArgs(args);
|
|
120
|
-
const result = validatePRUnapproveResult(await api(input.method, input.path, input.body), input.target);
|
|
121
|
-
emit(result, () => out(t(locale, "prUnapproved", { actor: result.reviewer, repository: result.repository, number: result.number, head: result.approvedHead })));
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
if (sub === "merge" && isAutoMergeArgs(args)) {
|
|
125
|
-
ctx.rejectKey = "prMergeRejected";
|
|
126
|
-
ctx.unknownKey = "prMergeOutcomeUnknown";
|
|
127
|
-
ctx.nameInstance = true;
|
|
128
|
-
return writeCommand(ctx, async () => {
|
|
129
|
-
const input = parsePRAutoMergeArgs(args);
|
|
130
|
-
const result = validatePRAutoMergeResult(await api(input.method, input.path, input.body), input.target);
|
|
131
|
-
emit(result, () => {
|
|
132
|
-
out(formatAutoMerge(result, (key, vars) => t(locale, key, vars)));
|
|
133
|
-
outInstance(ctx);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
if (sub === "merge") {
|
|
138
|
-
ctx.rejectKey = "prMergeRejected";
|
|
139
|
-
ctx.unknownKey = "prMergeOutcomeUnknown";
|
|
140
|
-
ctx.nameInstance = true;
|
|
141
|
-
return writeCommand(ctx, async () => {
|
|
142
|
-
const input = parsePRMergeArgs(args);
|
|
143
|
-
const result = validatePRMergeResult(await api(input.method, input.path, input.body), input.target);
|
|
144
|
-
emit(result, () => {
|
|
145
|
-
out(result.mergedBy === "stamp-app"
|
|
146
|
-
? t(locale, "prMergedByApp", { actor: result.agent, sha: result.mergeSha, repository: result.repository, number: result.number, head: result.mergedHead })
|
|
147
|
-
: t(locale, "prMerged", { actor: result.actorLogin, sha: result.mergeSha, repository: result.repository, number: result.number }));
|
|
148
|
-
outInstance(ctx);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
if (sub === "close") {
|
|
153
|
-
ctx.rejectKey = "prCloseRejected";
|
|
154
|
-
ctx.unknownKey = "prCloseOutcomeUnknown";
|
|
155
|
-
return writeCommand(ctx, async () => {
|
|
156
|
-
const input = parsePRCloseArgs(args);
|
|
157
|
-
const result = validatePRCloseResult(await api(input.method, input.path, input.body), input.target);
|
|
158
|
-
emit(result, () => out(t(locale, "prClosed", { repository: result.repository, number: result.number, url: result.url })));
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
if (sub === "edit") {
|
|
162
|
-
ctx.rejectKey = "prEditRejected";
|
|
163
|
-
ctx.unknownKey = "prEditOutcomeUnknown";
|
|
164
|
-
return writeCommand(ctx, async () => {
|
|
165
|
-
const input = parsePREditArgs(args);
|
|
166
|
-
const result = validatePREditResult(await api("PATCH", input.path, input.body), input.target);
|
|
167
|
-
emit(result, () => out(t(locale, "prEdited", { repository: result.repository, number: result.number, url: result.url })));
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
if (sub === "create") {
|
|
171
|
-
const waitOpts = process.env.STAMP_PUBLISH_WAIT_MS ? { timeoutMs: publishWaitMs(process.env.STAMP_PUBLISH_WAIT_MS), intervalMs: 50 } : {};
|
|
172
|
-
// Validate everything that needs no network first, as before. One draft
|
|
173
|
-
// serves both builds, so the body is read once (see pullRequestDraft).
|
|
174
|
-
const draft = pullRequestDraft(args);
|
|
175
|
-
let input = pullRequestInput(args, pullRequestNeedsReceipt(args) ? { repository: "o/r", targetRef: "refs/heads/x", publishedSha: "0".repeat(40) } : null, draft);
|
|
176
|
-
let waited = false;
|
|
177
|
-
if (pullRequestNeedsReceipt(args)) {
|
|
178
|
-
input = pullRequestInput(args, await waitForPublishedReceipt(api, input.receiptId, waitOpts), draft);
|
|
179
|
-
waited = true;
|
|
180
|
-
}
|
|
181
|
-
try {
|
|
182
|
-
let d;
|
|
183
|
-
try {
|
|
184
|
-
d = await api("POST", "/v1/pull-requests", input);
|
|
185
|
-
} catch (e) {
|
|
186
|
-
// Created too soon after the push: wait for publication, then retry
|
|
187
|
-
// once with the same idempotency key.
|
|
188
|
-
if (waited || !(e instanceof ApiError) || e.body?.error !== "PUBLISHED_RECEIPT_NOT_FOUND") throw e;
|
|
189
|
-
await waitForPublishedReceipt(api, input.receiptId, waitOpts);
|
|
190
|
-
d = await api("POST", "/v1/pull-requests", input);
|
|
191
|
-
}
|
|
192
|
-
emit(d, () => {
|
|
193
|
-
out(t(locale, d.idempotent ? "prExisting" : "prCreated", { number: d.pullNumber, url: d.url }));
|
|
194
|
-
for (const line of pullRequestNextLines(d, ctx.auth?.apiBase, (key, vars) => t(locale, key, vars))) out(line);
|
|
195
|
-
});
|
|
196
|
-
} catch (e) {
|
|
197
|
-
if (e instanceof ApiError && e.status !== 401) {
|
|
198
|
-
err(`${prefix()}${e.message}`);
|
|
199
|
-
if (!printGatewayError(e, err)) err(t(locale, pullRequestRecovery(e.body?.error)));
|
|
200
|
-
return exit(1);
|
|
201
|
-
}
|
|
202
|
-
throw e;
|
|
203
|
-
}
|
|
204
|
-
return exit(0);
|
|
205
|
-
}
|
|
206
|
-
if (sub === "list" || sub === "ls") {
|
|
207
|
-
const { path, sections } = parsePRListArgs(args);
|
|
208
|
-
const paged = path.includes("limit=");
|
|
209
|
-
const d = validatePRListResponse(await api("GET", path), paged);
|
|
210
|
-
const labels = {
|
|
211
|
-
statusUnavailable: t(locale, "prStatusUnavailable"),
|
|
212
|
-
ci: t(locale, "prCIShort"),
|
|
213
|
-
agent: t(locale, "prAgentShort"),
|
|
214
|
-
...sectionLabels(locale),
|
|
215
|
-
};
|
|
216
|
-
emit(
|
|
217
|
-
sections
|
|
218
|
-
? { ...d, items: d.items.map((item) => ({ ...item, section: prSection(item) })) }
|
|
219
|
-
: d,
|
|
220
|
-
() => {
|
|
221
|
-
const lines = sections ? formatPRListSections(d, labels) : formatPRList(d, labels);
|
|
222
|
-
if (lines.length === 0) out(t(locale, "prListEmpty"));
|
|
223
|
-
else for (const line of lines) out(line);
|
|
224
|
-
if (d.nextCursor) out(t(locale, "prListMore", { cursor: safeInline(d.nextCursor) }));
|
|
225
|
-
},
|
|
226
|
-
);
|
|
227
|
-
return exit(0);
|
|
228
|
-
}
|
|
229
|
-
if (sub === "view") {
|
|
230
|
-
const target = parsePRTargetArgs(args, "usagePrView");
|
|
231
|
-
const d = validatePRDetail(await api("GET", prDetailPath(target)), target);
|
|
232
|
-
// The Stamp page is added to --json too (stampUrl), for agents that
|
|
233
|
-
// build their report from it.
|
|
234
|
-
const stampUrl = stampPullRequestPage(ctx.auth?.apiBase, d.repository, d.number);
|
|
235
|
-
emit(stampUrl ? { ...d, stampUrl } : d, () => {
|
|
236
|
-
for (const line of formatPRDetail(d, {
|
|
237
|
-
verdictLine: d.verdict ? formatVerdictLine(d.verdict, (key) => t(locale, key)) : "",
|
|
238
|
-
stampPage: stampUrl ? t(locale, "prViewStampPage", { page: stampUrl }) : "",
|
|
239
|
-
head: t(locale, "prHeadLabel"),
|
|
240
|
-
checks: t(locale, "prChecksLabel"),
|
|
241
|
-
ciUnreadable: t(locale, "prCIUnreadable"),
|
|
242
|
-
review: t(locale, "prReviewLabel"),
|
|
243
|
-
})) out(line);
|
|
244
|
-
outInstance(ctx);
|
|
245
|
-
});
|
|
246
|
-
return exit(0);
|
|
247
|
-
}
|
|
248
|
-
if (sub === "review") {
|
|
249
|
-
const target = parsePRTargetArgs(args, "usagePrReview");
|
|
250
|
-
const d = validatePRDetail(await api("GET", prDetailPath(target)), target);
|
|
251
|
-
const brief = reviewBrief(d);
|
|
252
|
-
emit(brief, () => {
|
|
253
|
-
for (const line of formatPRReview(brief, (key) => t(locale, key))) out(line);
|
|
254
|
-
});
|
|
255
|
-
// Stays exit 0 even when the CI rollup is unreadable, and that is a
|
|
256
|
-
// decision rather than an omission (飞牛 raised it). `pr checks` is a gate
|
|
257
|
-
// answering "is this green?", so it fails closed; `pr review` is a fetch
|
|
258
|
-
// answering "give me the brief", and the fetch succeeded. Failing it here
|
|
259
|
-
// would conflate "I could not build the brief" with "the brief says CI is
|
|
260
|
-
// unknown", and would break callers that use it to obtain a brief at all.
|
|
261
|
-
// The unreadability travels in the brief itself -- printed in the text and
|
|
262
|
-
// carried as `ciUnreadable` in --json, which is purely additive.
|
|
263
|
-
return exit(0);
|
|
264
|
-
}
|
|
265
|
-
if (sub === "diff") {
|
|
266
|
-
const target = parsePRDiffArgs(args);
|
|
267
|
-
const d = validatePRDiff(await api("GET", prDiffPath(target)), target);
|
|
268
|
-
emit(d, () => {
|
|
269
|
-
const chunks = formatPRDiff(d, target.nameOnly, t(locale, "prDiffUnavailable"));
|
|
270
|
-
if (chunks.length === 0) out(t(locale, "prDiffEmpty"));
|
|
271
|
-
else out(chunks.join("\n"));
|
|
272
|
-
});
|
|
273
|
-
return exit(0);
|
|
274
|
-
}
|
|
275
|
-
if (sub === "checks") {
|
|
276
|
-
const target = parsePRTargetArgs(args, "usagePrChecks");
|
|
277
|
-
const d = validatePRDetail(await api("GET", prDetailPath(target)), target);
|
|
278
|
-
emit(d.checks, () => {
|
|
279
|
-
// BOUNDARY, deliberately not fixed here: `--json` emits the checks ARRAY,
|
|
280
|
-
// which has nowhere to put "the source was refused" -- an agent parsing
|
|
281
|
-
// stdout sees `[]` for both "no CI" and "could not read CI". Widening it
|
|
282
|
-
// to an object would break every agent that parses an array, which is the
|
|
283
|
-
// same compatibility trap as adding a ciStatus value, so the contract is:
|
|
284
|
-
// **the exit code is authoritative for --json callers, and `pr view
|
|
285
|
-
// --json` carries ciUnreadable if you need the reason.** Said out loud
|
|
286
|
-
// rather than left for the next person to discover (飞牛, cross).
|
|
287
|
-
const lines = formatPRChecks(d);
|
|
288
|
-
// "No checks reported." is the same lie as CI:none, just where a person
|
|
289
|
-
// reads it rather than in a column. An empty list because the source was
|
|
290
|
-
// refused must not borrow the sentence meant for a repo that has no CI.
|
|
291
|
-
if (d.ciUnreadable) out(t(locale, "prChecksUnreadable"));
|
|
292
|
-
else if (lines.length === 0) out(t(locale, "prChecksEmpty"));
|
|
293
|
-
else for (const line of lines) out(line);
|
|
294
|
-
});
|
|
295
|
-
return exit(prChecksExitCode(d));
|
|
296
|
-
}
|
|
297
|
-
throw new Error(t(locale, "usagePrRead"));
|
|
298
|
-
}
|
package/lib/commands/queue.mjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { t, prefix } from "../locale.mjs";
|
|
2
|
-
import { NetworkError } from "../client.mjs";
|
|
3
|
-
import { formatQueueSetup, formatQueueStatus, parseQueueArgs, queueRequest, setupPath, validateQueueView } from "../queue/setup.mjs";
|
|
4
|
-
|
|
5
|
-
export async function run(ctx) {
|
|
6
|
-
const { args, api, emit, out, err, locale, exit } = ctx;
|
|
7
|
-
const input = parseQueueArgs(args);
|
|
8
|
-
|
|
9
|
-
if (input.action === "setup" || input.action === "status") {
|
|
10
|
-
const req = queueRequest(input);
|
|
11
|
-
const d = validateQueueView(await api(req.method, req.path), input);
|
|
12
|
-
emit(d, () => { for (const line of (input.action === "setup" ? formatQueueSetup(d) : formatQueueStatus(d))) out(line); });
|
|
13
|
-
return exit(0);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let confirmed;
|
|
17
|
-
if (input.action === "save") {
|
|
18
|
-
// The digest, revision and source come from a fresh discovery, never from
|
|
19
|
-
// the agent's hands; what is confirmed is shown before it is sent.
|
|
20
|
-
const view = validateQueueView(await api("GET", setupPath(input.repository, input.branch, input.workflow)), input);
|
|
21
|
-
if (!view.canSave || !view.confirmation) {
|
|
22
|
-
emit({ confirmed: null, discovery: view }, () => { for (const line of formatQueueSetup(view)) out(line); });
|
|
23
|
-
err(`${prefix()}${t(locale, "queueCannotSave")}`);
|
|
24
|
-
return exit(1);
|
|
25
|
-
}
|
|
26
|
-
confirmed = {
|
|
27
|
-
branch: view.branch, workflowId: view.workflowId, workflowSha: view.workflowSha, sourceSha: view.sourceSha,
|
|
28
|
-
jobs: view.jobs, required: view.required, additionalWorkflows: view.additionalWorkflows,
|
|
29
|
-
confirmation: view.confirmation, revision: view.revision,
|
|
30
|
-
ciPolicy: input.ciPolicy, maxBatch: input.maxBatch, waitSeconds: input.waitSeconds, timeoutSeconds: input.timeoutSeconds,
|
|
31
|
-
};
|
|
32
|
-
const show = () => {
|
|
33
|
-
out(t(locale, "queueConfirming", { repository: view.repository, branch: view.branch }));
|
|
34
|
-
for (const line of formatQueueSetup(view)) out(` ${line}`);
|
|
35
|
-
out(` ci-policy ${input.ciPolicy}, max-batch ${input.maxBatch}, wait ${input.waitSeconds}s, timeout ${input.timeoutSeconds}s`);
|
|
36
|
-
};
|
|
37
|
-
if (!input.confirm) {
|
|
38
|
-
emit({ confirmed, sent: false }, show);
|
|
39
|
-
err(`${prefix()}${t(locale, "queueConfirmRequired")}`);
|
|
40
|
-
return exit(1);
|
|
41
|
-
}
|
|
42
|
-
if (!ctx.json) show();
|
|
43
|
-
const req = queueRequest(input, view);
|
|
44
|
-
return write(ctx, req, input, confirmed);
|
|
45
|
-
}
|
|
46
|
-
return write(ctx, queueRequest(input), input);
|
|
47
|
-
|
|
48
|
-
async function write(ctx, req, input, confirmed) {
|
|
49
|
-
let d;
|
|
50
|
-
try {
|
|
51
|
-
d = validateQueueView(await api(req.method, req.path, req.body), input);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
if (e instanceof NetworkError) {
|
|
54
|
-
err(`${prefix()}${t(locale, "queueOutcomeUnknown", { repository: input.repository })}`);
|
|
55
|
-
err(`${prefix()}${t(locale, e.code, e.details)}`);
|
|
56
|
-
return exit(1);
|
|
57
|
-
}
|
|
58
|
-
throw e;
|
|
59
|
-
}
|
|
60
|
-
const key = { save: "queueSaved", verify: "queueVerifyStarted", enable: "queueEnabled" }[input.action];
|
|
61
|
-
emit(confirmed ? { confirmed, result: d } : d, () => {
|
|
62
|
-
out(t(locale, key, { repository: d.repository, revision: d.revision ?? d.config?.revision ?? "—", number: input.number ?? "" }));
|
|
63
|
-
for (const line of formatQueueStatus(d)) out(line);
|
|
64
|
-
});
|
|
65
|
-
return exit(0);
|
|
66
|
-
}
|
|
67
|
-
}
|
package/lib/commands/receipt.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { t } from "../locale.mjs";
|
|
2
|
-
import { formatReceiptLine, parseReceiptListArgs, validateReceiptList } from "../receipt/list.mjs";
|
|
3
|
-
|
|
4
|
-
export async function run(ctx) {
|
|
5
|
-
const sub = ctx.args.shift();
|
|
6
|
-
if (sub === "list") {
|
|
7
|
-
const { path } = parseReceiptListArgs(ctx.args);
|
|
8
|
-
const d = validateReceiptList(await ctx.api("GET", path));
|
|
9
|
-
ctx.emit(d, () => {
|
|
10
|
-
if (d.items.length === 0) {
|
|
11
|
-
ctx.out(t(ctx.locale, "receiptListEmpty"));
|
|
12
|
-
} else {
|
|
13
|
-
for (const item of d.items) {
|
|
14
|
-
ctx.out(formatReceiptLine(item));
|
|
15
|
-
if (item.lastError) ctx.out(` last error: ${item.lastError}`);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (d.nextCursor) ctx.out(t(ctx.locale, "receiptListMore", { cursor: d.nextCursor }));
|
|
19
|
-
});
|
|
20
|
-
return ctx.exit(0);
|
|
21
|
-
}
|
|
22
|
-
const id = ctx.args.shift();
|
|
23
|
-
if (sub !== "get" || !id) throw new Error(t(ctx.locale, "usageReceiptGet"));
|
|
24
|
-
const d = await ctx.api("GET", `/v1/receipts/${encodeURIComponent(id)}`);
|
|
25
|
-
ctx.emit(d, () => {
|
|
26
|
-
let line = `${d.id} ${d.status} ${d.repository} ${d.targetRef} published=${d.publishedSha ?? "-"}`;
|
|
27
|
-
if (d.publishAttempts) line += ` attempts=${d.publishAttempts}`;
|
|
28
|
-
if (d.nextRetryAt) line += ` nextRetry=${d.nextRetryAt}`;
|
|
29
|
-
ctx.out(line);
|
|
30
|
-
if (d.lastError) ctx.out(` last error: ${d.lastError}`);
|
|
31
|
-
});
|
|
32
|
-
return ctx.exit(0);
|
|
33
|
-
}
|
package/lib/commands/repo.mjs
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { t } from "../locale.mjs";
|
|
3
|
-
import { takeFlag } from "../flags.mjs";
|
|
4
|
-
import { gatewayCloneURL, parseRepoCloneArgs, parseRepository, runGitClone, runGitSetSSHCommand, setCommitIdentity } from "../repo/clone.mjs";
|
|
5
|
-
import { fetchPublishedKnownHosts, resolveIdentity, resolveKnownHostsPath, sshCommandFor, writePinnedKnownHosts } from "../repo/ssh.mjs";
|
|
6
|
-
import { readRecordedIdentity } from "../repo/identities.mjs";
|
|
7
|
-
import { ensureAgentKey } from "./key.mjs";
|
|
8
|
-
|
|
9
|
-
export async function run(ctx) {
|
|
10
|
-
const sub = ctx.args.shift();
|
|
11
|
-
if (sub === "use") return use(ctx);
|
|
12
|
-
if (sub !== "clone") throw new Error(t(ctx.locale, "usageRepoClone"));
|
|
13
|
-
const identityFlag = takeFlag(ctx.args, "identity");
|
|
14
|
-
const knownHostsFlag = takeFlag(ctx.args, "known-hosts");
|
|
15
|
-
const parsed = parseRepoCloneArgs(ctx.args);
|
|
16
|
-
if (!parsed) throw new Error(t(ctx.locale, "usageRepoClone"));
|
|
17
|
-
const me = await ctx.api("GET", "/v1/me");
|
|
18
|
-
const repo = parseRepository(parsed.repository, me?.github?.login);
|
|
19
|
-
if (!repo) throw new Error(t(ctx.locale, "usageRepoClone"));
|
|
20
|
-
const url = gatewayCloneURL(me.sshHost, me.sshPort, repo.owner, repo.name);
|
|
21
|
-
|
|
22
|
-
// The clone carries the enrolled identity and the gateway's published host
|
|
23
|
-
// key itself (task #475): a bare clone must not fail with publickey, and it
|
|
24
|
-
// must not need a hand-exported GIT_SSH_COMMAND.
|
|
25
|
-
if (!identityFlag && !String(ctx.env.STAMP_SSH_IDENTITY ?? "").trim()) {
|
|
26
|
-
const key = await ensureAgentKey(ctx);
|
|
27
|
-
if (key) ctx.err(t(ctx.locale, "keyEnsured", { path: key.path, fingerprint: key.fingerprint }));
|
|
28
|
-
}
|
|
29
|
-
const recorded = readRecordedIdentity(ctx.env, ctx.auth.apiBase);
|
|
30
|
-
const { identityPath, source } = resolveIdentity(ctx.env, identityFlag, recorded);
|
|
31
|
-
if (!existsSync(identityPath)) {
|
|
32
|
-
// The recorded key is not on this machine (or moved): say which record
|
|
33
|
-
// pointed there, so the fix is `key enroll` here or --identity, not a
|
|
34
|
-
// search of ~/.ssh (task #514: never scan).
|
|
35
|
-
throw new Error(t(ctx.locale, source === "enrolled" ? "cloneEnrolledIdentityMissing" : "cloneIdentityMissing", { path: identityPath, origin: ctx.auth.apiBase }));
|
|
36
|
-
}
|
|
37
|
-
const knownHostsPath = resolveKnownHostsPath(ctx.env, knownHostsFlag);
|
|
38
|
-
const fetchImpl = ctx.opts.fetchImpl ?? fetch;
|
|
39
|
-
const published = await fetchPublishedKnownHosts({ apiBase: ctx.auth.apiBase, fetchImpl });
|
|
40
|
-
if (!published.ok) {
|
|
41
|
-
throw new Error(t(ctx.locale, published.invalid ? "cloneKnownHostsInvalid" : "cloneKnownHostsUnavailable", {
|
|
42
|
-
url: `${ctx.auth.apiBase}/.well-known/ssh-known-hosts`,
|
|
43
|
-
status: published.status ?? "?",
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
writePinnedKnownHosts(knownHostsPath, published.pattern, published.line);
|
|
47
|
-
const sshCommand = sshCommandFor({ identityPath, knownHostsPath });
|
|
48
|
-
|
|
49
|
-
const git = ctx.opts.gitCloneImpl ?? runGitClone;
|
|
50
|
-
const result = await git({
|
|
51
|
-
url,
|
|
52
|
-
directory: parsed.directory,
|
|
53
|
-
gitFlags: parsed.gitFlags,
|
|
54
|
-
env: { ...(ctx.opts.gitEnv ?? ctx.env), GIT_SSH_COMMAND: sshCommand },
|
|
55
|
-
});
|
|
56
|
-
if (result.code !== 0) {
|
|
57
|
-
if (result.stderr) ctx.err(result.stderr.trimEnd());
|
|
58
|
-
if (/permission denied \(publickey\)/i.test(result.stderr ?? "")) {
|
|
59
|
-
ctx.err(t(ctx.locale, "clonePublicKeyRejected", { path: identityPath, publicKey: `${identityPath}.pub` }));
|
|
60
|
-
}
|
|
61
|
-
throw new Error(t(ctx.locale, "cloneFailed", { repository: `${repo.owner}/${repo.name}` }));
|
|
62
|
-
}
|
|
63
|
-
if (result.stderr) ctx.err(result.stderr.trimEnd());
|
|
64
|
-
|
|
65
|
-
// Make later git operations in this checkout work without any export.
|
|
66
|
-
const directory = parsed.directory ?? repo.name;
|
|
67
|
-
const pinned = await (ctx.opts.gitConfigImpl ?? runGitSetSSHCommand)({ directory, sshCommand });
|
|
68
|
-
const commitEmail = await setCommitIdentity(ctx, me, directory);
|
|
69
|
-
ctx.emit(
|
|
70
|
-
{ ok: true, repository: `${repo.owner}/${repo.name}`, url, directory, sshIdentity: identityPath, sshIdentitySource: source, sshPinned: pinned.ok, commitEmail },
|
|
71
|
-
() => {
|
|
72
|
-
if (commitEmail) ctx.out(t(ctx.locale, "repoCommitEmailSet", { email: commitEmail, directory }));
|
|
73
|
-
ctx.out(t(ctx.locale, "cloned", { repository: `${repo.owner}/${repo.name}`, url }));
|
|
74
|
-
// The commit rules this gateway enforces, stated once up front (task #549):
|
|
75
|
-
// a pusher should not meet them for the first time as a refusal.
|
|
76
|
-
if (me.commitTrailers && (me.commitTrailers.signedOffBy || me.commitTrailers.coauthoredBy)) {
|
|
77
|
-
ctx.out(t(ctx.locale, "cloneCommitTrailers"));
|
|
78
|
-
if (me.commitTrailers.signedOffBy) ctx.out(` ${me.commitTrailers.signedOffBy}`);
|
|
79
|
-
if (me.commitTrailers.coauthoredBy) ctx.out(` ${me.commitTrailers.coauthoredBy}`);
|
|
80
|
-
}
|
|
81
|
-
ctx.out(pinned.ok
|
|
82
|
-
? t(ctx.locale, "cloneIdentityPinned", { directory })
|
|
83
|
-
: t(ctx.locale, "cloneIdentityPinFailed", { directory, command: sshCommand }));
|
|
84
|
-
},
|
|
85
|
-
);
|
|
86
|
-
return ctx.exit(0);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// `stamp repo use [DIR]` gives a checkout that was not cloned through Stamp
|
|
90
|
-
// the same per-repository ssh settings `repo clone` writes: this agent's own
|
|
91
|
-
// key and the gateway's pinned host key, in the repository's local config
|
|
92
|
-
// only (artin 09-27: never ~/.ssh/config or a global setting, which other
|
|
93
|
-
// agents on the machine share).
|
|
94
|
-
async function use(ctx) {
|
|
95
|
-
const identityFlag = takeFlag(ctx.args, "identity");
|
|
96
|
-
const knownHostsFlag = takeFlag(ctx.args, "known-hosts");
|
|
97
|
-
const directory = ctx.args.shift() ?? ".";
|
|
98
|
-
if (ctx.args.length !== 0) throw new Error(t(ctx.locale, "usageRepoUse"));
|
|
99
|
-
if (!identityFlag && !String(ctx.env.STAMP_SSH_IDENTITY ?? "").trim()) {
|
|
100
|
-
const key = await ensureAgentKey(ctx);
|
|
101
|
-
if (key) ctx.err(t(ctx.locale, "keyEnsured", { path: key.path, fingerprint: key.fingerprint }));
|
|
102
|
-
}
|
|
103
|
-
const recorded = readRecordedIdentity(ctx.env, ctx.auth.apiBase);
|
|
104
|
-
const { identityPath, source } = resolveIdentity(ctx.env, identityFlag, recorded);
|
|
105
|
-
if (!existsSync(identityPath)) {
|
|
106
|
-
throw new Error(t(ctx.locale, source === "enrolled" ? "cloneEnrolledIdentityMissing" : "cloneIdentityMissing", { path: identityPath, origin: ctx.auth.apiBase }));
|
|
107
|
-
}
|
|
108
|
-
const knownHostsPath = resolveKnownHostsPath(ctx.env, knownHostsFlag);
|
|
109
|
-
const fetchImpl = ctx.opts.fetchImpl ?? fetch;
|
|
110
|
-
const published = await fetchPublishedKnownHosts({ apiBase: ctx.auth.apiBase, fetchImpl });
|
|
111
|
-
if (!published.ok) {
|
|
112
|
-
throw new Error(t(ctx.locale, published.invalid ? "cloneKnownHostsInvalid" : "cloneKnownHostsUnavailable", {
|
|
113
|
-
url: `${ctx.auth.apiBase}/.well-known/ssh-known-hosts`,
|
|
114
|
-
status: published.status ?? "?",
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
writePinnedKnownHosts(knownHostsPath, published.pattern, published.line);
|
|
118
|
-
const sshCommand = sshCommandFor({ identityPath, knownHostsPath });
|
|
119
|
-
const pinned = await (ctx.opts.gitConfigImpl ?? runGitSetSSHCommand)({ directory, sshCommand });
|
|
120
|
-
if (!pinned.ok) {
|
|
121
|
-
throw new Error(t(ctx.locale, "repoUseFailed", { directory, detail: (pinned.stderr ?? "").trim() }));
|
|
122
|
-
}
|
|
123
|
-
const me = await ctx.api("GET", "/v1/me").catch(() => null);
|
|
124
|
-
const commitEmail = await setCommitIdentity(ctx, me, directory);
|
|
125
|
-
ctx.emit({ directory, identityPath, knownHostsPath, sshCommand, commitEmail }, () => {
|
|
126
|
-
ctx.out(t(ctx.locale, "repoUseDone", { directory, path: identityPath }));
|
|
127
|
-
if (commitEmail) ctx.out(t(ctx.locale, "repoCommitEmailSet", { email: commitEmail, directory }));
|
|
128
|
-
});
|
|
129
|
-
return ctx.exit(0);
|
|
130
|
-
}
|
package/lib/commands/search.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { AgentError } from "../errors.mjs";
|
|
2
|
-
import { t } from "../locale.mjs";
|
|
3
|
-
import { takeNamedFlag } from "../pr/read.mjs";
|
|
4
|
-
|
|
5
|
-
// `stamp search QUERY... [--limit N] [--cursor CURSOR]`: GET /v1/search. An
|
|
6
|
-
// agent searches the pull requests of every repository enabled on its server
|
|
7
|
-
// (the repositories it can read a PR in), and those repositories by name.
|
|
8
|
-
// Pull results page with --limit / --cursor. When the gateway answers
|
|
9
|
-
// `pullSearch: "unavailable"` the index could not be asked: that is not "no
|
|
10
|
-
// results", so the command says so and exits non-zero.
|
|
11
|
-
|
|
12
|
-
export const SEARCH_MAX_LIMIT = 50;
|
|
13
|
-
const MAX_QUERY_LEN = 256;
|
|
14
|
-
|
|
15
|
-
export function parseSearchArgs(input) {
|
|
16
|
-
const args = [...input];
|
|
17
|
-
const limitRaw = takeNamedFlag(args, "limit", undefined, "usageSearch");
|
|
18
|
-
const cursor = takeNamedFlag(args, "cursor", undefined, "usageSearch");
|
|
19
|
-
if (args.some((a) => a.startsWith("-"))) throw new AgentError("usageSearch");
|
|
20
|
-
const query = args.join(" ").trim();
|
|
21
|
-
if (query === "" || query.length > MAX_QUERY_LEN) throw new AgentError("usageSearch");
|
|
22
|
-
const params = new URLSearchParams({ q: query });
|
|
23
|
-
if (limitRaw !== undefined) {
|
|
24
|
-
if (!/^[1-9][0-9]*$/.test(limitRaw) || Number(limitRaw) > SEARCH_MAX_LIMIT) throw new AgentError("usageSearch");
|
|
25
|
-
params.set("limit", limitRaw);
|
|
26
|
-
}
|
|
27
|
-
if (cursor !== undefined) params.set("cursor", cursor);
|
|
28
|
-
return { path: `/v1/search?${params}` };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function validateSearch(d) {
|
|
32
|
-
if (!d || !Array.isArray(d.items)) throw new AgentError("searchBadResponse");
|
|
33
|
-
for (const item of d.items) {
|
|
34
|
-
if (typeof item?.type !== "string" || typeof item?.title !== "string") throw new AgentError("searchBadResponse");
|
|
35
|
-
if (item.type === "pull" && (typeof item.pull?.repository !== "string" || !Number.isInteger(item.pull?.number))) {
|
|
36
|
-
throw new AgentError("searchBadResponse");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (d.nextCursor !== null && d.nextCursor !== undefined && typeof d.nextCursor !== "string") throw new AgentError("searchBadResponse");
|
|
40
|
-
return { items: d.items, nextCursor: d.nextCursor ?? null, pullSearch: d.pullSearch };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const oneLine = (s) => String(s ?? "").replace(/\s+/g, " ").trim();
|
|
44
|
-
|
|
45
|
-
export function formatSearchLine(item) {
|
|
46
|
-
if (item.type === "pull") {
|
|
47
|
-
return `${item.pull.repository}#${item.pull.number}\t${item.pull.state || "-"}\t${oneLine(item.title)}`;
|
|
48
|
-
}
|
|
49
|
-
return `${item.type}\t${oneLine(item.title)}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export async function run(ctx) {
|
|
53
|
-
const { path } = parseSearchArgs(ctx.args);
|
|
54
|
-
const d = validateSearch(await ctx.api("GET", path));
|
|
55
|
-
const unavailable = d.pullSearch === "unavailable";
|
|
56
|
-
ctx.emit(d, () => {
|
|
57
|
-
if (unavailable) ctx.out(t(ctx.locale, "searchPullUnavailable"));
|
|
58
|
-
if (d.items.length === 0 && !unavailable) ctx.out(t(ctx.locale, "searchEmpty"));
|
|
59
|
-
for (const item of d.items) ctx.out(formatSearchLine(item));
|
|
60
|
-
if (d.nextCursor) ctx.out(t(ctx.locale, "searchMore", { cursor: d.nextCursor }));
|
|
61
|
-
});
|
|
62
|
-
return ctx.exit(unavailable ? 1 : 0);
|
|
63
|
-
}
|
package/lib/commands/session.mjs
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { runAgentLogin } from "../agent-login.mjs";
|
|
2
|
-
import { humanExpiry } from "../expiry.mjs";
|
|
3
|
-
import { t } from "../locale.mjs";
|
|
4
|
-
import { ensureAgentKey } from "./key.mjs";
|
|
5
|
-
|
|
6
|
-
export async function login(ctx) {
|
|
7
|
-
const { auth, opts, emit, out, locale, exit } = ctx;
|
|
8
|
-
if (auth.mode !== "agent") {
|
|
9
|
-
out(t(locale, "loginHumanIntro"));
|
|
10
|
-
out(t(locale, "loginHumanBrowser", { url: auth.apiBase }));
|
|
11
|
-
out(t(locale, "loginHumanCI"));
|
|
12
|
-
return exit(0);
|
|
13
|
-
}
|
|
14
|
-
const loginImpl = opts.loginImpl ?? runAgentLogin;
|
|
15
|
-
const session = await loginImpl(auth.agentEnv, auth.apiBase, { service: auth.service, fetchImpl: opts.fetchImpl });
|
|
16
|
-
// JSON keeps the raw RFC3339 instant; the human line renders it for a reader
|
|
17
|
-
// in their own time zone with how long is left (task #436).
|
|
18
|
-
const expiry = humanExpiry(locale, session.access_expires_at);
|
|
19
|
-
emit({ ok: true, service: auth.service, api_base: auth.apiBase, access_expires_at: session.access_expires_at },
|
|
20
|
-
() => out(t(locale, expiry.expired ? "loginTokenExpired" : "loginAgentReady", {
|
|
21
|
-
service: auth.service, url: auth.apiBase, expires: expiry.text, remaining: expiry.remaining,
|
|
22
|
-
})));
|
|
23
|
-
// The agent's own SSH key, without a separate step. A failure never costs
|
|
24
|
-
// the login: clone and `key enroll` try again.
|
|
25
|
-
if (!expiry.expired) {
|
|
26
|
-
try {
|
|
27
|
-
const key = await ensureAgentKey(ctx);
|
|
28
|
-
if (key) ctx.err(t(locale, "keyEnsured", { path: key.path, fingerprint: key.fingerprint }));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
ctx.err(t(locale, "keyEnsureFailed", { reason: String(e?.message ?? e) }));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return exit(0);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function logout(ctx) {
|
|
37
|
-
const p = ctx.auth.logout();
|
|
38
|
-
ctx.out(p ? t(ctx.locale, "logoutForgot", { path: p }) : t(ctx.locale, "logoutNothing"));
|
|
39
|
-
return ctx.exit(0);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function whoami(ctx) {
|
|
43
|
-
const me = await ctx.api("GET", "/v1/me");
|
|
44
|
-
ctx.emit(me, () => {
|
|
45
|
-
ctx.out(`${me.principalType} ${me.name} (${me.agentId}@${me.serverId}) ssh=${me.sshHost} @ ${ctx.auth.apiBase}`);
|
|
46
|
-
// An agent always has a commit email (artin 09-27): its own, or Stamp's
|
|
47
|
-
// default, which receives no mail. Say which, and how to use it.
|
|
48
|
-
const email = me.commitEmail;
|
|
49
|
-
if (email && typeof email.address === "string" && email.address !== "") {
|
|
50
|
-
ctx.out(t(ctx.locale, email.default ? "whoamiCommitEmailDefault" : "whoamiCommitEmail", { email: email.address }));
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
return ctx.exit(0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function migrationHelp(ctx) {
|
|
57
|
-
const fetchImpl = ctx.opts.fetchImpl ?? fetch;
|
|
58
|
-
const res = await fetchImpl(`${ctx.auth.apiBase}/v1/migration-help`, {
|
|
59
|
-
headers: { "accept-language": "en" },
|
|
60
|
-
});
|
|
61
|
-
const d = await res.json();
|
|
62
|
-
ctx.emit(d, () => {
|
|
63
|
-
ctx.out(t(ctx.locale, "helpInstall", { cmds: (d.install ?? []).join(" ; ") }));
|
|
64
|
-
ctx.out(t(ctx.locale, "helpAgentLogin", { text: d.login?.agent ?? "" }));
|
|
65
|
-
for (const [from, to] of Object.entries(d.actions_to_cli ?? {})) {
|
|
66
|
-
const note = d.notes?.[from];
|
|
67
|
-
ctx.out(note ? ` ${from} → ${to} (${note})` : ` ${from} → ${to}`);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return ctx.exit(0);
|
|
71
|
-
}
|