Repository navigation
Expand file tree
/
Copy pathissue_completion_composition_root.ts
More file actions
35 lines (34 loc) · 2.46 KB
/
Copy pathissue_completion_composition_root.ts
File metadata and controls
35 lines (34 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import type { BoundIssueCompletionPort, BoundNativeStatusReadPort, BoundIssueCompletionMetadataPort } from '../../application/ports/issue_completion_ports';
import { IssueCompletionRepository } from '../../data/repository/issue/issue_completion_repository';
import type { GithubIssueCompletionClient } from '../github/ports/github_issue_completion_client';
import { getOctokitClient } from '../github/octokit_client_resolver';
import type { RepositoryCredentialBinding } from './shared_capability_port_binding';
export function bindIssueCompletion(repository: IssueCompletionRepository): BoundIssueCompletionPort {
return Object.freeze({ readPullRequest: (number: number) => repository.readPullRequest(number), forIssue: (number: number) => {
if (!Number.isSafeInteger(number) || number < 1) throw new Error('A safe issue number is required.');
return Object.freeze({
read: () => repository.readIssue(number), close: () => repository.closeIssue(number),
addLabel: (label: string) => repository.addLabel(number, label),
removeLabel: (label: string) => repository.removeLabel(number, label),
});
} });
}
export function bindNativeStatusRead(repository: IssueCompletionRepository): BoundNativeStatusReadPort {
return Object.freeze({ readIssue: (number: number) => repository.readIssue(number),
readPullRequest: (number: number) => repository.readPullRequest(number) });
}
export function bindIssueCompletionMetadata(repository: IssueCompletionRepository): BoundIssueCompletionMetadataPort {
return Object.freeze({ forIssue: (number: number) => {
if (!Number.isSafeInteger(number) || number < 1) throw new Error('A safe issue number is required.');
return Object.freeze({ read: () => repository.readIssue(number),
addLabel: (label: string) => repository.addLabel(number, label),
removeLabel: (label: string) => repository.removeLabel(number, label) });
} });
}
export function createIssueCompletionRepository(binding: RepositoryCredentialBinding): IssueCompletionRepository {
return new IssueCompletionRepository({ getClient: token => getOctokitClient<GithubIssueCompletionClient>(token) },
Object.freeze({ ...binding, apiBaseUrl: process.env.GITHUB_API_URL ?? 'https://api.github.com' }));
}
export function createNativeStatusReadPort(binding: RepositoryCredentialBinding): BoundNativeStatusReadPort {
return bindNativeStatusRead(createIssueCompletionRepository(binding));
}