@botiverse/stamp-cli 0.3.13 → 0.3.14
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/README.md +1 -0
- package/lib/commands/search.mjs +63 -0
- package/lib/locale.mjs +7 -0
- package/lib/main.mjs +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ stamp repo clone org/repo
|
|
|
19
19
|
git push ssh://git@ssh.staging.stamp.build:443/org/repo.git HEAD:refs/heads/agent/my-change
|
|
20
20
|
stamp receipt get <id>
|
|
21
21
|
stamp receipt list
|
|
22
|
+
stamp search "flaky test"
|
|
22
23
|
stamp pr create --receipt <published-id> --repo org/repo --head agent/my-change --sha <exact-sha> --base main --title "My change" --body-file ./pr-body.md
|
|
23
24
|
stamp pr list
|
|
24
25
|
stamp pr view 123 --repo org/repo
|
|
@@ -0,0 +1,63 @@
|
|
|
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/locale.mjs
CHANGED
|
@@ -180,6 +180,8 @@ export const messages = {
|
|
|
180
180
|
{cli} receipt list [--repo OWNER/REPO] [--limit N] [--cursor CURSOR]
|
|
181
181
|
list your own push receipts (newest first)
|
|
182
182
|
{cli} changelog [--limit N] [--all] release history: CLI/API changes per version (--all: everything)
|
|
183
|
+
{cli} search QUERY... [--limit N] [--cursor CURSOR]
|
|
184
|
+
search pull requests (title, discussion) in this server's enabled repositories
|
|
183
185
|
{cli} pr create --receipt ID [--repo OWNER/REPO --head BRANCH --sha SHA] --base BRANCH --title TITLE (--body TEXT|--body-file FILE|-) [--idempotency-key KEY]
|
|
184
186
|
{cli} pr list
|
|
185
187
|
{cli} pr view <number|URL> --repo OWNER/REPO
|
|
@@ -264,6 +266,11 @@ docs: {docs} (the agent workflow, step by step)`,
|
|
|
264
266
|
receiptListMore: "More receipts; rerun with --limit and --cursor {cursor}.",
|
|
265
267
|
receiptListBadResponse: "Unexpected receipt list response; check {cli} and gateway versions, then retry.",
|
|
266
268
|
usageChangelog: "usage: {cli} changelog [--limit N] [--all]",
|
|
269
|
+
usageSearch: "usage: {cli} search QUERY... [--limit N] [--cursor CURSOR]",
|
|
270
|
+
searchEmpty: "no results",
|
|
271
|
+
searchMore: "More results; rerun with --cursor {cursor}.",
|
|
272
|
+
searchPullUnavailable: "Pull request search is unavailable right now (the search index did not answer); pull results are missing, not empty. Retry later.",
|
|
273
|
+
searchBadResponse: "Unexpected search response; check {cli} and gateway versions, then retry.",
|
|
267
274
|
changelogScopeAgent: "Showing CLI and API changes; --all shows everything.",
|
|
268
275
|
changelogScopeAll: "Showing every change, including the web app and internal work.",
|
|
269
276
|
changelogNoneForAgents: "no CLI or API changes in this release ({hidden} other; --all shows them)",
|
package/lib/main.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import * as pr from "./commands/pr.mjs";
|
|
|
16
16
|
import * as subscribe from "./commands/subscribe.mjs";
|
|
17
17
|
import * as changelog from "./commands/changelog.mjs";
|
|
18
18
|
import * as queue from "./commands/queue.mjs";
|
|
19
|
+
import * as search from "./commands/search.mjs";
|
|
19
20
|
|
|
20
21
|
const require = createRequire(import.meta.url);
|
|
21
22
|
const pkg = require("../package.json");
|
|
@@ -39,6 +40,7 @@ const commands = {
|
|
|
39
40
|
unwatch: subscribe.watch,
|
|
40
41
|
changelog: changelog.run,
|
|
41
42
|
queue: queue.run,
|
|
43
|
+
search: search.run,
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
export async function main(argv, opts) {
|
|
@@ -47,7 +49,7 @@ export async function main(argv, opts) {
|
|
|
47
49
|
const err = opts.stderr ?? ((s) => console.error(s));
|
|
48
50
|
let env = opts.env ?? process.env;
|
|
49
51
|
const exit = opts.exit ?? ((code) => process.exit(code));
|
|
50
|
-
const localValues = new Set(["--limit", "--public-key", "--email", "--identity", "--known-hosts", "--kind", "--number", "--event", "--receipt", "--repo", "--head", "--sha", "--base", "--title", "--body", "--body-file", "--reason", "--reason-file", "--idempotency-key", "--method", "-b", "-F", "-R", "--branch", "--workflow", "--ci-policy", "--max-batch", "--wait", "--timeout", "--pr"]);
|
|
52
|
+
const localValues = new Set(["--limit", "--public-key", "--email", "--identity", "--known-hosts", "--kind", "--number", "--event", "--receipt", "--repo", "--head", "--sha", "--base", "--title", "--body", "--body-file", "--reason", "--reason-file", "--idempotency-key", "--method", "-b", "-F", "-R", "--branch", "--workflow", "--ci-policy", "--max-batch", "--wait", "--timeout", "--pr", "--cursor"]);
|
|
51
53
|
let json = false, langFlag, help = false, version = false;
|
|
52
54
|
const commandArgs = [];
|
|
53
55
|
for (let i = 0; i < args.length; i++) {
|