fix: project center — Gitea API wraps responses in {ok,data}, extract data field
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 44s

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
WangDL 2026-05-24 20:36:32 +08:00
parent b81b7fba92
commit e36f9c9785

View File

@ -20,18 +20,30 @@ export class GiteaService {
} }
} }
private extractData<T>(response: any): T | null {
if (!response) return null;
// Gitea API wraps responses in {ok: true, data: ...}
if (response.ok && Array.isArray(response.data)) return response.data as T;
// Direct array response (standard REST API)
if (Array.isArray(response)) return response as T;
return null;
}
async getRepos() { async getRepos() {
// Try search with wildcard first, fall back to user repos let repos: any[] | null = null;
let repos = await this.giteaGet<any[]>('/repos/search?q=&limit=50');
const searchResult = await this.giteaGet<any>('/repos/search?q=&limit=50');
repos = this.extractData<any[]>(searchResult);
if (!repos || repos.length === 0) { if (!repos || repos.length === 0) {
repos = await this.giteaGet<any[]>('/user/repos?limit=50'); const userResult = await this.giteaGet<any>('/user/repos?limit=50');
repos = this.extractData<any[]>(userResult);
} }
if (!repos) return []; if (!repos) return [];
const enriched: any[] = []; const enriched: any[] = [];
for (const r of repos) { for (const r of repos) {
const fullName = r.full_name; const fullName = r.full_name;
// Just use open_issues_count from the search result; skip extra API calls
enriched.push({ enriched.push({
id: r.id, name: r.name, fullName, description: r.description, id: r.id, name: r.name, fullName, description: r.description,
owner: r.owner?.login, stars: r.stars_count ?? 0, forks: r.forks_count ?? 0, owner: r.owner?.login, stars: r.stars_count ?? 0, forks: r.forks_count ?? 0,
@ -43,20 +55,24 @@ export class GiteaService {
} }
async getMilestones(owner: string, repo: string) { async getMilestones(owner: string, repo: string) {
return this.giteaGet<any[]>(`/repos/${owner}/${repo}/milestones?state=all`) ?? []; const result = await this.giteaGet<any>(`/repos/${owner}/${repo}/milestones?state=all`);
return this.extractData<any[]>(result) ?? [];
} }
async getIssues(owner: string, repo: string, milestone?: string, state = 'open') { async getIssues(owner: string, repo: string, milestone?: string, state = 'open') {
let path = `/repos/${owner}/${repo}/issues?state=${state}&limit=50`; let path = `/repos/${owner}/${repo}/issues?state=${state}&limit=50`;
if (milestone) path += `&milestone=${milestone}`; if (milestone) path += `&milestone=${milestone}`;
return this.giteaGet<any[]>(path) ?? []; const result = await this.giteaGet<any>(path);
return this.extractData<any[]>(result) ?? [];
} }
async getRunners() { async getRunners() {
return this.giteaGet<any[]>('/admin/runners') ?? []; const result = await this.giteaGet<any>('/admin/runners');
return this.extractData<any[]>(result) ?? [];
} }
async getReleases(owner: string, repo: string) { async getReleases(owner: string, repo: string) {
return this.giteaGet<any[]>(`/repos/${owner}/${repo}/releases?limit=20`) ?? []; const result = await this.giteaGet<any>(`/repos/${owner}/${repo}/releases?limit=20`);
return this.extractData<any[]>(result) ?? [];
} }
} }