Skip to content

Commit ad0fe0b

Browse files
committed
Add CodeCommit PR commenting to CloudFormation template
1 parent cf25693 commit ad0fe0b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

cloudformation/continuous-integration-pull-request-checks.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
AWSTemplateFormatVersion: 2010-09-09
2+
Transform: 'AWS::Serverless-2016-10-31'
23

34
Description: Perform continuous integration pull request checks on a CodeCommit repository with CodeBuild
45

@@ -196,3 +197,45 @@ Resources:
196197
- - !Ref 'AWS::StackName'
197198
- CodeBuild
198199
Type: AWS::IAM::Role
200+
201+
PullRequestBuildComments:
202+
Type: 'AWS::Serverless::Function'
203+
Properties:
204+
Handler: codecommit_pr_notifications.handler
205+
Runtime: nodejs8.10
206+
CodeUri: ../ci_tools
207+
Description: >-
208+
Comment on the CodeCommit pull request when a build is triggered and when it completes
209+
Policies:
210+
- AWSLambdaBasicExecutionRole
211+
- Version: '2012-10-17'
212+
Statement:
213+
- Effect: Allow
214+
Action:
215+
- codecommit:PostCommentForPullRequest
216+
Resource:
217+
- !Join
218+
- ':'
219+
- - arn
220+
- aws
221+
- codecommit
222+
- !Ref 'AWS::Region'
223+
- !Ref 'AWS::AccountId'
224+
- !Ref CodeCommitRepoName
225+
- Effect: Allow
226+
Action:
227+
- logs:GetLogEvents
228+
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/*"
229+
Events:
230+
BuildTrigger:
231+
Type: CloudWatchEvent
232+
Properties:
233+
Pattern:
234+
source:
235+
- aws.codebuild
236+
detail-type:
237+
- CodeBuild Build State Change
238+
detail:
239+
additional-information:
240+
initiator:
241+
- !Sub "rule/${SourceEvent}"

0 commit comments

Comments
 (0)