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

feat(codebuild): add support for setting the gitCloneDepth property on Project sources #1798

Merged
merged 1 commit into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 41 additions & 10 deletions packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,48 @@ export class NoSource extends BuildSource {
}
}

/**
* The construction properties common to all build sources that are backed by Git.
*/
export interface GitBuildSourceProps extends BuildSourceProps {
/**
* The depth of history to download. Minimum value is 0.
* If this value is 0, greater than 25, or not provided,
* then the full history is downloaded with each build of the project.
*/
cloneDepth?: number;
}

/**
* A common superclass of all build sources that are backed by Git.
*/
export abstract class GitBuildSource extends BuildSource {
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 this is an example of over-modeling. Now what happens if we have another Git source that's not in the codebuild package, then what...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I was so proud of how I DRYied it up... 😭

What alternative would you propose here Elad?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just duplicate. Sometimes it's too DRY

Copy link
Contributor

Choose a reason for hiding this comment

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

But I am okay with this too :-D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't. I can't bear myself to copy & paste cloneDepth after I've so beautifully applied inheritance and the Decorator pattern here. My object-oriented programming education forbids me.

I'll leave this as is for now, feel free to open a separate PR changing this behind my back 😃

private readonly cloneDepth?: number;

protected constructor(props: GitBuildSourceProps) {
super(props);

this.cloneDepth = props.cloneDepth;
}

public toSourceJSON(): CfnProject.SourceProperty {
const ret = super.toSourceJSON();
ret.gitCloneDepth = this.cloneDepth;
return ret;
}
}

/**
* Construction properties for {@link CodeCommitSource}.
*/
export interface CodeCommitSourceProps extends BuildSourceProps {
export interface CodeCommitSourceProps extends GitBuildSourceProps {
repository: codecommit.IRepository;
}

/**
* CodeCommit Source definition for a CodeBuild project.
*/
export class CodeCommitSource extends BuildSource {
export class CodeCommitSource extends GitBuildSource {
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, based on our discussions around #1743, this class should technically be in CodeCommit...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're probably right, but that seems like a separate change.

public readonly type: SourceType = SourceType.CodeCommit;
private readonly repo: codecommit.IRepository;

Expand Down Expand Up @@ -153,7 +184,7 @@ export class CodePipelineSource extends BuildSource {
/**
* Construction properties for {@link GitHubSource} and {@link GitHubEnterpriseSource}.
*/
export interface GitHubSourceProps extends BuildSourceProps {
export interface GitHubSourceProps extends GitBuildSourceProps {
/**
* The GitHub account/user that owns the repo.
*
Expand Down Expand Up @@ -193,7 +224,7 @@ export interface GitHubSourceProps extends BuildSourceProps {
/**
* GitHub Source definition for a CodeBuild project.
*/
export class GitHubSource extends BuildSource {
export class GitHubSource extends GitBuildSource {
public readonly type: SourceType = SourceType.GitHub;
private readonly httpsCloneUrl: string;
private readonly oauthToken: cdk.Secret;
Expand Down Expand Up @@ -228,7 +259,7 @@ export class GitHubSource extends BuildSource {
/**
* Construction properties for {@link GitHubEnterpriseSource}.
*/
export interface GitHubEnterpriseSourceProps extends BuildSourceProps {
export interface GitHubEnterpriseSourceProps extends GitBuildSourceProps {
/**
* The HTTPS URL of the repository in your GitHub Enterprise installation.
*/
Expand All @@ -250,8 +281,8 @@ export interface GitHubEnterpriseSourceProps extends BuildSourceProps {
/**
* GitHub Enterprise Source definition for a CodeBuild project.
*/
export class GitHubEnterpriseSource extends BuildSource {
public readonly type: SourceType = SourceType.GitHubEnterPrise;
export class GitHubEnterpriseSource extends GitBuildSource {
public readonly type: SourceType = SourceType.GitHubEnterprise;
private readonly httpsCloneUrl: string;
private readonly oauthToken: cdk.Secret;
private readonly ignoreSslErrors?: boolean;
Expand All @@ -275,7 +306,7 @@ export class GitHubEnterpriseSource extends BuildSource {
/**
* Construction properties for {@link BitBucketSource}.
*/
export interface BitBucketSourceProps extends BuildSourceProps {
export interface BitBucketSourceProps extends GitBuildSourceProps {
/**
* The BitBucket account/user that owns the repo.
*
Expand All @@ -294,7 +325,7 @@ export interface BitBucketSourceProps extends BuildSourceProps {
/**
* BitBucket Source definition for a CodeBuild project.
*/
export class BitBucketSource extends BuildSource {
export class BitBucketSource extends GitBuildSource {
public readonly type: SourceType = SourceType.BitBucket;
private readonly httpsCloneUrl: any;

Expand All @@ -318,7 +349,7 @@ export enum SourceType {
CodeCommit = 'CODECOMMIT',
CodePipeline = 'CODEPIPELINE',
GitHub = 'GITHUB',
GitHubEnterPrise = 'GITHUB_ENTERPRISE',
Copy link
Contributor

Choose a reason for hiding this comment

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

LOLx

GitHubEnterprise = 'GITHUB_ENTERPRISE',
BitBucket = 'BITBUCKET',
S3 = 'S3',
}
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export = {

const repo = new codecommit.Repository(stack, 'MyRepo', { repositoryName: 'hello-cdk' });

const source = new codebuild.CodeCommitSource({ repository: repo });
const source = new codebuild.CodeCommitSource({ repository: repo, cloneDepth: 2 });

new codebuild.Project(stack, 'MyProject', {
source
Expand Down Expand Up @@ -282,6 +282,7 @@ export = {
"CloneUrlHttp"
]
},
"GitCloneDepth": 2,
"Type": "CODECOMMIT"
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-codebuild/test/test.project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export = {
source: new codebuild.GitHubSource({
owner: 'testowner',
repo: 'testrepo',
cloneDepth: 3,
oauthToken: new cdk.Secret("test_oauth_token")
})
});
Expand All @@ -71,6 +72,7 @@ export = {
},
Location: 'https://github.com/testowner/testrepo.git',
ReportBuildStatus: true,
GitCloneDepth: 3,
}
}));

Expand Down Expand Up @@ -135,6 +137,7 @@ export = {
source: new codebuild.GitHubEnterpriseSource({
httpsCloneUrl: 'https://github.testcompany.com/testowner/testrepo',
ignoreSslErrors: true,
cloneDepth: 4,
oauthToken: new cdk.Secret("test_oauth_token")
})
});
Expand All @@ -148,6 +151,7 @@ export = {
Resource: 'test_oauth_token'
},
InsecureSsl: true,
GitCloneDepth: 4,
Location: 'https://github.testcompany.com/testowner/testrepo'
}
}));
Expand All @@ -164,6 +168,7 @@ export = {
source: new codebuild.BitBucketSource({
owner: 'testowner',
repo: 'testrepo',
cloneDepth: 5,
})
});

Expand All @@ -172,6 +177,7 @@ export = {
Source: {
Type: 'BITBUCKET',
Location: 'https://bitbucket.org/testowner/testrepo.git',
GitCloneDepth: 5,
},
}));

Expand Down