Skip to content

Commit

Permalink
Implement requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderKnape committed Apr 23, 2019
1 parent 7f60617 commit 1d8310f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 106 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/app-delivery/test/integ.cicd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const source = new cpactions.GitHubSourceAction({
owner: 'awslabs',
repo: 'aws-cdk',
oauthToken: cdk.SecretValue.plainText('DummyToken'),
trigger: cpactions.TriggerType.Poll,
outputArtifactName: 'Artifact_CICDGitHubF8BA7ADD',
trigger: cpactions.GitHubTrigger.Poll,
output: sourceOutput,
});
pipeline.addStage({
name: 'Source',
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codepipeline-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const sourceAction = new codepipeline_actions.GitHubSourceAction({
oauthToken: token.value,
output: sourceOutput,
branch: 'develop', // default: 'master'
trigger: codepipeline_actions.TriggerType.Poll // default: 'WebHook', 'None' is also possible for no Source trigger
trigger: codepipeline_actions.GitHubTrigger.Poll // default: 'WebHook', 'None' is also possible for no Source trigger
});
pipeline.addStage({
name: 'Source',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import codepipeline = require('@aws-cdk/aws-codepipeline');
import { SecretValue } from '@aws-cdk/cdk';
import { sourceArtifactBounds } from '../common';

export enum TriggerType {
/**
* If and how the GitHub source action should be triggered
*/
export enum GitHubTrigger {
None = 'None',
Poll = 'Poll',
WebHook = 'WebHook',
Expand Down Expand Up @@ -47,9 +50,13 @@ export interface GitHubSourceActionProps extends codepipeline.CommonActionProps
/**
* How AWS CodePipeline should be triggered
*
* @default "WebHook"
* With the default value "WebHook", a webhook is created in GitHub that triggers the action
* With "Poll", CodePipeline periodically checks the source for changes
* With "None", the action is not triggered through changes in the source
*
* @default GitHubTrigger.WebHook
*/
readonly trigger?: TriggerType;
readonly trigger?: GitHubTrigger;
}

/**
Expand All @@ -71,15 +78,15 @@ export class GitHubSourceAction extends codepipeline.Action {
Repo: props.repo,
Branch: props.branch || "master",
OAuthToken: props.oauthToken.toString(),
PollForSourceChanges: (props.trigger && props.trigger === TriggerType.Poll) || false,
PollForSourceChanges: props.trigger === GitHubTrigger.Poll,
},
});

this.props = props;
}

protected bind(info: codepipeline.ActionBind): void {
if (!this.props.trigger || this.props.trigger === TriggerType.WebHook) {
if (!this.props.trigger || this.props.trigger === GitHubTrigger.WebHook) {
new codepipeline.CfnWebhook(info.scope, 'WebhookResource', {
authentication: 'GITHUB_HMAC',
authenticationConfiguration: {
Expand Down
116 changes: 18 additions & 98 deletions packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ export = {
new cpactions.GitHubSourceAction({
actionName: 'GH',
runOrder: 8,
outputArtifactName: 'A',
output: new codepipeline.Artifact('A'),
branch: 'branch',
oauthToken: SecretValue.plainText(secret.stringValue),
owner: 'foo',
repo: 'bar',
trigger: cpactions.TriggerType.Poll
trigger: cpactions.GitHubTrigger.Poll
}),
],
});
Expand All @@ -100,63 +100,23 @@ export = {
expect(stack).to(not(haveResourceLike('AWS::CodePipeline::Webhook')));

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
"ArtifactStore": {
"Location": {
"Ref": "PArtifactsBucket5E711C12"
},
"Type": "S3"
},
"RoleArn": {
"Fn::GetAtt": [
"PRole07BDC907",
"Arn"
]
},
"Stages": [
{
"Actions": [
{
"ActionTypeId": {
"Category": "Source",
"Owner": "ThirdParty",
"Provider": "GitHub",
"Version": "1"
},
"Configuration": {
"Owner": "foo",
"Repo": "bar",
"Branch": "branch",
"OAuthToken": {
"Ref": "GitHubToken"
},
"PollForSourceChanges": true
},
"InputArtifacts": [],
"Name": "GH",
"OutputArtifacts": [
{
"Name": "A"
"Configuration": {
"PollForSourceChanges": true
},
"Name": "GH"
}
],
"RunOrder": 8
}
],
"Name": "Source"
},
{
"Actions": [
{
"ActionTypeId": {
"Category": "Approval",
"Owner": "AWS",
"Provider": "Manual",
"Version": "1"
},
"InputArtifacts": [],
"Name": "Boo",
"OutputArtifacts": [],
"RunOrder": 1
}
{
"Name": "Boo",
}
],
"Name": "Two"
}
Expand All @@ -179,12 +139,12 @@ export = {
new cpactions.GitHubSourceAction({
actionName: 'GH',
runOrder: 8,
outputArtifactName: 'A',
output: new codepipeline.Artifact('A'),
branch: 'branch',
oauthToken: SecretValue.plainText(secret.stringValue),
owner: 'foo',
repo: 'bar',
trigger: cpactions.TriggerType.None
trigger: cpactions.GitHubTrigger.None
}),
],
});
Expand All @@ -199,63 +159,23 @@ export = {
expect(stack).to(not(haveResourceLike('AWS::CodePipeline::Webhook')));

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
"ArtifactStore": {
"Location": {
"Ref": "PArtifactsBucket5E711C12"
},
"Type": "S3"
},
"RoleArn": {
"Fn::GetAtt": [
"PRole07BDC907",
"Arn"
]
},
"Stages": [
{
"Actions": [
{
"ActionTypeId": {
"Category": "Source",
"Owner": "ThirdParty",
"Provider": "GitHub",
"Version": "1"
},
"Configuration": {
"Owner": "foo",
"Repo": "bar",
"Branch": "branch",
"OAuthToken": {
"Ref": "GitHubToken"
},
"PollForSourceChanges": false
},
"InputArtifacts": [],
"Name": "GH",
"OutputArtifacts": [
{
"Name": "A"
"Configuration": {
"PollForSourceChanges": false
},
"Name": "GH"
}
],
"RunOrder": 8
}
],
"Name": "Source"
},
{
"Actions": [
{
"ActionTypeId": {
"Category": "Approval",
"Owner": "AWS",
"Provider": "Manual",
"Version": "1"
},
"InputArtifacts": [],
"Name": "Boo",
"OutputArtifacts": [],
"RunOrder": 1
}
{
"Name": "Boo",
}
],
"Name": "Two"
}
Expand Down

0 comments on commit 1d8310f

Please sign in to comment.