| 51 | } |
| 52 | |
| 53 | export class GitHubAdapter implements IPlatformAdapter { |
| 54 | private octokit: Octokit; |
| 55 | private webhookSecret: string; |
| 56 | |
| 57 | constructor(token: string, webhookSecret: string) { |
| 58 | this.octokit = new Octokit({ auth: token }); |
| 59 | this.webhookSecret = webhookSecret; |
| 60 | console.log('[GitHub] Adapter initialized with secret:', webhookSecret.substring(0, 8) + '...'); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Send a message to a GitHub issue or PR |
| 65 | */ |
| 66 | async sendMessage(conversationId: string, message: string): Promise<void> { |
| 67 | const parsed = this.parseConversationId(conversationId); |
| 68 | if (!parsed) { |
| 69 | console.error('[GitHub] Invalid conversationId:', conversationId); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | try { |
| 74 | await this.octokit.rest.issues.createComment({ |
| 75 | owner: parsed.owner, |
| 76 | repo: parsed.repo, |
| 77 | issue_number: parsed.number, |
| 78 | body: message, |
| 79 | }); |
| 80 | console.log(`[GitHub] Comment posted to ${conversationId}`); |
| 81 | } catch (error) { |
| 82 | console.error('[GitHub] Failed to post comment:', { error, conversationId }); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Get streaming mode (always batch for GitHub to avoid comment spam) |
| 88 | */ |
| 89 | getStreamingMode(): 'batch' { |
| 90 | return 'batch'; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Get platform type |
| 95 | */ |
| 96 | getPlatformType(): string { |
| 97 | return 'github'; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Start the adapter (no-op for webhook-based adapter) |
| 102 | */ |
| 103 | async start(): Promise<void> { |
| 104 | console.log('[GitHub] Webhook adapter ready'); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Stop the adapter (no-op for webhook-based adapter) |
| 109 | */ |
| 110 | stop(): void { |
nothing calls this directly
no outgoing calls
no test coverage detected