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
86 lines
3.0 KiB
JavaScript
86 lines
3.0 KiB
JavaScript
//
|
|
// "Workflows" section: every run in the repository, grouped by workflow file.
|
|
// Servers without the workflow runs API fall back to a flat "Recent Runs" list.
|
|
//
|
|
|
|
const builders = require("./builders.js");
|
|
const nodes = require("./nodes.js");
|
|
const { NodeProvider } = require("./provider.js");
|
|
|
|
const { node, message, errorNode } = nodes;
|
|
|
|
class WorkflowsProvider extends NodeProvider {
|
|
signature() {
|
|
const store = this.store;
|
|
const parts = [store.baseSignature()];
|
|
|
|
for (const repo of store.repos) {
|
|
parts.push(store.runsSignature(repo.key));
|
|
parts.push(store.elapsedTick(store.runsFor(repo.key).runs));
|
|
}
|
|
return parts.join("|");
|
|
}
|
|
|
|
roots() {
|
|
const store = this.store;
|
|
|
|
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 Gitea repositories found.")];
|
|
}
|
|
|
|
const sections = store.repos.map((repo) => this.repoSection(repo));
|
|
return store.repos.length === 1 ? sections[0].children : sections;
|
|
}
|
|
|
|
repoSection(repo) {
|
|
const { runs, error, legacy } = this.store.runsFor(repo.key);
|
|
|
|
let children;
|
|
if (error) children = [errorNode(error)];
|
|
else if (!runs.length) children = [message("No workflow runs.")];
|
|
else if (legacy) children = runs.map((run) => builders.runNode(this.store, repo, run));
|
|
else children = this.groupByWorkflow(repo, runs);
|
|
|
|
return node("repo", repo.fullName, {
|
|
identifier: `wf-repo-${repo.key}`,
|
|
description: legacy ? "recent runs" : `${runs.length} runs`,
|
|
tooltip: repo.htmlUrl,
|
|
contextValue: "repo",
|
|
repo: repo,
|
|
data: { repoKey: repo.key },
|
|
expanded: true,
|
|
children: children,
|
|
});
|
|
}
|
|
|
|
groupByWorkflow(repo, runs) {
|
|
const groups = new Map();
|
|
for (const run of runs) {
|
|
const key = nodes.workflowKey(run);
|
|
if (!groups.has(key)) {
|
|
groups.set(key, { label: nodes.workflowLabel(run), runs: [] });
|
|
}
|
|
groups.get(key).runs.push(run);
|
|
}
|
|
|
|
return [...groups.entries()].map(([key, group]) => {
|
|
const latest = group.runs[0];
|
|
return node("workflow", group.label, {
|
|
identifier: `wf-${repo.key}-${key}`,
|
|
description: `${nodes.glyphFor(nodes.runState(latest))} ${group.runs.length}`,
|
|
tooltip: `${key}\nMost recent: ${nodes.runTitle(latest)}`,
|
|
contextValue: "workflow",
|
|
repo: repo,
|
|
data: { workflowPath: key, run: latest, repoKey: repo.key },
|
|
children: group.runs.map((run) => builders.runNode(this.store, repo, run)),
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
exports.WorkflowsProvider = WorkflowsProvider;
|