Skip to content

Commit 8c15b5f

Browse files
authored
feat(codebuild): add support of organization webhook in github source (#31740)
### Issue # (if applicable) closes #31736 ### Reason for this change Currently, the AWS CDK `aws-codebuild` module lacks native support for creating GitHub organization-level webhooks through the `Source` construct. Users need to manually use the `CfnProject` to enable organization webhooks, which adds complexity and inconsistency to the CodeBuild setup. This PR introduces support for creating GitHub organization webhooks directly within the `Source` construct, streamlining the experience and making it more consistent with the rest of the AWS CDK's high-level constructs. ### Description of changes - Enhanced the `GitHubSource` construct in the `aws-codebuild` module to support GitHub organization webhooks. - Updated the `GitHubSource` construct's configuration to so when repo is not specified an organization webhook is created. - Added filter of `REPOSITORY_NAME` to FilterGroups. ### Description of how you validated changes - [x] Added unit tests to validate that organization-level webhooks are created correctly when repo is not specified. - [x] Ran integration tests to ensure that the changes do not break any existing functionality related to project webhooks. - [x] Tested deployment of a CodeBuild project with organization webhook setup in a sample CDK application to verify end-to-end functionality. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 046f041 commit 8c15b5f

12 files changed

+866
-8
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.github-org-webhook.js.snapshot/cdk.out

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.github-org-webhook.js.snapshot/codebuild-github-org-webhook.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
{
2+
"Resources": {
3+
"MyProjectRole9BBE5233": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "codebuild.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
}
18+
}
19+
},
20+
"MyProjectRoleDefaultPolicyB19B7C29": {
21+
"Type": "AWS::IAM::Policy",
22+
"Properties": {
23+
"PolicyDocument": {
24+
"Statement": [
25+
{
26+
"Action": [
27+
"logs:CreateLogGroup",
28+
"logs:CreateLogStream",
29+
"logs:PutLogEvents"
30+
],
31+
"Effect": "Allow",
32+
"Resource": [
33+
{
34+
"Fn::Join": [
35+
"",
36+
[
37+
"arn:",
38+
{
39+
"Ref": "AWS::Partition"
40+
},
41+
":logs:",
42+
{
43+
"Ref": "AWS::Region"
44+
},
45+
":",
46+
{
47+
"Ref": "AWS::AccountId"
48+
},
49+
":log-group:/aws/codebuild/",
50+
{
51+
"Ref": "MyProject39F7B0AE"
52+
},
53+
":*"
54+
]
55+
]
56+
},
57+
{
58+
"Fn::Join": [
59+
"",
60+
[
61+
"arn:",
62+
{
63+
"Ref": "AWS::Partition"
64+
},
65+
":logs:",
66+
{
67+
"Ref": "AWS::Region"
68+
},
69+
":",
70+
{
71+
"Ref": "AWS::AccountId"
72+
},
73+
":log-group:/aws/codebuild/",
74+
{
75+
"Ref": "MyProject39F7B0AE"
76+
}
77+
]
78+
]
79+
}
80+
]
81+
}
82+
],
83+
"Version": "2012-10-17"
84+
},
85+
"PolicyName": "MyProjectRoleDefaultPolicyB19B7C29",
86+
"Roles": [
87+
{
88+
"Ref": "MyProjectRole9BBE5233"
89+
}
90+
]
91+
}
92+
},
93+
"MyProject39F7B0AE": {
94+
"Type": "AWS::CodeBuild::Project",
95+
"Properties": {
96+
"Artifacts": {
97+
"Type": "NO_ARTIFACTS"
98+
},
99+
"Cache": {
100+
"Type": "NO_CACHE"
101+
},
102+
"EncryptionKey": "alias/aws/s3",
103+
"Environment": {
104+
"ComputeType": "BUILD_GENERAL1_SMALL",
105+
"Image": "aws/codebuild/standard:7.0",
106+
"ImagePullCredentialsType": "CODEBUILD",
107+
"PrivilegedMode": false,
108+
"Type": "LINUX_CONTAINER"
109+
},
110+
"ServiceRole": {
111+
"Fn::GetAtt": [
112+
"MyProjectRole9BBE5233",
113+
"Arn"
114+
]
115+
},
116+
"Source": {
117+
"Location": "CODEBUILD_DEFAULT_WEBHOOK_SOURCE_LOCATION",
118+
"ReportBuildStatus": false,
119+
"Type": "GITHUB"
120+
},
121+
"Triggers": {
122+
"FilterGroups": [
123+
[
124+
{
125+
"Pattern": "WORKFLOW_JOB_QUEUED",
126+
"Type": "EVENT"
127+
},
128+
{
129+
"Pattern": "aws-cdk.*",
130+
"Type": "REPOSITORY_NAME"
131+
},
132+
{
133+
"ExcludeMatchedPattern": true,
134+
"Pattern": "aws-cdk-lib",
135+
"Type": "REPOSITORY_NAME"
136+
}
137+
]
138+
],
139+
"ScopeConfiguration": {
140+
"Name": "aws"
141+
},
142+
"Webhook": true
143+
}
144+
}
145+
}
146+
},
147+
"Parameters": {
148+
"BootstrapVersion": {
149+
"Type": "AWS::SSM::Parameter::Value<String>",
150+
"Default": "/cdk-bootstrap/hnb659fds/version",
151+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
152+
}
153+
},
154+
"Rules": {
155+
"CheckBootstrapVersion": {
156+
"Assertions": [
157+
{
158+
"Assert": {
159+
"Fn::Not": [
160+
{
161+
"Fn::Contains": [
162+
[
163+
"1",
164+
"2",
165+
"3",
166+
"4",
167+
"5"
168+
],
169+
{
170+
"Ref": "BootstrapVersion"
171+
}
172+
]
173+
}
174+
]
175+
},
176+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
177+
}
178+
]
179+
}
180+
}
181+
}

packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.github-org-webhook.js.snapshot/codebuildgithuborgwebhookintegDefaultTestDeployAssertB287C481.assets.json

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.github-org-webhook.js.snapshot/codebuildgithuborgwebhookintegDefaultTestDeployAssertB287C481.template.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-codebuild/test/integ.github-org-webhook.js.snapshot/integ.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)