| gio | 7f98e77 | 2025-05-07 11:00:14 +0000 | [diff] [blame] | 1 | export interface GitHubRepository { |
| 2 | 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; |
| 10 | } |
| 11 | |
| 12 | export interface GitHubService { |
| 13 | /** |
| 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[]>; |
| 18 | } |
| 19 | |
| 20 | export class GitHubServiceImpl implements GitHubService { |
| 21 | private projectId: string; |
| 22 | |
| 23 | constructor(projectId: string) { |
| 24 | this.projectId = projectId; |
| 25 | } |
| 26 | |
| 27 | async getRepositories(): Promise<GitHubRepository[]> { |
| 28 | const response = await fetch(`/api/project/${this.projectId}/repos/github`); |
| 29 | |
| 30 | if (!response.ok) { |
| 31 | throw new Error(`Failed to fetch repositories: ${response.statusText}`); |
| 32 | } |
| 33 | |
| 34 | return response.json(); |
| 35 | } |
| 36 | } |