Skip to content

Commit

Permalink
fix(codepipeline): manual approval action doesn't have configuration …
Browse files Browse the repository at this point in the history
…without a topic (#6106)

We were only rendering the CustomData and ExternalEntityLink configuration properties for the manual approval action if a notification SNS topic was either created or passed when instantiating the action.
This is a mistake, as those properties make sense even when the action doesn't publish anything to a topic.

Fixes #6100

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
skinny85 and mergify[bot] authored Feb 5, 2020
1 parent 15b6aa7 commit a63cbf8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ export class ManualApprovalAction extends Action {
}

return {
configuration: this._notificationTopic
? {
NotificationArn: this._notificationTopic.topicArn,
CustomData: this.props.additionalInformation,
ExternalEntityLink: this.props.externalEntityLink,
}
: undefined,
configuration: undefinedIfAllValuesAreEmpty({
NotificationArn: this._notificationTopic?.topicArn,
CustomData: this.props.additionalInformation,
ExternalEntityLink: this.props.externalEntityLink,
}),
};
}
}

function undefinedIfAllValuesAreEmpty(object: object): object | undefined {
return Object.values(object).some(v => v !== undefined) ? object : undefined;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { expect, haveResourceLike} from '@aws-cdk/assert';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as sns from '@aws-cdk/aws-sns';
import { SecretValue, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import * as cpactions from '../lib';

// tslint:disable:object-literal-key-quotes

export = {
'manual approval Action': {
'allows passing an SNS Topic when constructing it'(test: Test) {
const stack = new Stack();
const topic = new sns.Topic(stack, 'Topic');
const manualApprovalAction = new cpactions.ManualApprovalAction({
actionName: 'Approve',
notificationTopic: topic,
});
const pipeline = new codepipeline.Pipeline(stack, 'pipeline');
const stage = pipeline.addStage({ stageName: 'stage' });
stage.addAction(manualApprovalAction);

test.equal(manualApprovalAction.notificationTopic, topic);

test.done();
},

'renders CustomData and ExternalEntityLink even if notificationTopic was not passed'(test: Test) {
const stack = new Stack();
new codepipeline.Pipeline(stack, 'pipeline', {
stages: [
{
stageName: 'Source',
actions: [new cpactions.GitHubSourceAction({
actionName: 'Source',
output: new codepipeline.Artifact(),
oauthToken: SecretValue.plainText('secret'),
owner: 'aws',
repo: 'aws-cdk',
})],
},
{
stageName: 'Approve',
actions: [
new cpactions.ManualApprovalAction({
actionName: 'Approval',
additionalInformation: 'extra info',
externalEntityLink: 'external link',
}),
],
},
],
});

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
"Stages": [
{
"Name": "Source",
},
{
"Name": "Approve",
"Actions": [
{
"Name": "Approval",
"Configuration": {
"CustomData": "extra info",
"ExternalEntityLink": "external link",
},
},
],
},
],
}));

test.done();
},
},
};
21 changes: 0 additions & 21 deletions packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,6 @@ export = {
test.done();
},

'manual approval Action': {
'allows passing an SNS Topic when constructing it'(test: Test) {
const stack = new Stack();
const topic = new sns.Topic(stack, 'Topic');
const manualApprovalAction = new cpactions.ManualApprovalAction({
actionName: 'Approve',
notificationTopic: topic,
});
stageForTesting(stack).addAction(manualApprovalAction);

test.equal(manualApprovalAction.notificationTopic, topic);

test.done();
},
},

'PipelineProject': {
'with a custom Project Name': {
'sets the source and artifacts to CodePipeline'(test: Test) {
Expand Down Expand Up @@ -977,8 +961,3 @@ export = {
},
},
};

function stageForTesting(stack: Stack): codepipeline.IStage {
const pipeline = new codepipeline.Pipeline(stack, 'pipeline');
return pipeline.addStage({ stageName: 'stage' });
}

0 comments on commit a63cbf8

Please sign in to comment.