Skip to content

Commit

Permalink
fix(codebuild): badge is not allowed for CodeCommit sources (#6211)
Browse files Browse the repository at this point in the history
We used to validate that having a badge was forbidden with CodeCommit sources.
CodeBuild has since lifted that restriction, so we need to remove that validation.

Fixes #6205

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
skinny85 and mergify[bot] authored Feb 12, 2020
1 parent 6dbc0b1 commit 433d957
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ export interface CodeCommitSourceProps extends GitSourceProps {
* CodeCommit Source definition for a CodeBuild project.
*/
class CodeCommitSource extends GitSource {
public readonly badgeSupported = true;
public readonly type = CODECOMMIT_SOURCE_TYPE;
private readonly repo: codecommit.IRepository;

Expand Down
22 changes: 11 additions & 11 deletions packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ export = {

interface BadgeValidationTestCase {
source: codebuild.Source,
shouldPassValidation: boolean
allowsBadge: boolean
}

const repo = new codecommit.Repository(stack, 'MyRepo', {
Expand All @@ -1378,22 +1378,22 @@ export = {
const bucket = new s3.Bucket(stack, 'MyBucket');

const cases: BadgeValidationTestCase[] = [
{ source: new NoSource(), shouldPassValidation: false },
{ source: new CodePipelineSource(), shouldPassValidation: false },
{ source: codebuild.Source.codeCommit({ repository: repo }), shouldPassValidation: false },
{ source: codebuild.Source.s3({ bucket, path: 'path/to/source.zip' }), shouldPassValidation: false },
{ source: codebuild.Source.gitHub({ owner: 'awslabs', repo: 'aws-cdk' }), shouldPassValidation: true },
{ source: codebuild.Source.gitHubEnterprise({ httpsCloneUrl: 'url' }), shouldPassValidation: true },
{ source: codebuild.Source.bitBucket({ owner: 'awslabs', repo: 'aws-cdk' }), shouldPassValidation: true }
{ source: new NoSource(), allowsBadge: false },
{ source: new CodePipelineSource(), allowsBadge: false },
{ source: codebuild.Source.codeCommit({ repository: repo }), allowsBadge: true },
{ source: codebuild.Source.s3({ bucket, path: 'path/to/source.zip' }), allowsBadge: false },
{ source: codebuild.Source.gitHub({ owner: 'awslabs', repo: 'aws-cdk' }), allowsBadge: true },
{ source: codebuild.Source.gitHubEnterprise({ httpsCloneUrl: 'url' }), allowsBadge: true },
{ source: codebuild.Source.bitBucket({ owner: 'awslabs', repo: 'aws-cdk' }), allowsBadge: true },
];

cases.forEach(testCase => {
const source = testCase.source;
const validationBlock = () => { new codebuild.Project(stack, `MyProject-${source.type}`, { source, badge: true }); };
if (testCase.shouldPassValidation) {
test.doesNotThrow(validationBlock, Error, `Badge is not supported for source type ${source.type}`);
if (testCase.allowsBadge) {
test.doesNotThrow(validationBlock);
} else {
test.throws(validationBlock, Error, `Badge is not supported for source type ${source.type}`);
test.throws(validationBlock, /Badge is not supported for source type /);
}
});

Expand Down

0 comments on commit 433d957

Please sign in to comment.