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:
2026-08-28 19:55:54 -03:00
co-authored by Claude Opus 5
commit 694609a3cc
58 changed files with 6231 additions and 0 deletions
+139
View File
@@ -0,0 +1,139 @@
//
// Workflow artifacts: download to disk, reveal in Finder, and open. Artifacts
// arrive as zip archives, so "open" unzips alongside the download when possible
// and otherwise hands the archive to Finder.
//
const builders = require("../views/builders.js");
const config = require("../util/config.js");
const selection = require("./selection.js");
const ui = require("../ui.js");
const { exec } = require("../util/exec.js");
/** Resolves the configured download directory for a repository. */
function downloadDirectory(repo, run) {
const configured = config.artifactDownloadPath();
const base = nova.path.isAbsolute(configured)
? configured
: nova.path.join(repo.dir || nova.workspace.path || nova.path.expanduser("~"), configured);
return nova.path.join(base, repo.owner, repo.name, String(run ? run.id : "runs"));
}
function artifactFrom(argument) {
const node = selection.selectedNode(argument);
if (!node || !node.data || !node.data.artifact) return null;
return {
node: node,
repo: selection.repoOf(node),
artifact: node.data.artifact,
run: node.data.run,
};
}
async function download(store, repo, run, artifact) {
if (artifact.expired) {
ui.warn(`${artifact.name} has expired and is no longer downloadable.`);
return null;
}
const api = store.apiFor(repo);
if (!api) return null;
const target = nova.path.join(downloadDirectory(repo, run), `${artifact.name}.zip`);
try {
const bytes = await api.downloadArtifact(repo, artifact);
ui.writeBinary(target, bytes);
} catch (error) {
ui.error(
`Could not download ${artifact.name}: ${error.message || error}` +
(error.status === 403
? " The token needs the Actions read scope for artifacts."
: ""),
);
return null;
}
const size = builders.formatBytes(
artifact.size_in_bytes || (nova.fs.stat(target) || {}).size || 0,
);
ui.info(`Downloaded ${artifact.name} (${size}) to ${target}.`);
return target;
}
/** Unzips into a sibling folder; returns the folder or null when unzip fails. */
async function unzip(zipPath) {
const folder = zipPath.replace(/\.zip$/i, "");
const result = await exec("/usr/bin/env", ["unzip", "-o", "-q", zipPath, "-d", folder]);
return result.status === 0 ? folder : null;
}
function register(store) {
nova.commands.register("gitea.downloadArtifact", async (argument) => {
const context = artifactFrom(argument);
if (!context || !context.repo) {
ui.warn("Select an artifact in the Gitea sidebar first.");
return;
}
const path = await download(store, context.repo, context.run, context.artifact);
if (path) nova.fs.reveal(path);
});
nova.commands.register("gitea.openArtifact", async (argument) => {
const context = artifactFrom(argument);
if (!context || !context.repo) {
ui.warn("Select an artifact in the Gitea sidebar first.");
return;
}
const zipPath = await download(store, context.repo, context.run, context.artifact);
if (!zipPath) return;
const folder = await unzip(zipPath);
if (!folder) {
nova.fs.reveal(zipPath);
return;
}
// A single-file artifact is far more useful opened than revealed.
let entries = [];
try {
entries = nova.fs.listdir(folder).filter((entry) => !entry.startsWith("."));
} catch (error) {
entries = [];
}
if (entries.length === 1) {
const only = nova.path.join(folder, entries[0]);
const stats = nova.fs.stat(only);
if (stats && stats.isFile()) {
await nova.workspace.openFile(only);
return;
}
}
nova.fs.reveal(folder);
});
nova.commands.register("gitea.revealArtifact", async (argument) => {
const context = artifactFrom(argument);
if (!context || !context.repo) {
ui.warn("Select an artifact in the Gitea sidebar first.");
return;
}
const expected = nova.path.join(
downloadDirectory(context.repo, context.run),
`${context.artifact.name}.zip`,
);
if (nova.fs.access(expected, nova.fs.F_OK)) {
nova.fs.reveal(expected);
return;
}
const path = await download(store, context.repo, context.run, context.artifact);
if (path) nova.fs.reveal(path);
});
}
exports.register = register;
exports.downloadDirectory = downloadDirectory;