load latest woodpecker pipelines for dashboard
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2026-07-06 18:32:57 +09:00
parent 3aa90d2eee
commit b3dbcfd87f
+28 -3
View File
@@ -28,12 +28,38 @@ export class WoodpeckerService {
: isRecord(body) && Array.isArray(body.repos)
? body.repos
: [];
const normalizedRepos = repos.map((repo) => (isRecord(repo) ? repo : {}));
const pipelines = await Promise.all(
normalizedRepos.map((repo) => this.getLatestPipeline(repo).catch(() => getPipeline(repo))),
);
return {
repos: repos.map((repo) => normalizeRepo(repo)).sort((a, b) => b.createdAt - a.createdAt),
repos: normalizedRepos
.map((repo, index) => normalizeRepo(repo, pipelines[index]))
.sort((a, b) => b.createdAt - a.createdAt),
};
}
private async getLatestPipeline(repo: WoodpeckerRepo): Promise<WoodpeckerPipeline> {
const embeddedPipeline = getPipeline(repo);
if (getPipelineTime(embeddedPipeline) > 0) return embeddedPipeline;
const repoId = getString(repo.id);
if (!repoId) return {};
const body = await this.request<unknown>(
`/api/repos/${encodeURIComponent(repoId)}/pipelines?page=1&limit=1`,
);
const pipelines = Array.isArray(body)
? body
: isRecord(body) && Array.isArray(body.pipelines)
? body.pipelines
: [];
const latest = pipelines[0];
return isRecord(latest) ? latest : {};
}
private async request<T>(path: string): Promise<T> {
const response = await fetch(`${this.baseUrl}${path}`, {
headers: {
@@ -61,8 +87,7 @@ export class WoodpeckerService {
}
}
function normalizeRepo(repo: WoodpeckerRepo) {
const pipeline = getPipeline(repo);
function normalizeRepo(repo: WoodpeckerRepo, pipeline = getPipeline(repo)) {
const createdAt = getPipelineTime(pipeline);
const repository = getString(repo.full_name) || getString(repo.fullName) || joinRepoName(repo) || getString(repo.name) || '-';