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