Files
gitea-nova/Scripts/controllers/secretsVariables.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

195 lines
6.5 KiB
JavaScript

//
// Repository-level Actions secrets and variables.
//
const selection = require("./selection.js");
const ui = require("../ui.js");
const NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
function validateName(name) {
if (!name) return "A name is required.";
if (!NAME_PATTERN.test(name)) {
return "Names may contain letters, digits, and underscores, and cannot start with a digit.";
}
return null;
}
async function repoFor(argument, store, prompt) {
return await selection.resolveRepo(argument, { prompt: prompt });
}
function register(store) {
const reloadSecrets = (repo) => store.loadSecrets(repo);
const reloadVariables = (repo) => store.loadVariables(repo);
nova.commands.register("gitea.refreshSecrets", async (argument) => {
const repo = await repoFor(argument, store, "Refresh secrets for which repository?");
if (repo) await reloadSecrets(repo);
});
nova.commands.register("gitea.refreshVariables", async (argument) => {
const repo = await repoFor(argument, store, "Refresh variables for which repository?");
if (repo) await reloadVariables(repo);
});
nova.commands.register("gitea.createSecret", async (argument) => {
const repo = await repoFor(argument, store, "Add a secret to which repository?");
if (!repo) return;
const name = await ui.input(`New secret in ${repo.fullName}`, {
placeholder: "SECRET_NAME",
});
if (!name) return;
const problem = validateName(name.trim());
if (problem) {
ui.warn(problem);
return;
}
const value = await ui.input(`Value for ${name.trim()}`, {
placeholder: "Secret value",
secure: true,
});
if (value === null) return;
try {
await store.apiFor(repo).setSecret(repo, name.trim(), value);
ui.info(`Saved secret ${name.trim()}.`);
} catch (error) {
ui.error(`Could not save the secret: ${error.message || error}`);
return;
}
await reloadSecrets(repo);
});
nova.commands.register("gitea.updateSecret", async (argument) => {
const node = selection.selectedNode(argument);
const secret = node && node.data ? node.data.secret : null;
const repo = selection.repoOf(node);
if (!secret || !repo) {
ui.warn("Select a secret first.");
return;
}
// Gitea never returns a secret's value, so an update always sets a new one.
const value = await ui.input(`New value for ${secret.name}`, {
placeholder: "Secret value",
secure: true,
});
if (value === null) return;
try {
await store.apiFor(repo).setSecret(repo, secret.name, value);
ui.info(`Updated secret ${secret.name}.`);
} catch (error) {
ui.error(`Could not update the secret: ${error.message || error}`);
return;
}
await reloadSecrets(repo);
});
nova.commands.register("gitea.deleteSecret", async (argument) => {
const node = selection.selectedNode(argument);
const secret = node && node.data ? node.data.secret : null;
const repo = selection.repoOf(node);
if (!secret || !repo) {
ui.warn("Select a secret first.");
return;
}
if (!(await ui.confirm(`Delete secret ${secret.name} from ${repo.fullName}?`, "Delete"))) {
return;
}
try {
await store.apiFor(repo).deleteSecret(repo, secret.name);
ui.info(`Deleted secret ${secret.name}.`);
} catch (error) {
ui.error(`Could not delete the secret: ${error.message || error}`);
return;
}
await reloadSecrets(repo);
});
nova.commands.register("gitea.createVariable", async (argument) => {
const repo = await repoFor(argument, store, "Add a variable to which repository?");
if (!repo) return;
const name = await ui.input(`New variable in ${repo.fullName}`, {
placeholder: "VARIABLE_NAME",
});
if (!name) return;
const problem = validateName(name.trim());
if (problem) {
ui.warn(problem);
return;
}
const value = await ui.input(`Value for ${name.trim()}`, { placeholder: "Value" });
if (value === null) return;
try {
await store.apiFor(repo).createVariable(repo, name.trim(), value);
ui.info(`Created variable ${name.trim()}.`);
} catch (error) {
ui.error(`Could not create the variable: ${error.message || error}`);
return;
}
await reloadVariables(repo);
});
nova.commands.register("gitea.updateVariable", async (argument) => {
const node = selection.selectedNode(argument);
const variable = node && node.data ? node.data.variable : null;
const repo = selection.repoOf(node);
if (!variable || !repo) {
ui.warn("Select a variable first.");
return;
}
const value = await ui.input(`New value for ${variable.name}`, {
placeholder: "Value",
value: variable.data || variable.value || "",
});
if (value === null) return;
try {
await store.apiFor(repo).updateVariable(repo, variable.name, value);
ui.info(`Updated variable ${variable.name}.`);
} catch (error) {
ui.error(`Could not update the variable: ${error.message || error}`);
return;
}
await reloadVariables(repo);
});
nova.commands.register("gitea.deleteVariable", async (argument) => {
const node = selection.selectedNode(argument);
const variable = node && node.data ? node.data.variable : null;
const repo = selection.repoOf(node);
if (!variable || !repo) {
ui.warn("Select a variable first.");
return;
}
if (
!(await ui.confirm(`Delete variable ${variable.name} from ${repo.fullName}?`, "Delete"))
) {
return;
}
try {
await store.apiFor(repo).deleteVariable(repo, variable.name);
ui.info(`Deleted variable ${variable.name}.`);
} catch (error) {
ui.error(`Could not delete the variable: ${error.message || error}`);
return;
}
await reloadVariables(repo);
});
}
exports.register = register;
exports.validateName = validateName;