blob: b1732a01f4755bad4230c66777f6cbc30942172c [file] [log] [blame]
gio7f98e772025-05-07 11:00:14 +00001export interface GitHubRepository {
giod0026612025-05-08 13:00:36 +00002 id: number;
3 name: string;
4 full_name: string;
5 html_url: string;
6 ssh_url: string;
7 description: string | null;
8 private: boolean;
9 default_branch: string;
gio7f98e772025-05-07 11:00:14 +000010}
11
12export interface GitHubService {
giod0026612025-05-08 13:00:36 +000013 /**
14 * Fetches a list of repositories for the authenticated user
15 * @returns Promise resolving to an array of GitHub repositories
16 */
17 getRepositories(): Promise<GitHubRepository[]>;
gio7f98e772025-05-07 11:00:14 +000018}
19
20export class GitHubServiceImpl implements GitHubService {
giod0026612025-05-08 13:00:36 +000021 private projectId: string;
gio7f98e772025-05-07 11:00:14 +000022
giod0026612025-05-08 13:00:36 +000023 constructor(projectId: string) {
24 this.projectId = projectId;
25 }
gio7f98e772025-05-07 11:00:14 +000026
giod0026612025-05-08 13:00:36 +000027 async getRepositories(): Promise<GitHubRepository[]> {
28 const response = await fetch(`/api/project/${this.projectId}/repos/github`);
gio7f98e772025-05-07 11:00:14 +000029
giod0026612025-05-08 13:00:36 +000030 if (!response.ok) {
31 throw new Error(`Failed to fetch repositories: ${response.statusText}`);
32 }
gio7f98e772025-05-07 11:00:14 +000033
giod0026612025-05-08 13:00:36 +000034 return response.json();
35 }
36}