// // "Open in Browser" and "Copy URL" for whatever is selected in the sidebar. // const selection = require("./selection.js"); const ui = require("../ui.js"); /** Best web URL for a node, walking up to its repository as a last resort. */ function urlFor(node) { if (!node) return null; const data = node.data || {}; // Most specific first: a job page beats its run's, a comment beats its // pull request's. Anything without a page of its own falls back to the // repository. const direct = (data.comment && data.comment.html_url) || (data.review && data.review.html_url) || (data.file && data.file.html_url) || (data.job && data.job.html_url) || (data.pull && data.pull.html_url) || (data.run && data.run.html_url) || null; if (direct) return direct; if (node.kind === "workflow") { const repo = selection.repoOf(node); return repo ? `${repo.htmlUrl}/actions?workflow=${encodeURIComponent(node.name)}` : null; } if (node.kind === "instance" && data.baseUrl) return data.baseUrl; if (node.kind === "secretsFolder" || node.kind === "secret") { const repo = selection.repoOf(node); return repo ? `${repo.htmlUrl}/settings/actions/secrets` : null; } if (node.kind === "variablesFolder" || node.kind === "variable") { const repo = selection.repoOf(node); return repo ? `${repo.htmlUrl}/settings/actions/variables` : null; } return repoUrl(node); } function repoUrl(node) { const repo = selection.repoOf(node); return repo ? repo.htmlUrl : null; } function register() { nova.commands.register("gitea.openInBrowser", (argument) => { const url = urlFor(selection.selectedNode(argument)); if (!url) { ui.warn("There is no web page for that item."); return; } nova.openURL(url); }); nova.commands.register("gitea.copyUrl", (argument) => { const url = urlFor(selection.selectedNode(argument)); if (!url) { ui.warn("There is no URL for that item."); return; } nova.clipboard.writeText(url); ui.info(`Copied ${url}`); }); } exports.register = register; exports.urlFor = urlFor;