@@ -4,6 +4,29 @@ import targets = require('@aws-cdk/aws-events-targets');
4
4
import iam = require( '@aws-cdk/aws-iam' ) ;
5
5
import { sourceArtifactBounds } from '../common' ;
6
6
7
+ /**
8
+ * How should the CodeCommit Action detect changes.
9
+ * This is the type of the {@link CodeCommitSourceAction.trigger} property.
10
+ */
11
+ export enum CodeCommitTrigger {
12
+ /**
13
+ * The Action will never detect changes -
14
+ * the Pipeline it's part of will only begin a run when explicitly started.
15
+ */
16
+ NONE = 'None' ,
17
+
18
+ /**
19
+ * CodePipeline will poll the repository to detect changes.
20
+ */
21
+ POLL = 'Poll' ,
22
+
23
+ /**
24
+ * CodePipeline will use CloudWatch Events to be notified of changes.
25
+ * This is the default method of detecting changes.
26
+ */
27
+ EVENTS = 'Events' ,
28
+ }
29
+
7
30
/**
8
31
* Construction properties of the {@link CodeCommitSourceAction CodeCommit source CodePipeline Action}.
9
32
*/
@@ -19,12 +42,11 @@ export interface CodeCommitSourceActionProps extends codepipeline.CommonActionPr
19
42
readonly branch ?: string ;
20
43
21
44
/**
22
- * Whether AWS CodePipeline should poll for source changes.
23
- * If this is `false`, the Pipeline will use CloudWatch Events to detect source changes instead.
45
+ * How should CodePipeline detect source changes for this Action.
24
46
*
25
- * @default false
47
+ * @default CodeCommitTrigger.EVENTS
26
48
*/
27
- readonly pollForSourceChanges ?: boolean ;
49
+ readonly trigger ?: CodeCommitTrigger ;
28
50
29
51
/**
30
52
* The CodeCommit repository.
@@ -36,9 +58,13 @@ export interface CodeCommitSourceActionProps extends codepipeline.CommonActionPr
36
58
* CodePipeline Source that is provided by an AWS CodeCommit repository.
37
59
*/
38
60
export class CodeCommitSourceAction extends codepipeline . Action {
39
- private readonly props : CodeCommitSourceActionProps ;
61
+ private readonly repository : codecommit . IRepository ;
62
+ private readonly branch : string ;
63
+ private readonly createEvent : boolean ;
40
64
41
65
constructor ( props : CodeCommitSourceActionProps ) {
66
+ const branch = props . branch || 'master' ;
67
+
42
68
super ( {
43
69
...props ,
44
70
category : codepipeline . ActionCategory . SOURCE ,
@@ -47,34 +73,35 @@ export class CodeCommitSourceAction extends codepipeline.Action {
47
73
outputs : [ props . output ] ,
48
74
configuration : {
49
75
RepositoryName : props . repository . repositoryName ,
50
- BranchName : props . branch || 'master' ,
51
- PollForSourceChanges : props . pollForSourceChanges || false ,
76
+ BranchName : branch ,
77
+ PollForSourceChanges : props . trigger === CodeCommitTrigger . POLL ,
52
78
} ,
53
79
} ) ;
54
80
55
- this . props = props ;
81
+ this . repository = props . repository ;
82
+ this . branch = branch ;
83
+ this . createEvent = props . trigger === undefined ||
84
+ props . trigger === CodeCommitTrigger . EVENTS ;
56
85
}
57
86
58
87
protected bind ( info : codepipeline . ActionBind ) : void {
59
- if ( ! this . props . pollForSourceChanges ) {
60
- this . props . repository . onCommit ( info . pipeline . node . uniqueId + 'EventRule' , {
88
+ if ( this . createEvent ) {
89
+ this . repository . onCommit ( info . pipeline . node . uniqueId + 'EventRule' , {
61
90
target : new targets . CodePipeline ( info . pipeline ) ,
62
- branches : [ this . props . branch || 'master' ]
91
+ branches : [ this . branch ] ,
63
92
} ) ;
64
93
}
65
94
66
95
// https://docs.aws.amazon.com/codecommit/latest/userguide/auth-and-access-control-permissions-reference.html#aa-acp
67
- const actions = [
68
- 'codecommit:GetBranch' ,
69
- 'codecommit:GetCommit' ,
70
- 'codecommit:UploadArchive' ,
71
- 'codecommit:GetUploadArchiveStatus' ,
72
- 'codecommit:CancelUploadArchive' ,
73
- ] ;
74
-
75
96
info . role . addToPolicy ( new iam . PolicyStatement ( {
76
- resources : [ this . props . repository . repositoryArn ] ,
77
- actions
97
+ resources : [ this . repository . repositoryArn ] ,
98
+ actions : [
99
+ 'codecommit:GetBranch' ,
100
+ 'codecommit:GetCommit' ,
101
+ 'codecommit:UploadArchive' ,
102
+ 'codecommit:GetUploadArchiveStatus' ,
103
+ 'codecommit:CancelUploadArchive' ,
104
+ ] ,
78
105
} ) ) ;
79
106
}
80
107
}
0 commit comments