load latest woodpecker pipelines for dashboard
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -28,12 +28,38 @@ export class WoodpeckerService {
|
|||||||
: isRecord(body) && Array.isArray(body.repos)
|
: isRecord(body) && Array.isArray(body.repos)
|
||||||
? 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 {
|
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> {
|
private async request<T>(path: string): Promise<T> {
|
||||||
const response = await fetch(`${this.baseUrl}${path}`, {
|
const response = await fetch(`${this.baseUrl}${path}`, {
|
||||||
headers: {
|
headers: {
|
||||||
@@ -61,8 +87,7 @@ export class WoodpeckerService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeRepo(repo: WoodpeckerRepo) {
|
function normalizeRepo(repo: WoodpeckerRepo, pipeline = getPipeline(repo)) {
|
||||||
const pipeline = getPipeline(repo);
|
|
||||||
const createdAt = getPipelineTime(pipeline);
|
const createdAt = getPipelineTime(pipeline);
|
||||||
const repository = getString(repo.full_name) || getString(repo.fullName) || joinRepoName(repo) || getString(repo.name) || '-';
|
const repository = getString(repo.full_name) || getString(repo.fullName) || joinRepoName(repo) || getString(repo.name) || '-';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user