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(codebuild): add validation for source when badge is enabled #2242

Merged
merged 3 commits into from
Apr 11, 2019
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
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ export class Project extends ProjectBase {

// Render the source and add in the buildspec
const renderSource = () => {
if (props.badge && !this.source.isBadgeSupported()) {
if (props.badge && !this.source.badgeAllowed) {
throw new Error(`Badge is not supported for source type ${this.source.type}`);
}

Expand Down
15 changes: 3 additions & 12 deletions packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface BuildSourceProps {
export abstract class BuildSource {
public readonly identifier?: string;
public abstract readonly type: SourceType;
public readonly badgeAllowed: boolean = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think badgeSupported makes more sense than allowed


constructor(props: BuildSourceProps) {
this.identifier = props.identifier;
Expand Down Expand Up @@ -52,10 +53,6 @@ export abstract class BuildSource {
return undefined;
}

public isBadgeSupported(): boolean {
return false;
}

protected toSourceProperty(): any {
return {
};
Expand Down Expand Up @@ -93,6 +90,7 @@ export interface GitBuildSourceProps extends BuildSourceProps {
* A common superclass of all build sources that are backed by Git.
*/
export abstract class GitBuildSource extends BuildSource {
public readonly badgeAllowed: boolean = true;
private readonly cloneDepth?: number;

protected constructor(props: GitBuildSourceProps) {
Expand All @@ -107,10 +105,6 @@ export abstract class GitBuildSource extends BuildSource {
gitCloneDepth: this.cloneDepth
};
}

public isBadgeSupported(): boolean {
return true;
}
}

/**
Expand All @@ -125,6 +119,7 @@ export interface CodeCommitSourceProps extends GitBuildSourceProps {
*/
export class CodeCommitSource extends GitBuildSource {
public readonly type: SourceType = SourceType.CodeCommit;
public readonly badgeAllowed: boolean = false;
private readonly repo: codecommit.IRepository;

constructor(props: CodeCommitSourceProps) {
Expand All @@ -142,10 +137,6 @@ export class CodeCommitSource extends GitBuildSource {
.addResource(this.repo.repositoryArn));
}

public isBadgeSupported(): boolean {
return false;
}

protected toSourceProperty(): any {
return {
location: this.repo.repositoryCloneUrlHttp
Expand Down