-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublicRepo.ts
108 lines (96 loc) · 2.27 KB
/
publicRepo.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
105
106
107
108
import * as gh from '@pulumi/github';
import {
RepositoryRulesetRules,
RepositoryRulesetRulesRequiredStatusChecks,
RepositoryTemplate,
} from '@pulumi/github/types/input';
import { ComponentResourceOptions, Input, output } from '@pulumi/pulumi';
import { Repo } from './repo';
const integrationIds = {
github: 15368,
};
export interface PublicRepoArgs {
description: Input<string>;
githubChecks?: Input<Input<string>[]>;
requiredChecks?: RepositoryRulesetRulesRequiredStatusChecks['requiredChecks'];
template?: RepositoryTemplate;
}
export class PublicRepo extends Repo {
public readonly mainRuleset: gh.RepositoryRuleset;
constructor(
name: string,
args: PublicRepoArgs,
opts?: ComponentResourceOptions,
) {
super(
'unmango:github:PublicRepo',
name,
{
overrides: {
name,
description: args.description,
visibility: 'public',
allowAutoMerge: true,
template: args.template,
vulnerabilityAlerts: true,
},
},
opts,
);
const repo = this.repo;
const statusChecks = args.githubChecks
? getGitHubStatusChecks(args.githubChecks)
: getRequiredStatusChecks(args.requiredChecks);
const mainRuleset = new gh.RepositoryRuleset(
name,
{
name: 'main',
repository: repo.name,
enforcement: 'active',
target: 'branch',
conditions: {
refName: {
includes: ['~DEFAULT_BRANCH'],
excludes: [],
},
},
rules: {
deletion: true,
pullRequest: {
dismissStaleReviewsOnPush: true,
requiredReviewThreadResolution: true,
},
nonFastForward: true,
requiredLinearHistory: true,
requiredSignatures: true,
requiredStatusChecks: statusChecks,
},
},
{ parent: this },
);
this.mainRuleset = mainRuleset;
this.registerOutputs({
repo,
mainRuleset,
});
}
}
function getGitHubStatusChecks(
checks: PublicRepoArgs['githubChecks'],
): RepositoryRulesetRules['requiredStatusChecks'] {
if (!checks) return;
return getRequiredStatusChecks(
output(checks).apply(c =>
c.map(x => ({
integrationId: integrationIds.github,
context: x,
}))
),
);
}
function getRequiredStatusChecks(
checks: PublicRepoArgs['requiredChecks'],
): RepositoryRulesetRules['requiredStatusChecks'] {
if (!checks) return;
return { requiredChecks: checks };
}