Files
gitea-nova/Scripts/views/branchView.js
T
thatguygriffandClaude Opus 5 87851de921
CI / Tests (push) Successful in 36s
CI / Generated images (push) Successful in 1m1s
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
2026-08-28 20:10:05 -03:00

119 lines
4.1 KiB
JavaScript

//
// "Current Branch" section: the pull requests and workflow runs that belong to
// the branch checked out in the workspace (or to the configured branch filter).
//
const builders = require("./builders.js");
const config = require("../util/config.js");
const nodes = require("./nodes.js");
const { NodeProvider } = require("./provider.js");
const { node, message, errorNode } = nodes;
class BranchProvider extends NodeProvider {
roots() {
const store = this.store;
if (!store.router.baseUrls.length) {
return [message("No Gitea instance configured. Open the extension preferences.")];
}
if (!store.hasAnyToken) {
return [message("No token stored. Run “Gitea → Set Token…” to sign in.")];
}
if (!store.repos.length) {
if (store.unmatchedHosts.length) return builders.unmatchedHostNodes(store);
return [
message(
store.loading
? "Loading…"
: "No repository in this workspace points at a configured Gitea instance.",
),
];
}
const filter = config.branchFilter();
const sections = store.repos.map((repo) => this.repoSection(repo, filter));
return store.repos.length === 1 ? sections[0].children : sections;
}
repoSection(repo, filter) {
const branch = this.store.branchFor(repo);
const label =
filter.mode === "all"
? "all branches"
: branch || "no branch (detached HEAD)";
return node("repo", repo.fullName, {
identifier: `branch-repo-${repo.key}`,
description: label,
tooltip: `${repo.htmlUrl}\nBranch filter: ${label}`,
contextValue: "repo",
repo: repo,
data: { repoKey: repo.key },
expanded: true,
children: [this.pullRequestsFolder(repo, branch), this.runsFolder(repo, branch)],
});
}
pullRequestsFolder(repo, branch) {
const { items, error } = this.store.pullRequestsFor(repo.key);
const matching = branch
? items.filter((pull) => pull.head && pull.head.ref === branch)
: items;
let children;
if (error) children = [errorNode(error)];
else if (!matching.length) {
children = [
message(
branch
? `No open pull request from ${branch}.`
: "No open pull requests.",
),
];
} else {
children = matching.map((pull) => builders.pullRequestNode(this.store, repo, pull));
}
return node("prFolder", "Pull Requests", {
identifier: `branch-prs-${repo.key}`,
description: matching.length ? String(matching.length) : "",
contextValue: "prFolder",
repo: repo,
expanded: true,
children: children,
});
}
runsFolder(repo, branch) {
const { runs, error, legacy } = this.store.runsFor(repo.key);
const matching = branch ? runs.filter((run) => run.head_branch === branch) : runs;
let children;
if (error) children = [errorNode(error)];
else if (!matching.length) {
children = [
message(branch ? `No runs for ${branch}.` : "No workflow runs."),
];
} else {
children = matching.map((run) =>
builders.runNode(this.store, repo, run, { showBranch: !branch }),
);
}
return node("runsFolder", legacy ? "Recent Runs" : "Workflow Runs", {
identifier: `branch-runs-${repo.key}`,
description: matching.length ? String(matching.length) : "",
tooltip: legacy
? "This Gitea server predates the workflow runs API; showing recent tasks instead."
: "",
contextValue: "runsFolder",
repo: repo,
expanded: true,
children: children,
});
}
}
exports.BranchProvider = BranchProvider;