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,138 @@
|
||||
//
|
||||
// Thin git wrapper. Nova cannot read a repository's state directly, so branch,
|
||||
// remote, and checkout information all come from the git binary.
|
||||
//
|
||||
|
||||
const { exec, output } = require("./exec.js");
|
||||
const log = require("./log.js");
|
||||
|
||||
const GIT = "/usr/bin/env";
|
||||
|
||||
function git(dir, args) {
|
||||
return exec(GIT, ["git", ...args], { cwd: dir });
|
||||
}
|
||||
|
||||
function gitOutput(dir, args) {
|
||||
return output(GIT, ["git", ...args], { cwd: dir });
|
||||
}
|
||||
|
||||
async function isRepository(dir) {
|
||||
const result = await gitOutput(dir, ["rev-parse", "--is-inside-work-tree"]);
|
||||
return result === "true";
|
||||
}
|
||||
|
||||
async function repositoryRoot(dir) {
|
||||
return await gitOutput(dir, ["rev-parse", "--show-toplevel"]);
|
||||
}
|
||||
|
||||
async function currentBranch(dir) {
|
||||
const branch = await gitOutput(dir, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
||||
// A detached HEAD reports "HEAD", which is not a branch anyone can filter by.
|
||||
return branch && branch !== "HEAD" ? branch : null;
|
||||
}
|
||||
|
||||
async function headSha(dir) {
|
||||
return await gitOutput(dir, ["rev-parse", "HEAD"]);
|
||||
}
|
||||
|
||||
/** Returns [{ name, url }] for every configured remote. */
|
||||
async function remotes(dir) {
|
||||
const text = await gitOutput(dir, ["config", "--get-regexp", "^remote\\..*\\.url$"]);
|
||||
if (!text) return [];
|
||||
|
||||
const found = [];
|
||||
for (const line of text.split("\n")) {
|
||||
const match = line.trim().match(/^remote\.(.+)\.url\s+(.+)$/);
|
||||
if (match) found.push({ name: match[1], url: match[2] });
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/** Prefers "origin" when present; otherwise the first remote defined. */
|
||||
async function primaryRemote(dir) {
|
||||
const list = await remotes(dir);
|
||||
if (!list.length) return null;
|
||||
return list.find((remote) => remote.name === "origin") || list[0];
|
||||
}
|
||||
|
||||
async function hasLocalBranch(dir, branch) {
|
||||
const result = await git(dir, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`]);
|
||||
return result.status === 0;
|
||||
}
|
||||
|
||||
async function isDirty(dir) {
|
||||
const text = await gitOutput(dir, ["status", "--porcelain"]);
|
||||
return Boolean(text && text.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the remote and switches to `branch`, creating a tracking branch when
|
||||
* it only exists on the remote. Resolves to an error string, or null on success.
|
||||
*/
|
||||
async function checkoutBranch(dir, branch, remoteName = "origin") {
|
||||
if (await isDirty(dir)) {
|
||||
return "The working tree has uncommitted changes.";
|
||||
}
|
||||
|
||||
const fetched = await git(dir, ["fetch", remoteName, branch]);
|
||||
if (fetched.status !== 0) {
|
||||
log.debug("fetch failed", fetched.stderr);
|
||||
}
|
||||
|
||||
if (await hasLocalBranch(dir, branch)) {
|
||||
const result = await git(dir, ["checkout", branch]);
|
||||
return result.status === 0 ? null : result.stderr.trim() || "Checkout failed.";
|
||||
}
|
||||
|
||||
const result = await git(dir, [
|
||||
"checkout",
|
||||
"-b",
|
||||
branch,
|
||||
"--track",
|
||||
`${remoteName}/${branch}`,
|
||||
]);
|
||||
return result.status === 0 ? null : result.stderr.trim() || "Checkout failed.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds git repositories at `root` and one level below it, which covers both a
|
||||
* single-project workspace and the common "folder of repos" layout.
|
||||
*/
|
||||
async function discoverRepositories(root) {
|
||||
if (!root) return [];
|
||||
|
||||
const found = [];
|
||||
if (await isRepository(root)) {
|
||||
const top = (await repositoryRoot(root)) || root;
|
||||
found.push(top);
|
||||
}
|
||||
|
||||
let entries = [];
|
||||
try {
|
||||
entries = nova.fs.listdir(root);
|
||||
} catch (error) {
|
||||
log.debug("listdir failed", root, String(error));
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
if (entry.startsWith(".")) continue;
|
||||
const child = nova.path.join(root, entry);
|
||||
const stats = nova.fs.stat(child);
|
||||
if (!stats || !stats.isDirectory()) continue;
|
||||
if (!nova.fs.access(nova.path.join(child, ".git"), nova.fs.F_OK)) continue;
|
||||
if (!found.includes(child)) found.push(child);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
exports.git = git;
|
||||
exports.isRepository = isRepository;
|
||||
exports.repositoryRoot = repositoryRoot;
|
||||
exports.currentBranch = currentBranch;
|
||||
exports.headSha = headSha;
|
||||
exports.remotes = remotes;
|
||||
exports.primaryRemote = primaryRemote;
|
||||
exports.checkoutBranch = checkoutBranch;
|
||||
exports.isDirty = isDirty;
|
||||
exports.discoverRepositories = discoverRepositories;
|
||||
Reference in New Issue
Block a user