Skip to content

Commit

Permalink
feat(codebuild): add support for setting the gitCloneDepth property o…
Browse files Browse the repository at this point in the history
…n Project sources. (#1798)

Also fixed the weird casing of the 'GitHubEnterPrise' SourceType enum value while I was in the area.

Fixes #1789
  • Loading branch information
skinny85 authored and Elad Ben-Israel committed Feb 26, 2019
1 parent d14123c commit 0d4a4fb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
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 {
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 {
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',
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

0 comments on commit 0d4a4fb

Please sign in to comment.