Discovery matched a git remote's host against the instance URL's host, so a server answering SSH on a different name than its web UI resolved to nothing — and said so only in a debug log. Resolution now runs in three stages. A remote host is matched directly, then against configured aliases, and failing both the instances are asked for the repository: Gitea publishes its SSH hostname in a repository's ssh_url, so the right instance identifies itself. What that turns up is saved as a host alias, so later repositories on the same host resolve with no lookup at all, and the mapping is visible and editable rather than hidden. Each unknown host is probed at most once per session. When nothing resolves the sidebar now names the unmatched host and offers Add Host Alias, instead of showing an empty section. Aliases can also be written by hand as "remote-host = instance URL", accepting =, -> and =>, ignoring ports, and skipping # comments. List preferences now merge workspace entries onto global ones rather than letting an empty global array mask them. Adds Tests/host-aliases.test.js covering both directions: unmatched hosts reported and nothing persisted, a hand-written alias, detection from ssh_url, and a later repository resolving from the stored alias without a probe. 131 checks across three suites. Also adds CLAUDE.md, and .gitea/workflows/ci.yml running the suites, script syntax checks, manifest validation, and a generated-image check. Tools/make-icons.py gains --check, which compares decompressed pixels so a differing zlib version cannot fail it spuriously. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MQuusXgZC2dzwpJJ1qhtti
178 lines
5.8 KiB
JavaScript
178 lines
5.8 KiB
JavaScript
//
|
|
// Entry point. Builds the store, the four sidebar sections, and the command
|
|
// handlers, then keeps the sections in step with the store.
|
|
//
|
|
|
|
const artifacts = require("./controllers/artifacts.js");
|
|
const auth = require("./controllers/auth.js");
|
|
const browser = require("./controllers/browser.js");
|
|
const log = require("./util/log.js");
|
|
const logs = require("./controllers/logs.js");
|
|
const pullRequests = require("./controllers/pullRequests.js");
|
|
const review = require("./controllers/review.js");
|
|
const runControl = require("./controllers/runControl.js");
|
|
const secretsVariables = require("./controllers/secretsVariables.js");
|
|
const selection = require("./controllers/selection.js");
|
|
const ui = require("./ui.js");
|
|
|
|
const { BranchProvider } = require("./views/branchView.js");
|
|
const { PullRequestsProvider } = require("./views/pullRequestsView.js");
|
|
const { ReviewCommentsController } = require("./controllers/reviewComments.js");
|
|
const { SettingsProvider } = require("./views/settingsView.js");
|
|
const { Store } = require("./store.js");
|
|
const { WorkflowsProvider } = require("./views/workflowsView.js");
|
|
|
|
const RELOAD_DEBOUNCE_MS = 150;
|
|
|
|
// Preferences that change which repositories exist, rather than only how they
|
|
// are displayed, force a full rediscovery.
|
|
const REDISCOVERY_KEYS = [
|
|
"gitea.baseUrl",
|
|
"gitea.instances",
|
|
"gitea.hostAliases",
|
|
"gitea.discovery.mode",
|
|
];
|
|
const DISPLAY_KEYS = [
|
|
"gitea.maxRunsPerRepo",
|
|
"gitea.maxJobsPerRun",
|
|
"gitea.branchFilter",
|
|
"gitea.branchFilter.custom",
|
|
];
|
|
|
|
let state = null;
|
|
|
|
function buildSections(store) {
|
|
const definitions = [
|
|
{ id: "gitea.branch", provider: new BranchProvider(store) },
|
|
{ id: "gitea.workflows", provider: new WorkflowsProvider(store) },
|
|
{ id: "gitea.pullRequests", provider: new PullRequestsProvider(store) },
|
|
{ id: "gitea.settings", provider: new SettingsProvider(store) },
|
|
];
|
|
|
|
return definitions.map((definition) => {
|
|
const view = new TreeView(definition.id, { dataProvider: definition.provider });
|
|
nova.subscriptions.add(view);
|
|
return Object.assign(definition, { view: view });
|
|
});
|
|
}
|
|
|
|
/** Rebuilds every section from current store state. */
|
|
function reloadSections(sections) {
|
|
for (const section of sections) {
|
|
section.provider.invalidate();
|
|
section.view.reload().catch((error) => log.debug("reload failed", String(error)));
|
|
}
|
|
}
|
|
|
|
function registerCommands(store, refresh, sections, reviewComments) {
|
|
auth.register(store, refresh);
|
|
logs.register(store);
|
|
artifacts.register(store);
|
|
runControl.register(store, refresh);
|
|
pullRequests.register(store, refresh);
|
|
review.register(store, refresh, reviewComments);
|
|
secretsVariables.register(store);
|
|
browser.register();
|
|
|
|
nova.commands.register("gitea.refresh", async () => {
|
|
await refresh({ rediscover: true });
|
|
await reviewComments.reload({ force: true });
|
|
});
|
|
|
|
// The per-section refresh buttons all drive the same fetch; they exist so
|
|
// each section header has an affordance of its own.
|
|
for (const name of ["gitea.refreshRuns", "gitea.refreshPullRequests", "gitea.refreshSettings"]) {
|
|
nova.commands.register(name, () => refresh());
|
|
}
|
|
|
|
nova.commands.register("gitea.refreshRepo", async (argument) => {
|
|
const repo = await selection.resolveRepo(argument, {
|
|
prompt: "Refresh which repository?",
|
|
});
|
|
if (repo) await store.refreshRepo(repo.key);
|
|
});
|
|
}
|
|
|
|
function watchPreferences(refresh) {
|
|
const subscriptions = [];
|
|
|
|
for (const key of REDISCOVERY_KEYS) {
|
|
subscriptions.push(nova.config.onDidChange(key, () => refresh({ rediscover: true })));
|
|
}
|
|
for (const key of DISPLAY_KEYS) {
|
|
subscriptions.push(nova.config.onDidChange(key, () => refresh()));
|
|
if (nova.workspace && nova.workspace.config) {
|
|
subscriptions.push(nova.workspace.config.onDidChange(key, () => refresh()));
|
|
}
|
|
}
|
|
if (nova.workspace && nova.workspace.config) {
|
|
subscriptions.push(
|
|
nova.workspace.config.onDidChange("gitea.baseUrl", () =>
|
|
refresh({ rediscover: true }),
|
|
),
|
|
);
|
|
}
|
|
|
|
for (const subscription of subscriptions) {
|
|
if (subscription) nova.subscriptions.add(subscription);
|
|
}
|
|
}
|
|
|
|
exports.activate = function () {
|
|
const store = new Store();
|
|
const sections = buildSections(store);
|
|
const reviewComments = new ReviewCommentsController(store);
|
|
|
|
selection.configure(
|
|
store,
|
|
sections.map((section) => section.view),
|
|
);
|
|
|
|
let timer = null;
|
|
const scheduleReload = () => {
|
|
if (timer) clearTimeout(timer);
|
|
timer = setTimeout(() => {
|
|
timer = null;
|
|
reloadSections(sections);
|
|
}, RELOAD_DEBOUNCE_MS);
|
|
};
|
|
|
|
const subscription = store.onDidChange(scheduleReload);
|
|
|
|
const refresh = (options) =>
|
|
store.refresh(options).catch((error) => {
|
|
log.error("refresh failed", String(error));
|
|
});
|
|
|
|
registerCommands(store, refresh, sections, reviewComments);
|
|
watchPreferences(refresh);
|
|
|
|
state = {
|
|
store: store,
|
|
sections: sections,
|
|
reviewComments: reviewComments,
|
|
subscription: subscription,
|
|
cancelReload: () => {
|
|
if (timer) clearTimeout(timer);
|
|
},
|
|
};
|
|
|
|
log.info(`activated for ${store.router.baseUrls.join(", ") || "no configured instance"}`);
|
|
|
|
if (!store.router.baseUrls.length) {
|
|
ui.warn("Gitea: set an instance URL in the extension preferences to get started.");
|
|
return;
|
|
}
|
|
|
|
refresh({ rediscover: true }).then(() => reviewComments.reload({ force: true }));
|
|
};
|
|
|
|
exports.deactivate = function () {
|
|
if (!state) return;
|
|
state.cancelReload();
|
|
state.subscription.dispose();
|
|
state.reviewComments.dispose();
|
|
state.store.dispose();
|
|
state = null;
|
|
};
|