// // "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 { roots() { const store = this.store; if (!store.hasAnyToken) { return [message("No token stored. Run “Gitea → Set Token…” to sign in.")]; } if (!store.repos.length) { 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;