Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codepipeline): manual approval action doesn't have configuration without a topic #6106

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' });
}