Support instances that serve SSH from another hostname
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
This commit is contained in:
+44
-6
@@ -45,6 +45,14 @@ function bool(key) {
|
||||
return value === null ? DEFAULTS[key] === true : value === true;
|
||||
}
|
||||
|
||||
/** List preferences merge the workspace's entries on top of the global ones. */
|
||||
function arrayPref(key) {
|
||||
const globalEntries = nova.config.get(key, "array") || [];
|
||||
const workspaceEntries =
|
||||
(nova.workspace && nova.workspace.config && nova.workspace.config.get(key, "array")) || [];
|
||||
return [...globalEntries, ...workspaceEntries];
|
||||
}
|
||||
|
||||
/** Trailing slashes make every later URL join ambiguous, so strip them once here. */
|
||||
function normalizeBaseUrl(url) {
|
||||
if (!url) return null;
|
||||
@@ -67,12 +75,7 @@ function instances() {
|
||||
};
|
||||
|
||||
add(get("gitea.baseUrl", "string"));
|
||||
|
||||
const extra =
|
||||
nova.config.get("gitea.instances", "array") ||
|
||||
(nova.workspace && nova.workspace.config.get("gitea.instances", "array")) ||
|
||||
[];
|
||||
for (const url of extra) add(url);
|
||||
for (const url of arrayPref("gitea.instances")) add(url);
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -107,11 +110,46 @@ function setBranchFilter(mode, branch) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Raw "remote-host = instance" entries. Some servers answer SSH on a different
|
||||
* hostname than the web UI, which would otherwise leave those remotes matching
|
||||
* no instance at all.
|
||||
*/
|
||||
function hostAliasEntries() {
|
||||
return arrayPref("gitea.hostAliases");
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends an alias, replacing any existing entry for the same remote host.
|
||||
* Returns false and writes nothing when the preference already says this, so
|
||||
* auto-detection cannot bounce the change observers.
|
||||
*/
|
||||
function addHostAlias(host, baseUrl) {
|
||||
const key = String(host).trim().toLowerCase();
|
||||
const entry = `${key} = ${baseUrl}`;
|
||||
|
||||
const current = nova.config.get("gitea.hostAliases", "array") || [];
|
||||
const kept = current.filter((existing) => {
|
||||
const left = String(existing).split(/\s*(?:=>|->|=)\s*/)[0];
|
||||
return String(left).trim().toLowerCase() !== key;
|
||||
});
|
||||
|
||||
const next = [...kept, entry];
|
||||
if (next.length === current.length && next.every((value, i) => value === current[i])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nova.config.set("gitea.hostAliases", next);
|
||||
return true;
|
||||
}
|
||||
|
||||
exports.get = get;
|
||||
exports.num = num;
|
||||
exports.bool = bool;
|
||||
exports.instances = instances;
|
||||
exports.setInstances = setInstances;
|
||||
exports.hostAliasEntries = hostAliasEntries;
|
||||
exports.addHostAlias = addHostAlias;
|
||||
exports.normalizeBaseUrl = normalizeBaseUrl;
|
||||
exports.branchFilter = branchFilter;
|
||||
exports.setBranchFilter = setBranchFilter;
|
||||
|
||||
Reference in New Issue
Block a user