File tree 4 files changed +58
-0
lines changed
packages/@aws-cdk/aws-codebuild
4 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,18 @@ CodePipeline action.
84
84
#### ` GitHubSource ` and ` GitHubEnterpriseSource `
85
85
86
86
These source types can be used to build code from a GitHub repository.
87
+ Example:
88
+
89
+ ``` typescript
90
+ const gitHubSource = new codebuild .GitHubSource ({
91
+ owner: ' awslabs' ,
92
+ repo: ' aws-cdk' ,
93
+ oauthToken: new cdk .SecretParameter (this , ' GitHubOAuthToken' , {
94
+ ssmParameter: ' my-github-token' ,
95
+ }),
96
+ webhook: true , // optional, default: false
97
+ });
98
+ ```
87
99
88
100
#### ` BitBucketSource `
89
101
Original file line number Diff line number Diff line change @@ -562,6 +562,7 @@ export class Project extends ProjectRef {
562
562
timeoutInMinutes : props . timeout ,
563
563
secondarySources : new cdk . Token ( ( ) => this . renderSecondarySources ( ) ) ,
564
564
secondaryArtifacts : new cdk . Token ( ( ) => this . renderSecondaryArtifacts ( ) ) ,
565
+ triggers : this . source . buildTriggers ( ) ,
565
566
} ) ;
566
567
567
568
this . projectArn = resource . projectArn ;
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ export abstract class BuildSource {
46
46
} ;
47
47
}
48
48
49
+ public buildTriggers ( ) : CfnProject . ProjectTriggersProperty | undefined {
50
+ return undefined ;
51
+ }
52
+
49
53
protected toSourceProperty ( ) : any {
50
54
return {
51
55
} ;
@@ -171,6 +175,13 @@ export interface GitHubSourceProps extends BuildSourceProps {
171
175
*/
172
176
oauthToken : cdk . Secret ;
173
177
178
+ /**
179
+ * Whether to create a webhook that will trigger a build every time a commit is pushed to the GitHub repository.
180
+ *
181
+ * @default false
182
+ */
183
+ webhook ?: boolean ;
184
+
174
185
/**
175
186
* Whether to send GitHub notifications on your build's start and end.
176
187
*
@@ -187,14 +198,24 @@ export class GitHubSource extends BuildSource {
187
198
private readonly httpsCloneUrl : string ;
188
199
private readonly oauthToken : cdk . Secret ;
189
200
private readonly reportBuildStatus : boolean ;
201
+ private readonly webhook ?: boolean ;
190
202
191
203
constructor ( props : GitHubSourceProps ) {
192
204
super ( props ) ;
193
205
this . httpsCloneUrl = `https://github.com/${ props . owner } /${ props . repo } .git` ;
194
206
this . oauthToken = props . oauthToken ;
207
+ this . webhook = props . webhook ;
195
208
this . reportBuildStatus = props . reportBuildStatus === undefined ? true : props . reportBuildStatus ;
196
209
}
197
210
211
+ public buildTriggers ( ) : CfnProject . ProjectTriggersProperty | undefined {
212
+ return this . webhook === undefined
213
+ ? undefined
214
+ : {
215
+ webhook : this . webhook ,
216
+ } ;
217
+ }
218
+
198
219
protected toSourceProperty ( ) : any {
199
220
return {
200
221
auth : { type : 'OAUTH' , resource : this . oauthToken } ,
Original file line number Diff line number Diff line change @@ -100,6 +100,30 @@ export = {
100
100
101
101
test . done ( ) ;
102
102
} ,
103
+
104
+ 'can explicitly set webhook to true' ( test : Test ) {
105
+ // GIVEN
106
+ const stack = new cdk . Stack ( ) ;
107
+
108
+ // WHEN
109
+ new codebuild . Project ( stack , 'Project' , {
110
+ source : new codebuild . GitHubSource ( {
111
+ owner : 'testowner' ,
112
+ repo : 'testrepo' ,
113
+ oauthToken : new cdk . Secret ( 'test_oauth_token' ) ,
114
+ webhook : true ,
115
+ } )
116
+ } ) ;
117
+
118
+ // THEN
119
+ expect ( stack ) . to ( haveResourceLike ( 'AWS::CodeBuild::Project' , {
120
+ Triggers : {
121
+ Webhook : true ,
122
+ } ,
123
+ } ) ) ;
124
+
125
+ test . done ( ) ;
126
+ } ,
103
127
} ,
104
128
105
129
'github enterprise auth test' ( test : Test ) {
You can’t perform that action at this time.
0 commit comments