Implement the Gitea extension
The repository was a bare Nova scaffold. This builds it out to match the
capabilities of the official Gitea VS Code extension.
Sidebar sections:
- Current Branch: pull requests and workflow runs for the checked-out
branch, with a current/all/pinned branch filter
- Workflows: runs grouped by workflow file, expanding into jobs, steps,
and artifacts
- Pull Requests: open pull requests across repositories, expanding into
reviews, review comments, and changed files
- Settings: per-instance connection state, plus repository Actions
secrets and variables
Commands cover run control (re-run, re-run failed jobs, re-run a job,
cancel), job logs, artifact download/reveal/open, pull request overview,
diff, checkout, creation, merge and close, the full review cycle, and
secret and variable management. Multiple instances are supported, routed
by git remote host, with tokens held per instance in the Keychain.
Nova exposes no webview, diff editor, editor decorations, or extension
status bar, so four features are shaped differently from the VS Code
original: the pull request timeline renders as Markdown, diffs open as
unified .diff documents, review comments are published through an
IssueCollection so they appear in the gutter and the Issues sidebar, and
a failed run posts a notification. OAuth and insecureSkipVerify have no
Nova equivalent and are omitted. README.md records all of this.
Endpoints were taken from Gitea's published swagger.v1.json. Servers
predating the workflow runs API fall back to /actions/tasks.
Tests/ runs the extension's real code under Node against a stubbed Nova
runtime and a canned Gitea instance: 88 checks, no install step and no
network. Images are generated by Tools/make-icons.py.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MQuusXgZC2dzwpJJ1qhtti
This commit is contained in:
@@ -0,0 +1,255 @@
|
||||
//
|
||||
// End-to-end: activates the real extension against a real git checkout and a
|
||||
// canned Gitea instance, then renders every sidebar section and drives the
|
||||
// commands that touch the filesystem or the API.
|
||||
//
|
||||
|
||||
const { EXTENSION_ROOT } = require("./nova-stub.js");
|
||||
const fake = require("./fake-gitea.js");
|
||||
const { Checker } = require("./assert.js");
|
||||
|
||||
const path = require("node:path");
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
const { execFileSync } = require("node:child_process");
|
||||
|
||||
const script = (...parts) => path.join(EXTENSION_ROOT, "Scripts", ...parts);
|
||||
const t = new Checker();
|
||||
|
||||
// -- fixture ---------------------------------------------------------------
|
||||
|
||||
const WORKSPACE = fs.mkdtempSync(path.join(os.tmpdir(), "gitea-nova-test-"));
|
||||
const REPO = path.join(WORKSPACE, "widget");
|
||||
|
||||
function buildRepository() {
|
||||
fs.mkdirSync(path.join(REPO, "src"), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(REPO, "src", "login.js"),
|
||||
Array.from({ length: 20 }, (_, i) => `// line ${i + 1}`).join("\n") + "\n",
|
||||
);
|
||||
fs.writeFileSync(path.join(REPO, "README.md"), "# widget\n");
|
||||
|
||||
const git = (...args) => execFileSync("git", args, { cwd: REPO, encoding: "utf-8" });
|
||||
git("init", "-q", "-b", "main");
|
||||
git("config", "user.email", "[email protected]");
|
||||
git("config", "user.name", "Test");
|
||||
git("remote", "add", "origin", "[email protected]:acme/widget.git");
|
||||
git("add", "-A");
|
||||
git("commit", "-qm", "initial");
|
||||
git("checkout", "-qb", "feature/login");
|
||||
}
|
||||
|
||||
buildRepository();
|
||||
|
||||
nova.workspace.path = WORKSPACE;
|
||||
nova.config.set("gitea.baseUrl", "https://gitea.test");
|
||||
nova.credentials.setPassword("unsupervised.giteanova", "https://gitea.test", "tok_test");
|
||||
|
||||
// -- helpers ---------------------------------------------------------------
|
||||
|
||||
/** Renders a provider's tree to indented text, expanding lazy rows as it goes. */
|
||||
async function render(provider, node = null, depth = 0, lines = []) {
|
||||
for (const child of await provider.getChildren(node)) {
|
||||
const item = provider.getTreeItem(child);
|
||||
const description = item.descriptiveText ? ` [${item.descriptiveText}]` : "";
|
||||
lines.push(`${" ".repeat(depth)}${item.name}${description}`);
|
||||
if (depth < 3 && (child.children || child.load)) {
|
||||
await render(provider, child, depth + 1, lines);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
/** Every command name the manifest exposes to the user. */
|
||||
function declaredCommands(manifest) {
|
||||
const declared = new Set();
|
||||
|
||||
for (const list of Object.values(manifest.commands || {})) {
|
||||
for (const entry of list) if (entry.command) declared.add(entry.command);
|
||||
}
|
||||
for (const sidebar of manifest.sidebars || []) {
|
||||
for (const section of sidebar.sections || []) {
|
||||
const entries = [...(section.headerCommands || []), ...(section.contextCommands || [])];
|
||||
for (const entry of entries) if (entry.command) declared.add(entry.command);
|
||||
}
|
||||
}
|
||||
const walk = (entry) => {
|
||||
if (entry.command) declared.add(entry.command);
|
||||
for (const child of entry.children || []) walk(child);
|
||||
};
|
||||
for (const entry of manifest.config || []) walk(entry);
|
||||
|
||||
return declared;
|
||||
}
|
||||
|
||||
// -- suite -----------------------------------------------------------------
|
||||
|
||||
(async () => {
|
||||
const main = require(script("main.js"));
|
||||
main.activate();
|
||||
await new Promise((resolve) => setTimeout(resolve, 400)); // let activation settle
|
||||
|
||||
const store = require(script("controllers", "selection.js")).store();
|
||||
const views = Object.fromEntries(global.__treeViews.map((view) => [view.id, view]));
|
||||
|
||||
t.section("discovery");
|
||||
console.log(
|
||||
store.repos
|
||||
.map((r) => `${r.fullName} @ ${r.baseUrl} branch=${r.branch}`)
|
||||
.join("\n") || "(none)",
|
||||
);
|
||||
t.check("one repository discovered", store.repos.length === 1, `got ${store.repos.length}`);
|
||||
t.check("routed to the matching instance", store.repos[0]?.baseUrl === "https://gitea.test");
|
||||
t.check("branch read from git", store.repos[0]?.branch === "feature/login", store.repos[0]?.branch);
|
||||
t.check(
|
||||
"instance reported healthy",
|
||||
store.instanceStatus.get("https://gitea.test")?.ok === true,
|
||||
JSON.stringify(store.instanceStatus.get("https://gitea.test")),
|
||||
);
|
||||
|
||||
for (const id of ["gitea.branch", "gitea.workflows", "gitea.pullRequests", "gitea.settings"]) {
|
||||
t.section(id);
|
||||
const lines = await render(views[id].dataProvider);
|
||||
console.log(lines.join("\n"));
|
||||
t.check(`${id} renders rows`, lines.length > 0);
|
||||
t.check(
|
||||
`${id} renders no error rows`,
|
||||
!lines.some((line) => line.includes("⚠")),
|
||||
lines.filter((line) => line.includes("⚠")).join(" | "),
|
||||
);
|
||||
}
|
||||
|
||||
t.section("branch filtering");
|
||||
const branchLines = await render(views["gitea.branch"].dataProvider);
|
||||
t.check("shows the branch's pull request", branchLines.some((l) => l.includes("#7 Add login form")));
|
||||
t.check("hides another branch's pull request", !branchLines.some((l) => l.includes("#6 Bump deps")));
|
||||
t.check("hides another branch's run", !branchLines.some((l) => l.includes("Nightly")));
|
||||
|
||||
t.section("workflow grouping");
|
||||
const workflowLines = await render(views["gitea.workflows"].dataProvider);
|
||||
t.check(
|
||||
"grouped by workflow file",
|
||||
workflowLines.some((l) => l.trim().startsWith("ci.yml")) &&
|
||||
workflowLines.some((l) => l.trim().startsWith("nightly.yml")),
|
||||
);
|
||||
t.check("jobs load under a run", workflowLines.some((l) => l.includes("build")));
|
||||
t.check("steps load under a job", workflowLines.some((l) => l.includes("Checkout")));
|
||||
t.check("artifacts listed under a run", workflowLines.some((l) => l.includes("coverage")));
|
||||
|
||||
t.section("inline review comments");
|
||||
const { ReviewCommentsController } = require(script("controllers", "reviewComments.js"));
|
||||
const comments = new ReviewCommentsController(store);
|
||||
await comments.reload({ force: true });
|
||||
|
||||
const annotated = [...comments.collection.map.entries()];
|
||||
for (const [uri, issues] of annotated) {
|
||||
console.log(uri);
|
||||
for (const issue of issues) console.log(` line ${issue.line} [${issue.source}] ${issue.message}`);
|
||||
}
|
||||
t.check("exactly one file annotated", annotated.length === 1, `got ${annotated.length}`);
|
||||
t.check("annotation lands on the commented file", annotated[0]?.[0].endsWith("/src/login.js"));
|
||||
// The hunk adds three lines after one context line starting at new line 10,
|
||||
// so the commented line — the hunk's last — is line 14.
|
||||
t.check("line derived from the diff hunk", annotated[0]?.[1][0].line === 14, annotated[0]?.[1][0].line);
|
||||
t.check("request-changes comment raised as an error", annotated[0]?.[1][0].severity === IssueSeverity.Error);
|
||||
comments.dispose();
|
||||
|
||||
t.section("manifest and command registration");
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(EXTENSION_ROOT, "extension.json"), "utf-8"));
|
||||
const declared = declaredCommands(manifest);
|
||||
const registered = global.__commands;
|
||||
|
||||
const missing = [...declared].filter((name) => !registered.has(name));
|
||||
t.check("every command the manifest offers is registered", missing.length === 0, missing.join(", "));
|
||||
|
||||
// gitea.openReviewComment is deliberately absent: it is a TreeItem.command
|
||||
// for double-click, never a menu entry.
|
||||
const extra = [...registered.keys()].filter((name) => !declared.has(name));
|
||||
t.equals("only the double-click handler is manifest-free", extra, ["gitea.openReviewComment"]);
|
||||
|
||||
t.section("command behaviour");
|
||||
const branch = views["gitea.branch"];
|
||||
const roots = await branch.dataProvider.getChildren(null);
|
||||
const pullFolder = roots.find((n) => n.kind === "prFolder");
|
||||
const pullNode = (await branch.dataProvider.getChildren(pullFolder)).find((n) => n.kind === "pr");
|
||||
branch.selection = [pullNode];
|
||||
|
||||
await registered.get("gitea.copyUrl")(branch);
|
||||
t.check(
|
||||
"copy URL uses the pull request's own page",
|
||||
global.__clipboard === "https://gitea.test/acme/widget/pulls/7",
|
||||
global.__clipboard,
|
||||
);
|
||||
|
||||
await registered.get("gitea.openPullRequestDiff")(branch);
|
||||
t.check("diff saved into the repository", fs.existsSync(path.join(REPO, ".tmp", "gitea-diffs", "pr-7.diff")));
|
||||
|
||||
await registered.get("gitea.openPullRequestOverview")(branch);
|
||||
const overview = global.__opened?.untitled?.content ?? "";
|
||||
t.check("overview headed with the pull request title", overview.includes("# #7 Add login form"));
|
||||
t.check("overview lists reviews", overview.includes("alice") && overview.includes("request_changes"));
|
||||
t.check("overview lists changed files", overview.includes("src/login.js"));
|
||||
|
||||
const runsFolder = roots.find((n) => n.kind === "runsFolder");
|
||||
const runNode = (await branch.dataProvider.getChildren(runsFolder)).find((n) => n.kind === "run");
|
||||
const jobNode = (await branch.dataProvider.getChildren(runNode)).find((n) => n.kind === "job");
|
||||
branch.selection = [jobNode];
|
||||
await registered.get("gitea.viewJobLogs")(branch);
|
||||
|
||||
const logsDir = path.join(REPO, ".tmp", "gitea-logs");
|
||||
const logFiles = fs.existsSync(logsDir) ? fs.readdirSync(logsDir) : [];
|
||||
t.check("job log written into the repository", logFiles.length === 1, logFiles.join(", "));
|
||||
|
||||
const workflows = views["gitea.workflows"];
|
||||
const ciGroup = (await workflows.dataProvider.getChildren(null)).find(
|
||||
(n) => n.kind === "workflow" && n.name === "ci.yml",
|
||||
);
|
||||
const finishedRun = (await workflows.dataProvider.getChildren(ciGroup)).find(
|
||||
(n) => n.data.run.id === 101,
|
||||
);
|
||||
const artifactsFolder = (await workflows.dataProvider.getChildren(finishedRun)).find(
|
||||
(n) => n.kind === "artifactsFolder",
|
||||
);
|
||||
workflows.selection = [(await workflows.dataProvider.getChildren(artifactsFolder))[0]];
|
||||
await registered.get("gitea.downloadArtifact")(workflows);
|
||||
|
||||
const zip = path.join(REPO, ".tmp", "gitea-artifacts", "acme", "widget", "101", "coverage.zip");
|
||||
t.check("artifact downloaded to the configured path", fs.existsSync(zip), zip);
|
||||
|
||||
t.section("secrets and variables");
|
||||
const settingsLines = await render(views["gitea.settings"].dataProvider);
|
||||
console.log(settingsLines.join("\n"));
|
||||
t.check("secret listed", settingsLines.some((l) => l.includes("DEPLOY_KEY")));
|
||||
t.check("variable listed", settingsLines.some((l) => l.includes("REGISTRY")));
|
||||
|
||||
t.section("write operations");
|
||||
global.__messages.length = 0;
|
||||
workflows.selection = [finishedRun];
|
||||
await registered.get("gitea.rerunRun")(workflows);
|
||||
t.check(
|
||||
"re-run reported as requested",
|
||||
global.__messages.some(([kind, message]) => kind === "info" && message.includes("Re-run")),
|
||||
JSON.stringify(global.__messages),
|
||||
);
|
||||
|
||||
global.__messages.length = 0;
|
||||
global.__inputAnswer = "Looks good to me";
|
||||
branch.selection = [pullNode];
|
||||
await registered.get("gitea.reviewApprove")(branch);
|
||||
t.check(
|
||||
"approval submitted",
|
||||
global.__messages.some(([kind, message]) => kind === "info" && message.includes("Review submitted")),
|
||||
JSON.stringify(global.__messages),
|
||||
);
|
||||
|
||||
t.section("api paths exercised");
|
||||
console.log([...new Set(fake.calls.map((call) => call.split("?")[0]))].sort().join("\n"));
|
||||
|
||||
main.deactivate();
|
||||
fs.rmSync(WORKSPACE, { recursive: true, force: true });
|
||||
t.finish("INTEGRATION CHECKS");
|
||||
})().catch((error) => {
|
||||
console.error("HARNESS ERROR", error);
|
||||
fs.rmSync(WORKSPACE, { recursive: true, force: true });
|
||||
process.exit(2);
|
||||
});
|
||||
Reference in New Issue
Block a user