Files
gitea-nova/Scripts/controllers/runControl.js
T
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

79 lines
2.6 KiB
JavaScript

//
// Re-running and cancelling workflow runs.
//
const nodes = require("../views/nodes.js");
const selection = require("./selection.js");
const ui = require("../ui.js");
function contextFrom(argument) {
const node = selection.selectedNode(argument);
const repo = selection.repoOf(node);
const run = selection.runFor(node);
const job = node && node.data ? node.data.job : null;
return { node, repo, run, job };
}
/** Runs `action`, reports the outcome, and refreshes so the new state shows. */
async function perform(store, refresh, repo, label, action) {
try {
await action();
ui.info(`${label} requested for ${repo.fullName}.`);
} catch (error) {
const hint = error.status === 403 ? " The token needs Actions write access." : "";
ui.error(`${label} failed: ${error.message || error}${hint}`);
return;
}
await refresh();
}
function register(store, refresh) {
nova.commands.register("gitea.rerunRun", async (argument) => {
const { repo, run } = contextFrom(argument);
if (!repo || !run) {
ui.warn("Select a workflow run first.");
return;
}
await perform(store, refresh, repo, `Re-run of ${nodes.runTitle(run)}`, () =>
store.apiFor(repo).rerunRun(repo, run.id),
);
});
nova.commands.register("gitea.rerunFailedJobs", async (argument) => {
const { repo, run } = contextFrom(argument);
if (!repo || !run) {
ui.warn("Select a workflow run first.");
return;
}
await perform(store, refresh, repo, `Re-run of failed jobs in ${nodes.runTitle(run)}`, () =>
store.apiFor(repo).rerunFailedJobs(repo, run.id),
);
});
nova.commands.register("gitea.rerunJob", async (argument) => {
const { repo, run, job } = contextFrom(argument);
if (!repo || !run || !job) {
ui.warn("Select a job first.");
return;
}
await perform(store, refresh, repo, `Re-run of ${job.name || job.id}`, () =>
store.apiFor(repo).rerunJob(repo, run.id, job.id),
);
});
nova.commands.register("gitea.cancelRun", async (argument) => {
const { repo, run } = contextFrom(argument);
if (!repo || !run) {
ui.warn("Select a workflow run first.");
return;
}
if (!(await ui.confirm(`Cancel ${nodes.runTitle(run)}?`, "Cancel Run"))) return;
await perform(store, refresh, repo, `Cancellation of ${nodes.runTitle(run)}`, () =>
store.apiFor(repo).cancelRun(repo, run.id),
);
});
}
exports.register = register;