Repository navigation
Expand file tree
/
Copy pathexecution_setup_composition_root.ts
More file actions
74 lines (72 loc) · 3.54 KB
/
Copy pathexecution_setup_composition_root.ts
File metadata and controls
74 lines (72 loc) · 3.54 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { ExecutionBranchVersionResolver } from '../../application/usecases/execution/execution_branch_version_resolver';
import { SetupExecutionUseCase } from '../../application/usecases/execution/setup_execution_use_case';
import { GetHotfixVersionUseCase } from '../../application/usecases/steps/common/get_hotfix_version_use_case';
import { GetReleaseTypeUseCase } from '../../application/usecases/steps/common/get_release_type_use_case';
import { GetReleaseVersionUseCase } from '../../application/usecases/steps/common/get_release_version_use_case';
import type { LatestTagQueryPort } from '../../application/ports/branch_tag_ports';
import type {
SetupConfigurationQueryPort,
SetupIssueQueryPort,
SetupOrganizationQueryPort,
} from '../../application/ports/setup_execution_ports';
import { ConfigurationHandler } from '../../manager/description/configuration_handler';
import { createAuthenticatedUserCompositionRoot } from './authenticated_user_composition_root';
import { createExecutionIssueSetupCompositionRoot } from './execution_issue_setup_composition_root';
export interface SetupExecutionCredentials {
readonly owner: string;
readonly repository: string;
readonly token: string;
}
export function createSetupExecutionUseCase(
latestTagQueryPort: LatestTagQueryPort,
credentials: SetupExecutionCredentials,
): SetupExecutionUseCase {
const rawIssueSetupPort = createExecutionIssueSetupCompositionRoot();
const rawOrganizationSetupPort = createAuthenticatedUserCompositionRoot();
const configurationHandler = new ConfigurationHandler(rawIssueSetupPort);
const issueSetupPort: SetupIssueQueryPort = {
isPullRequest: (issueNumber) => rawIssueSetupPort.isPullRequest(
credentials.owner, credentials.repository, issueNumber, credentials.token,
),
isIssue: (issueNumber) => rawIssueSetupPort.isIssue(
credentials.owner, credentials.repository, issueNumber, credentials.token,
),
getHeadBranch: (issueNumber) => rawIssueSetupPort.getHeadBranch(
credentials.owner, credentials.repository, issueNumber, credentials.token,
),
getLabels: (issueNumber) => rawIssueSetupPort.getLabels(
credentials.owner, credentials.repository, issueNumber, credentials.token,
),
getTitle: (issueNumber) => rawIssueSetupPort.getTitle(
credentials.owner, credentials.repository, issueNumber, credentials.token,
),
getDescription: (issueNumber) => rawIssueSetupPort.getDescription(
credentials.owner, credentials.repository, issueNumber, credentials.token,
),
};
const organizationSetupPort: SetupOrganizationQueryPort = {
getTokenUser: () => rawOrganizationSetupPort.getUserFromToken(credentials.token),
};
const configurationPort: SetupConfigurationQueryPort = {
get: (issueNumber) => configurationHandler.get({
owner: credentials.owner,
repository: credentials.repository,
issueNumber,
token: credentials.token,
}),
};
const releaseVersion = new GetReleaseVersionUseCase(issueSetupPort);
const releaseType = new GetReleaseTypeUseCase(issueSetupPort);
const hotfixVersion = new GetHotfixVersionUseCase(issueSetupPort);
return new SetupExecutionUseCase(
issueSetupPort,
organizationSetupPort,
configurationPort,
new ExecutionBranchVersionResolver(
latestTagQueryPort,
releaseVersion,
releaseType,
hotfixVersion,
),
);
}