Refreshing rebuilt the whole tree, and TreeView.reload() with no argument drops the scroll position. Watching a job meant the view jumped every fifteen seconds. The provider now reconciles instead of replacing. update() rebuilds from the store, matches rows to the existing nodes by identifier, copies the rendered fields onto them, and reports the topmost rows that actually changed; main.js reloads just those. Node identity survives the merge, which is what makes a targeted reload possible. An open row that fetches its own children has that cache dropped so it refetches — the running-job path. A job finishing now reloads one run's row and nothing else. Sections also each describe what they draw, so a section only rebuilds when its own content moved: run activity no longer disturbs the pull request list, and an idle tree is left alone entirely. This does not slow anything down — a section showing a run in progress still updates on every poll, and contributes a time bucket so its elapsed clock keeps moving. A row set changing at the root still needs a whole-tree reload; there the selected row is re-revealed afterwards, which is the closest thing to a scroll anchor Nova exposes. Adds seventeen checks: no-op updates reporting nothing, a finishing job naming only its own row, node identity surviving, a new run reloading just its workflow group, and a new workflow escalating to a full reload. 168 checks total. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MQuusXgZC2dzwpJJ1qhtti
131 lines
4.5 KiB
JavaScript
131 lines
4.5 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 {
|
|
signature() {
|
|
const store = this.store;
|
|
const filter = config.branchFilter();
|
|
const parts = [store.baseSignature(), `filter:${filter.mode}:${filter.branch || ""}`];
|
|
|
|
for (const repo of store.repos) {
|
|
parts.push(store.runsSignature(repo.key), store.pullsSignature(repo.key));
|
|
parts.push(store.elapsedTick(store.runsFor(repo.key).runs));
|
|
}
|
|
return parts.join("|");
|
|
}
|
|
|
|
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;
|