Files
thatguygriffandClaude Opus 5 694609a3cc 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
2026-08-28 19:55:54 -03:00

128 lines
3.6 KiB
JavaScript

//
// Promise wrappers around Nova's callback-based panels, plus the small file
// helpers used to surface logs, diffs, and artifacts in the editor.
//
const log = require("./util/log.js");
function input(message, options = {}) {
return new Promise((resolve) => {
nova.workspace.showInputPanel(message, options, (value) => resolve(value ?? null));
});
}
function palette(message, options = {}) {
return new Promise((resolve) => {
nova.workspace.showInputPalette(message, options, (value) => resolve(value ?? null));
});
}
/**
* Shows a choice palette over `items` and resolves to the chosen item.
* `label` maps an item to its display string.
*/
function choose(items, { placeholder, label = String } = {}) {
return new Promise((resolve) => {
const labels = items.map((item) => label(item));
nova.workspace.showChoicePalette(
labels,
{ placeholder: placeholder },
(value, index) => {
if (value === null || index === null || index === undefined) resolve(null);
else resolve(items[index]);
},
);
});
}
/** Resolves to the index of the chosen button, or null when dismissed. */
function actions(message, buttons) {
return new Promise((resolve) => {
nova.workspace.showActionPanel(message, { buttons: buttons }, (index) =>
resolve(index ?? null),
);
});
}
async function confirm(message, confirmLabel = "OK") {
const index = await actions(message, [confirmLabel, "Cancel"]);
return index === 0;
}
function info(message) {
nova.workspace.showInformativeMessage(message);
}
function warn(message) {
nova.workspace.showWarningMessage(message);
}
function error(message) {
nova.workspace.showErrorMessage(String(message && message.message ? message.message : message));
}
/** Creates `dir` and every missing parent. */
function mkdirp(dir) {
const parts = nova.path.split(nova.path.normalize(dir));
let current = nova.path.isAbsolute(dir) ? "/" : "";
for (const part of parts) {
if (!part || part === "/") continue;
current = nova.path.join(current, part);
if (!nova.fs.access(current, nova.fs.F_OK)) {
nova.fs.mkdir(current);
}
}
}
function writeText(path, contents) {
mkdirp(nova.path.dirname(path));
const file = nova.fs.open(path, "w", "utf-8");
try {
file.write(contents);
} finally {
file.close();
}
return path;
}
function writeBinary(path, buffer) {
mkdirp(nova.path.dirname(path));
const file = nova.fs.open(path, "wb");
try {
file.write(new Uint8Array(buffer));
} finally {
file.close();
}
return path;
}
/**
* Opens `contents` in the editor. When `path` is given the text is saved there
* first so the tab is a real file; otherwise it opens as an untitled document.
*/
async function openText(contents, { path = null, syntax = null } = {}) {
if (path) {
try {
writeText(path, contents);
return await nova.workspace.openFile(path);
} catch (writeError) {
log.error("could not save to", path, String(writeError));
// Fall through to an untitled tab rather than losing the content.
}
}
return await nova.workspace.openNewTextDocument({ content: contents, syntax: syntax });
}
exports.input = input;
exports.palette = palette;
exports.choose = choose;
exports.actions = actions;
exports.confirm = confirm;
exports.info = info;
exports.warn = warn;
exports.error = error;
exports.mkdirp = mkdirp;
exports.writeText = writeText;
exports.writeBinary = writeBinary;
exports.openText = openText;