@ferronhooi/aihub 0.1.0-next.6 → 0.1.0-next.7
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/commands/evidence.js +13 -0
- package/dist/commands/release.js +41 -0
- package/dist/commands/review.js +54 -0
- package/dist/commands/story-flow.js +48 -0
- package/dist/commands/wiki.js +19 -0
- package/dist/commands/workitem.js +23 -0
- package/dist/commands/worktree.js +27 -0
- package/dist/lib/ado.js +9 -2
- package/dist/lib/branches.js +46 -0
- package/dist/lib/cliargs.js +26 -0
- package/dist/lib/diff.js +68 -0
- package/dist/lib/evidence.js +41 -0
- package/dist/lib/gitx.js +45 -0
- package/dist/lib/release.js +202 -0
- package/dist/lib/repos.js +50 -0
- package/dist/lib/review.js +223 -0
- package/dist/lib/story-flow.js +202 -0
- package/dist/lib/wiki.js +46 -0
- package/dist/lib/workitems.js +56 -0
- package/dist/lib/worktree.js +152 -0
- package/dist/router.js +15 -2
- package/dist/tools/lintSkills.js +6 -0
- package/pack/commands/copilot/explain.prompt.md +6 -0
- package/pack/commands/copilot/finish.prompt.md +6 -0
- package/pack/commands/copilot/release.prompt.md +6 -0
- package/pack/commands/copilot/review-pr.prompt.md +6 -0
- package/pack/commands/copilot/start.prompt.md +6 -0
- package/pack/commands/copilot/wiki.prompt.md +6 -0
- package/pack/commands/opencode/explain.md +5 -0
- package/pack/commands/opencode/finish.md +5 -0
- package/pack/commands/opencode/release.md +5 -0
- package/pack/commands/opencode/review-pr.md +5 -0
- package/pack/commands/opencode/start.md +5 -0
- package/pack/commands/opencode/wiki.md +5 -0
- package/pack/skills/_shared/references/team.schema.yaml +3 -0
- package/pack/skills/evidence/SKILL.md +28 -0
- package/pack/skills/pr-explain/SKILL.md +28 -0
- package/pack/skills/pr-review/SKILL.md +35 -0
- package/pack/skills/release/SKILL.md +15 -16
- package/pack/skills/start-here/SKILL.md +20 -10
- package/pack/skills/story-finish/SKILL.md +29 -0
- package/pack/skills/story-run/SKILL.md +27 -0
- package/pack/skills/story-start/SKILL.md +31 -0
- package/pack/skills/team-settings/SKILL.md +28 -0
- package/pack/skills/voice-notes/SKILL.md +30 -0
- package/pack/skills/wiki/SKILL.md +29 -0
- package/pack/skills/worktrees/SKILL.md +29 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AihubError } from "../lib/errors.js";
|
|
2
|
+
import { parseFlags } from "../lib/cliargs.js";
|
|
3
|
+
import { addEvidence } from "../lib/evidence.js";
|
|
4
|
+
/** aihub evidence add --pr N --file img.png [--caption text] */
|
|
5
|
+
export async function run(argv, ctx) {
|
|
6
|
+
const [sub, ...rest] = argv;
|
|
7
|
+
const v = parseFlags(rest, { pr: { type: "string" }, file: { type: "string" }, caption: { type: "string" }, section: { type: "string" }, json: { type: "boolean" } });
|
|
8
|
+
if (sub !== "add")
|
|
9
|
+
throw new AihubError("usage: aihub evidence add --pr <n> --file <image> [--caption <text>]");
|
|
10
|
+
if (!v.pr || !v.file)
|
|
11
|
+
throw new AihubError("aihub evidence add needs --pr <n> and --file <image>");
|
|
12
|
+
ctx.out(await addEvidence(ctx, { pr: v.pr, file: v.file, caption: v.caption, section: v.section, json: !!v.json }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AihubError } from "../lib/errors.js";
|
|
2
|
+
import { intList, list, parseFlags } from "../lib/cliargs.js";
|
|
3
|
+
import { releasePlan, releaseRun } from "../lib/release.js";
|
|
4
|
+
/** aihub release plan|run */
|
|
5
|
+
export async function run(argv, ctx) {
|
|
6
|
+
const [sub, ...rest] = argv;
|
|
7
|
+
const v = parseFlags(rest, {
|
|
8
|
+
stories: { type: "string" },
|
|
9
|
+
prs: { type: "string" },
|
|
10
|
+
target: { type: "string" },
|
|
11
|
+
"also-cherry-pick-to": { type: "string" },
|
|
12
|
+
name: { type: "string" },
|
|
13
|
+
version: { type: "string" },
|
|
14
|
+
commits: { type: "string" },
|
|
15
|
+
tags: { type: "string" },
|
|
16
|
+
out: { type: "string" },
|
|
17
|
+
"plan-file": { type: "string" },
|
|
18
|
+
json: { type: "boolean" },
|
|
19
|
+
});
|
|
20
|
+
if (sub === "plan") {
|
|
21
|
+
ctx.out(await releasePlan(ctx, {
|
|
22
|
+
stories: intList(v.stories, "--stories"),
|
|
23
|
+
prs: intList(v.prs, "--prs"),
|
|
24
|
+
target: v.target,
|
|
25
|
+
also: list(v["also-cherry-pick-to"]),
|
|
26
|
+
name: v.name,
|
|
27
|
+
version: v.version,
|
|
28
|
+
commits: list(v.commits),
|
|
29
|
+
tags: list(v.tags),
|
|
30
|
+
out: v.out,
|
|
31
|
+
json: !!v.json,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
else if (sub === "run") {
|
|
35
|
+
if (!v["plan-file"])
|
|
36
|
+
throw new AihubError("aihub release run needs --plan-file <file.yaml>");
|
|
37
|
+
ctx.out(await releaseRun(ctx, { planFile: v["plan-file"], json: !!v.json }));
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
throw new AihubError("usage: aihub release plan --stories a,b|--prs a,b --target <branch> | release run --plan-file <file>");
|
|
41
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AihubError } from "../lib/errors.js";
|
|
2
|
+
import { optInt, parseFlags } from "../lib/cliargs.js";
|
|
3
|
+
import { prComplete, prExplain, reviewPost, reviewShow } from "../lib/review.js";
|
|
4
|
+
export const PR_EXTRA_SUBS = ["explain", "complete"];
|
|
5
|
+
function need(v, flag) {
|
|
6
|
+
if (typeof v !== "string" || !v)
|
|
7
|
+
throw new AihubError(`${flag} is required`);
|
|
8
|
+
return v;
|
|
9
|
+
}
|
|
10
|
+
/** aihub review show|post */
|
|
11
|
+
export async function run(argv, ctx) {
|
|
12
|
+
const [sub, ...rest] = argv;
|
|
13
|
+
const v = parseFlags(rest, {
|
|
14
|
+
pr: { type: "string" },
|
|
15
|
+
"comments-file": { type: "string" },
|
|
16
|
+
"max-files": { type: "string" },
|
|
17
|
+
"max-diff-lines": { type: "string" },
|
|
18
|
+
"no-diff": { type: "boolean" },
|
|
19
|
+
json: { type: "boolean" },
|
|
20
|
+
});
|
|
21
|
+
if (sub === "show") {
|
|
22
|
+
ctx.out(await reviewShow(ctx, {
|
|
23
|
+
pr: need(v.pr, "--pr"),
|
|
24
|
+
maxFiles: optInt(v["max-files"], "--max-files"),
|
|
25
|
+
maxDiffLines: optInt(v["max-diff-lines"], "--max-diff-lines"),
|
|
26
|
+
noDiff: !!v["no-diff"],
|
|
27
|
+
json: !!v.json,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
else if (sub === "post") {
|
|
31
|
+
ctx.out(await reviewPost(ctx, { pr: need(v.pr, "--pr"), commentsFile: need(v["comments-file"], "--comments-file"), json: !!v.json }));
|
|
32
|
+
}
|
|
33
|
+
else
|
|
34
|
+
throw new AihubError("usage: aihub review show --pr <n|url> | review post --pr <n> --comments-file <file.yaml>");
|
|
35
|
+
}
|
|
36
|
+
/** aihub pr explain|complete (the other pr subcommands live in commands/pr.ts). */
|
|
37
|
+
export async function runPrExtra(argv, ctx) {
|
|
38
|
+
const [sub, ...rest] = argv;
|
|
39
|
+
const v = parseFlags(rest, {
|
|
40
|
+
pr: { type: "string" },
|
|
41
|
+
auto: { type: "boolean" },
|
|
42
|
+
"delete-source": { type: "boolean" },
|
|
43
|
+
squash: { type: "boolean" },
|
|
44
|
+
json: { type: "boolean" },
|
|
45
|
+
});
|
|
46
|
+
const pr = need(v.pr, "--pr");
|
|
47
|
+
if (sub === "explain")
|
|
48
|
+
ctx.out(await prExplain(ctx, { pr, json: !!v.json }));
|
|
49
|
+
else if (sub === "complete") {
|
|
50
|
+
ctx.out(await prComplete(ctx, { pr, auto: !!v.auto, deleteSource: !!v["delete-source"], squash: !!v.squash, json: !!v.json }));
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
throw new AihubError("usage: aihub pr explain|complete --pr <n>");
|
|
54
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AihubError } from "../lib/errors.js";
|
|
2
|
+
import { list, parseFlags, posInt } from "../lib/cliargs.js";
|
|
3
|
+
import { finishStory, linkStory, startStory } from "../lib/story-flow.js";
|
|
4
|
+
export const STORY_FLOW_SUBS = ["start", "link", "finish"];
|
|
5
|
+
/** aihub story start|link|finish (create|refine|show live in the story command of the stories flow). */
|
|
6
|
+
export async function run(argv, ctx) {
|
|
7
|
+
const [sub, ...rest] = argv;
|
|
8
|
+
const v = parseFlags(rest, {
|
|
9
|
+
id: { type: "string" },
|
|
10
|
+
repos: { type: "string" },
|
|
11
|
+
base: { type: "string" },
|
|
12
|
+
root: { type: "string" },
|
|
13
|
+
branch: { type: "string" },
|
|
14
|
+
checkout: { type: "boolean" },
|
|
15
|
+
"no-checkout": { type: "boolean" },
|
|
16
|
+
"dry-run": { type: "boolean" },
|
|
17
|
+
"no-state": { type: "boolean" },
|
|
18
|
+
json: { type: "boolean" },
|
|
19
|
+
});
|
|
20
|
+
if (!STORY_FLOW_SUBS.includes(sub ?? ""))
|
|
21
|
+
throw new AihubError("usage: aihub story start|link|finish --id <story> [flags]");
|
|
22
|
+
const id = posInt(v.id, "--id");
|
|
23
|
+
const json = !!v.json;
|
|
24
|
+
if (sub === "start") {
|
|
25
|
+
ctx.out(await startStory(ctx, {
|
|
26
|
+
id,
|
|
27
|
+
repos: list(v.repos),
|
|
28
|
+
base: v.base,
|
|
29
|
+
root: v.root,
|
|
30
|
+
checkout: v.checkout,
|
|
31
|
+
noCheckout: v["no-checkout"],
|
|
32
|
+
json,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
else if (sub === "link") {
|
|
36
|
+
ctx.out(await linkStory(ctx, { id, branch: v.branch, json }));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
ctx.out(await finishStory(ctx, {
|
|
40
|
+
id,
|
|
41
|
+
repos: list(v.repos),
|
|
42
|
+
root: v.root,
|
|
43
|
+
dryRun: !!v["dry-run"],
|
|
44
|
+
noState: !!v["no-state"],
|
|
45
|
+
json,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AihubError } from "../lib/errors.js";
|
|
2
|
+
import { parseFlags } from "../lib/cliargs.js";
|
|
3
|
+
import { wikiUpdate } from "../lib/wiki.js";
|
|
4
|
+
/** aihub wiki update --page path --body-file F [--publish] */
|
|
5
|
+
export async function run(argv, ctx) {
|
|
6
|
+
const [sub, ...rest] = argv;
|
|
7
|
+
const v = parseFlags(rest, {
|
|
8
|
+
page: { type: "string" },
|
|
9
|
+
"body-file": { type: "string" },
|
|
10
|
+
wiki: { type: "string" },
|
|
11
|
+
publish: { type: "boolean" },
|
|
12
|
+
json: { type: "boolean" },
|
|
13
|
+
});
|
|
14
|
+
if (sub !== "update")
|
|
15
|
+
throw new AihubError("usage: aihub wiki update --page <path> --body-file <file> [--publish]");
|
|
16
|
+
if (!v.page || !v["body-file"])
|
|
17
|
+
throw new AihubError("aihub wiki update needs --page <path> and --body-file <file>");
|
|
18
|
+
ctx.out(await wikiUpdate(ctx, { page: v.page, bodyFile: v["body-file"], wiki: v.wiki, publish: !!v.publish, json: !!v.json }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { repoClient } from "../lib/context.js";
|
|
2
|
+
import { AihubError } from "../lib/errors.js";
|
|
3
|
+
import { parseFlags, posInt } from "../lib/cliargs.js";
|
|
4
|
+
import { getWorkItem, setWorkItemState } from "../lib/workitems.js";
|
|
5
|
+
/** aihub workitem state --id N --to <state> */
|
|
6
|
+
export async function run(argv, ctx) {
|
|
7
|
+
const [sub, ...rest] = argv;
|
|
8
|
+
const v = parseFlags(rest, { id: { type: "string" }, to: { type: "string" }, json: { type: "boolean" } });
|
|
9
|
+
if (sub !== "state")
|
|
10
|
+
throw new AihubError("usage: aihub workitem state --id <n> --to <state>");
|
|
11
|
+
const id = posInt(v.id, "--id");
|
|
12
|
+
const to = String(v.to ?? "").trim();
|
|
13
|
+
if (!to)
|
|
14
|
+
throw new AihubError("--to <state> is required (for example Active, Resolved, Done)");
|
|
15
|
+
const { client } = repoClient(ctx);
|
|
16
|
+
const wi = await getWorkItem(client, id);
|
|
17
|
+
if (wi.state.toLowerCase() === to.toLowerCase()) {
|
|
18
|
+
ctx.out(v.json ? JSON.stringify({ id, from: wi.state, to: wi.state, changed: false }) : `work item ${id} is already ${wi.state}`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
await setWorkItemState(client, id, to);
|
|
22
|
+
ctx.out(v.json ? JSON.stringify({ id, from: wi.state, to, changed: true }) : `work item ${id}: ${wi.state} -> ${to}`);
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AihubError } from "../lib/errors.js";
|
|
2
|
+
import { list, parseFlags, posInt } from "../lib/cliargs.js";
|
|
3
|
+
import { createSet, listSets, removeSet } from "../lib/worktree.js";
|
|
4
|
+
export async function run(argv, ctx) {
|
|
5
|
+
const [sub, ...rest] = argv;
|
|
6
|
+
const v = parseFlags(rest, {
|
|
7
|
+
story: { type: "string" },
|
|
8
|
+
repos: { type: "string" },
|
|
9
|
+
root: { type: "string" },
|
|
10
|
+
branch: { type: "string" },
|
|
11
|
+
base: { type: "string" },
|
|
12
|
+
json: { type: "boolean" },
|
|
13
|
+
});
|
|
14
|
+
const root = v.root;
|
|
15
|
+
const json = !!v.json;
|
|
16
|
+
if (sub === "create") {
|
|
17
|
+
ctx.out(await createSet(ctx, { story: posInt(v.story, "--story"), repos: list(v.repos), root, branch: v.branch, base: v.base, json }));
|
|
18
|
+
}
|
|
19
|
+
else if (sub === "list") {
|
|
20
|
+
ctx.out(listSets(ctx, { root, json }));
|
|
21
|
+
}
|
|
22
|
+
else if (sub === "remove") {
|
|
23
|
+
ctx.out(removeSet(ctx, { story: posInt(v.story, "--story"), root, json }));
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
throw new AihubError("usage: aihub worktree create|list|remove --story <id> [--repos a,b] [--root <folder>]");
|
|
27
|
+
}
|
package/dist/lib/ado.js
CHANGED
|
@@ -54,9 +54,12 @@ export class AdoClient {
|
|
|
54
54
|
headers: {
|
|
55
55
|
Authorization: await this.auth(),
|
|
56
56
|
Accept: opts.raw ? "text/plain" : "application/json",
|
|
57
|
-
...(opts.body !== undefined
|
|
57
|
+
...(opts.body !== undefined || opts.rawBody !== undefined
|
|
58
|
+
? { "Content-Type": opts.contentType ?? "application/json; charset=utf-8" }
|
|
59
|
+
: {}),
|
|
60
|
+
...(opts.headers ?? {}),
|
|
58
61
|
},
|
|
59
|
-
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
62
|
+
body: opts.rawBody !== undefined ? opts.rawBody : opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
60
63
|
});
|
|
61
64
|
const text = await res.text();
|
|
62
65
|
const ctype = res.headers.get("content-type") ?? "";
|
|
@@ -101,6 +104,10 @@ export class AdoClient {
|
|
|
101
104
|
workItemUrl(id) {
|
|
102
105
|
return `${this.remote.orgUrl}/${encodeURIComponent(this.remote.project)}/_workitems/edit/${id}`;
|
|
103
106
|
}
|
|
107
|
+
/** PUT/POST raw bytes (attachments). */
|
|
108
|
+
sendBytes(method, path, bytes, query) {
|
|
109
|
+
return this.request(method, path, { rawBody: bytes, contentType: "application/octet-stream", query }).then((r) => r.data);
|
|
110
|
+
}
|
|
104
111
|
getText(path, query) {
|
|
105
112
|
return this.request("GET", path, { query, raw: true }).then((r) => r.data);
|
|
106
113
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AihubError } from "./errors.js";
|
|
2
|
+
import { mustGit, refSha, tryGit } from "./gitx.js";
|
|
3
|
+
import { workItemFromBranch } from "./git.js";
|
|
4
|
+
/** An existing local or origin branch that belongs to the story (prefers `preferred`). */
|
|
5
|
+
export function findStoryBranchName(dir, id, preferred) {
|
|
6
|
+
return findStoryBranchNames(dir, id, preferred)[0];
|
|
7
|
+
}
|
|
8
|
+
export function findStoryBranchNames(dir, id, preferred) {
|
|
9
|
+
const refs = tryGit(dir, ["for-each-ref", "--format=%(refname)", "refs/heads", "refs/remotes/origin"]).out.split("\n").filter(Boolean);
|
|
10
|
+
const names = new Set();
|
|
11
|
+
for (const r of refs) {
|
|
12
|
+
const n = r.replace(/^refs\/heads\//, "").replace(/^refs\/remotes\/origin\//, "");
|
|
13
|
+
if (n === "HEAD")
|
|
14
|
+
continue;
|
|
15
|
+
if (workItemFromBranch(n) === id)
|
|
16
|
+
names.add(n);
|
|
17
|
+
}
|
|
18
|
+
const all = [...names];
|
|
19
|
+
return preferred && names.has(preferred) ? [preferred, ...all.filter((n) => n !== preferred)] : all;
|
|
20
|
+
}
|
|
21
|
+
/** Creates `branch` from origin/<base> when it does not exist yet, and pushes it. Never touches the working tree. */
|
|
22
|
+
export function ensureBranch(dir, branch, base, push = true) {
|
|
23
|
+
const hasLocal = refSha(dir, `refs/heads/${branch}`) !== "";
|
|
24
|
+
const hasRemote = refSha(dir, `refs/remotes/origin/${branch}`) !== "";
|
|
25
|
+
let created = false;
|
|
26
|
+
let from = "";
|
|
27
|
+
if (!hasLocal) {
|
|
28
|
+
if (hasRemote) {
|
|
29
|
+
mustGit(dir, ["branch", "--track", branch, `origin/${branch}`]);
|
|
30
|
+
from = `origin/${branch}`;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
from = refSha(dir, `refs/remotes/origin/${base}`) ? `origin/${base}` : base;
|
|
34
|
+
if (!refSha(dir, from))
|
|
35
|
+
throw new AihubError(`base branch '${base}' not found in ${dir}; pass --base <branch>`);
|
|
36
|
+
mustGit(dir, ["branch", branch, from]);
|
|
37
|
+
created = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let pushed = false;
|
|
41
|
+
if (push && !hasRemote) {
|
|
42
|
+
mustGit(dir, ["push", "--set-upstream", "origin", `refs/heads/${branch}:refs/heads/${branch}`]);
|
|
43
|
+
pushed = true;
|
|
44
|
+
}
|
|
45
|
+
return { created, pushed, from };
|
|
46
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
import { AihubError } from "./errors.js";
|
|
3
|
+
export function parseFlags(argv, options) {
|
|
4
|
+
try {
|
|
5
|
+
return parseArgs({ args: argv, options, allowPositionals: false }).values;
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
throw new AihubError(e.message);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** A positive integer, also accepting AB#123 and !123. */
|
|
12
|
+
export function posInt(v, flag) {
|
|
13
|
+
const n = Number(String(v ?? "").replace(/^(AB#|!)/i, ""));
|
|
14
|
+
if (!Number.isInteger(n) || n <= 0)
|
|
15
|
+
throw new AihubError(`${flag} must be a number`);
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
export function optInt(v, flag) {
|
|
19
|
+
return v === undefined ? undefined : posInt(v, flag);
|
|
20
|
+
}
|
|
21
|
+
export function list(v) {
|
|
22
|
+
return v === undefined ? [] : String(v).split(",").map((s) => s.trim()).filter(Boolean);
|
|
23
|
+
}
|
|
24
|
+
export function intList(v, flag) {
|
|
25
|
+
return list(v).map((x) => posInt(x, flag));
|
|
26
|
+
}
|
package/dist/lib/diff.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const CONTEXT = 2;
|
|
2
|
+
const MAX_CELLS = 4_000_000;
|
|
3
|
+
const splitLines = (t) => (t === "" ? [] : t.replace(/\r\n/g, "\n").replace(/\n$/, "").split("\n"));
|
|
4
|
+
export function diffLines(oldText, newText, maxLines = 150) {
|
|
5
|
+
const a = splitLines(oldText);
|
|
6
|
+
const b = splitLines(newText);
|
|
7
|
+
// trim common prefix/suffix to keep the table small
|
|
8
|
+
let s = 0;
|
|
9
|
+
while (s < a.length && s < b.length && a[s] === b[s])
|
|
10
|
+
s++;
|
|
11
|
+
let ea = a.length;
|
|
12
|
+
let eb = b.length;
|
|
13
|
+
while (ea > s && eb > s && a[ea - 1] === b[eb - 1])
|
|
14
|
+
(ea--, eb--);
|
|
15
|
+
const x = a.slice(s, ea);
|
|
16
|
+
const y = b.slice(s, eb);
|
|
17
|
+
const ops = [];
|
|
18
|
+
for (let i = 0; i < s; i++)
|
|
19
|
+
ops.push({ t: " ", line: a[i], n: i + 1 });
|
|
20
|
+
if (x.length * y.length > MAX_CELLS) {
|
|
21
|
+
x.forEach((l, i) => ops.push({ t: "-", line: l, n: s + i + 1 }));
|
|
22
|
+
y.forEach((l, i) => ops.push({ t: "+", line: l, n: s + i + 1 }));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const w = y.length + 1;
|
|
26
|
+
const t = new Uint32Array((x.length + 1) * w);
|
|
27
|
+
for (let i = x.length - 1; i >= 0; i--)
|
|
28
|
+
for (let j = y.length - 1; j >= 0; j--)
|
|
29
|
+
t[i * w + j] = x[i] === y[j] ? t[(i + 1) * w + j + 1] + 1 : Math.max(t[(i + 1) * w + j], t[i * w + j + 1]);
|
|
30
|
+
let i = 0;
|
|
31
|
+
let j = 0;
|
|
32
|
+
while (i < x.length || j < y.length) {
|
|
33
|
+
if (i < x.length && j < y.length && x[i] === y[j])
|
|
34
|
+
(ops.push({ t: " ", line: x[i], n: s + j + 1 }), i++, j++);
|
|
35
|
+
else if (j < y.length && (i === x.length || t[i * w + j + 1] >= t[(i + 1) * w + j]))
|
|
36
|
+
(ops.push({ t: "+", line: y[j], n: s + j + 1 }), j++);
|
|
37
|
+
else
|
|
38
|
+
(ops.push({ t: "-", line: x[i], n: s + i + 1 }), i++);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (let i = ea; i < a.length; i++)
|
|
42
|
+
ops.push({ t: " ", line: a[i], n: i + 1 });
|
|
43
|
+
const keep = new Array(ops.length).fill(false);
|
|
44
|
+
ops.forEach((o, i) => {
|
|
45
|
+
if (o.t === " ")
|
|
46
|
+
return;
|
|
47
|
+
for (let k = Math.max(0, i - CONTEXT); k <= Math.min(ops.length - 1, i + CONTEXT); k++)
|
|
48
|
+
keep[k] = true;
|
|
49
|
+
});
|
|
50
|
+
const out = [];
|
|
51
|
+
let gap = false;
|
|
52
|
+
ops.forEach((o, i) => {
|
|
53
|
+
if (!keep[i]) {
|
|
54
|
+
gap = true;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (gap && out.length)
|
|
58
|
+
out.push(" ...");
|
|
59
|
+
gap = false;
|
|
60
|
+
out.push(`${o.t} ${String(o.n).padStart(4)} ${o.line}`);
|
|
61
|
+
});
|
|
62
|
+
const shown = out.length > maxLines ? [...out.slice(0, maxLines), ` ... ${out.length - maxLines} more lines`] : out;
|
|
63
|
+
return {
|
|
64
|
+
added: ops.filter((o) => o.t === "+").length,
|
|
65
|
+
removed: ops.filter((o) => o.t === "-").length,
|
|
66
|
+
text: shown.join("\n"),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, extname } from "node:path";
|
|
3
|
+
import { getPr } from "./ado.js";
|
|
4
|
+
import { repoClient } from "./context.js";
|
|
5
|
+
import { AihubError } from "./errors.js";
|
|
6
|
+
import { parsePrRef } from "./pr.js";
|
|
7
|
+
import { editSection, parseSections } from "./templates.js";
|
|
8
|
+
const IMAGE = /^\.(png|jpe?g|gif|webp|bmp)$/i;
|
|
9
|
+
const MAX_BYTES = 20 * 1024 * 1024;
|
|
10
|
+
/** The section that holds evidence: screenshots/evidence first, then tests; null when there is none. */
|
|
11
|
+
export function evidenceHeading(description) {
|
|
12
|
+
const heads = parseSections(description).sections.map((s) => s.heading);
|
|
13
|
+
return heads.find((h) => /screenshot|evidence|bewijs/i.test(h)) ?? heads.find((h) => /^tests?\b|\btests?$|test/i.test(h));
|
|
14
|
+
}
|
|
15
|
+
export async function addEvidence(ctx, o) {
|
|
16
|
+
const ext = extname(o.file);
|
|
17
|
+
if (!IMAGE.test(ext))
|
|
18
|
+
throw new AihubError(`${basename(o.file)}: only image files (png, jpg, gif, webp, bmp) can be added as evidence`);
|
|
19
|
+
let size;
|
|
20
|
+
try {
|
|
21
|
+
size = statSync(o.file).size;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new AihubError(`file not found: ${o.file}`);
|
|
25
|
+
}
|
|
26
|
+
if (size > MAX_BYTES)
|
|
27
|
+
throw new AihubError(`${basename(o.file)} is ${(size / 1048576).toFixed(1)} MB; the limit is 20 MB`);
|
|
28
|
+
const { client } = repoClient(ctx);
|
|
29
|
+
const id = parsePrRef(o.pr);
|
|
30
|
+
const pr = await getPr(client, id);
|
|
31
|
+
const name = basename(o.file).replace(/\s+/g, "-");
|
|
32
|
+
const up = await client.sendBytes("POST", `${client.repoPath()}/pullrequests/${id}/attachments/${encodeURIComponent(name)}`, readFileSync(o.file));
|
|
33
|
+
if (!up.url)
|
|
34
|
+
throw new AihubError("Azure DevOps did not return an attachment url");
|
|
35
|
+
const caption = (o.caption ?? name.replace(ext, "")).replace(/[\[\]\n]/g, " ").trim();
|
|
36
|
+
const line = ``;
|
|
37
|
+
const heading = o.section ?? evidenceHeading(pr.description ?? "") ?? "Evidence";
|
|
38
|
+
const description = editSection(pr.description ?? "", heading, { append: line });
|
|
39
|
+
await client.patch(`${client.repoPath()}/pullrequests/${id}`, { description });
|
|
40
|
+
return o.json ? JSON.stringify({ pr: id, url: up.url, section: heading }) : `PR !${id}: ${name} attached and linked in '${heading}'`;
|
|
41
|
+
}
|
package/dist/lib/gitx.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { AihubError } from "./errors.js";
|
|
3
|
+
/** Runs git and reports success instead of throwing (the exit code matters for merge checks). */
|
|
4
|
+
export function tryGit(cwd, args) {
|
|
5
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
6
|
+
if (r.error)
|
|
7
|
+
throw new AihubError(`git is not available: ${r.error.message}`);
|
|
8
|
+
return { ok: r.status === 0, out: r.stdout.replace(/\r\n/g, "\n").trimEnd(), err: (r.stderr || "").trim() };
|
|
9
|
+
}
|
|
10
|
+
export function mustGit(cwd, args) {
|
|
11
|
+
const r = tryGit(cwd, args);
|
|
12
|
+
if (!r.ok)
|
|
13
|
+
throw new AihubError(`git ${args.join(" ")} failed: ${r.err.split("\n")[0]}`);
|
|
14
|
+
return r.out;
|
|
15
|
+
}
|
|
16
|
+
export const isDirty = (dir) => mustGit(dir, ["status", "--porcelain"]) !== "";
|
|
17
|
+
export const refSha = (dir, ref) => {
|
|
18
|
+
const r = tryGit(dir, ["rev-parse", "--verify", "--quiet", ref]);
|
|
19
|
+
return r.ok ? r.out.trim() : "";
|
|
20
|
+
};
|
|
21
|
+
export const isAncestor = (dir, a, b) => tryGit(dir, ["merge-base", "--is-ancestor", a, b]).ok;
|
|
22
|
+
export function listWorktrees(dir) {
|
|
23
|
+
const out = mustGit(dir, ["worktree", "list", "--porcelain"]);
|
|
24
|
+
const res = [];
|
|
25
|
+
for (const block of out.split(/\n\n+/)) {
|
|
26
|
+
const w = { path: "", head: "", main: res.length === 0 };
|
|
27
|
+
for (const l of block.split("\n")) {
|
|
28
|
+
if (l.startsWith("worktree "))
|
|
29
|
+
w.path = l.slice(9);
|
|
30
|
+
else if (l.startsWith("HEAD "))
|
|
31
|
+
w.head = l.slice(5);
|
|
32
|
+
else if (l.startsWith("branch "))
|
|
33
|
+
w.branch = l.slice(7).replace(/^refs\/heads\//, "");
|
|
34
|
+
}
|
|
35
|
+
if (w.path)
|
|
36
|
+
res.push(w);
|
|
37
|
+
}
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
/** Commits of HEAD that no remote-tracking branch has (would be lost with the worktree). */
|
|
41
|
+
export const unpushedCount = (dir) => {
|
|
42
|
+
const r = tryGit(dir, ["rev-list", "--count", "HEAD", "--not", "--remotes"]);
|
|
43
|
+
return r.ok ? Number(r.out) || 0 : 0;
|
|
44
|
+
};
|
|
45
|
+
export const samePath = (a, b) => a.replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase() === b.replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
|