-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.module.ts
104 lines (97 loc) · 2.82 KB
/
runner.module.ts
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* @file RunnerModule
* @module repostructure/RunnerModule
*/
import { Global, Module, type OnApplicationBootstrap } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { CommandBus, CqrsModule } from '@nestjs/cqrs'
import { AppsModule } from './subdomains/apps'
import {
BranchesModule,
ManageBranchProtectionsCommand
} from './subdomains/branches'
import { ConfigModule, type Config } from './subdomains/config'
import {
EnvironmentsModule,
ManageEnvironmentsCommand
} from './subdomains/environments'
import { LabelsModule, ManageLabelsCommand } from './subdomains/labels'
import { OctokitModule } from './subdomains/octokit'
import {
ManagePullRequestsCommand,
PullRequestsModule
} from './subdomains/pull-requests'
import { ManageSecurityCommand, SecurityModule } from './subdomains/security'
import { TeamsModule } from './subdomains/teams'
import { UsersModule } from './subdomains/users'
import type { Infrastructure, InfrastructureCommand } from './types'
/**
* Action runner module.
*
* @class
* @implements {OnApplicationBootstrap}
*/
@Global()
@Module({
imports: [
AppsModule,
BranchesModule,
ConfigModule.forRoot(),
CqrsModule.forRoot(),
EnvironmentsModule,
LabelsModule,
OctokitModule,
PullRequestsModule,
SecurityModule,
TeamsModule,
UsersModule
]
})
class RunnerModule implements OnApplicationBootstrap {
/**
* Create a new action runner module.
*
* @see {@linkcode CommandBus}
* @see {@linkcode ConfigService}
* @see {@linkcode Config}
*
* @param {ConfigService<Config, true>} config - Infrastructure config service
* @param {CommandBus} commands - Command bus
*/
constructor(
protected readonly config: ConfigService<Config, true>,
protected readonly commands: CommandBus
) {}
/**
* Manage repository infrastructure.
*
* @public
* @async
*
* @return {Promise<void>} Nothing when complete
*/
public async onApplicationBootstrap(): Promise<void> {
/**
* Repository infrastructure object.
*
* @const {Infrastructure} infrastructure
*/
const infrastructure: Infrastructure = this.config.get('infrastructure')
/**
* Infrastructure management commands to execute.
*
* @const {InfrastructureCommand[]} commands
*/
const commands: InfrastructureCommand[] = [
new ManageSecurityCommand(infrastructure.security),
new ManagePullRequestsCommand(infrastructure.pull_requests),
new ManageLabelsCommand(infrastructure.labels),
new ManageEnvironmentsCommand(infrastructure.environments),
new ManageBranchProtectionsCommand(infrastructure.branches)
]
// execute management commands
for (const command of commands) await this.commands.execute(command)
return void infrastructure
}
}
export default RunnerModule