From 41dbc8616de67527b4aae0cf68b3eb887b3e2287 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Tue, 19 Feb 2019 15:49:36 -0800 Subject: [PATCH] feat(codebuild): add support for setting the gitCloneDepth property on Project sources. Also fixed the weird casing of the 'GitHubEnterPrise' SourceType enum value while I was in the area. Fixes #1789 --- packages/@aws-cdk/aws-codebuild/lib/source.ts | 51 +++++++++++++++---- .../aws-codebuild/test/test.codebuild.ts | 3 +- .../aws-codebuild/test/test.project.ts | 6 +++ 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/packages/@aws-cdk/aws-codebuild/lib/source.ts b/packages/@aws-cdk/aws-codebuild/lib/source.ts index c0ff41efb3a43..add210773f4d5 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/source.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/source.ts @@ -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; @@ -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. * @@ -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; @@ -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. */ @@ -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; @@ -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. * @@ -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; @@ -318,7 +349,7 @@ export enum SourceType { CodeCommit = 'CODECOMMIT', CodePipeline = 'CODEPIPELINE', GitHub = 'GITHUB', - GitHubEnterPrise = 'GITHUB_ENTERPRISE', + GitHubEnterprise = 'GITHUB_ENTERPRISE', BitBucket = 'BITBUCKET', S3 = 'S3', } diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index f4a58d9d7d40e..2d876302d72ba 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -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 @@ -282,6 +282,7 @@ export = { "CloneUrlHttp" ] }, + "GitCloneDepth": 2, "Type": "CODECOMMIT" } } diff --git a/packages/@aws-cdk/aws-codebuild/test/test.project.ts b/packages/@aws-cdk/aws-codebuild/test/test.project.ts index 99208dbd797a1..83622ca99df28 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.project.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.project.ts @@ -57,6 +57,7 @@ export = { source: new codebuild.GitHubSource({ owner: 'testowner', repo: 'testrepo', + cloneDepth: 3, oauthToken: new cdk.Secret("test_oauth_token") }) }); @@ -71,6 +72,7 @@ export = { }, Location: 'https://github.com/testowner/testrepo.git', ReportBuildStatus: true, + GitCloneDepth: 3, } })); @@ -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") }) }); @@ -148,6 +151,7 @@ export = { Resource: 'test_oauth_token' }, InsecureSsl: true, + GitCloneDepth: 4, Location: 'https://github.testcompany.com/testowner/testrepo' } })); @@ -164,6 +168,7 @@ export = { source: new codebuild.BitBucketSource({ owner: 'testowner', repo: 'testrepo', + cloneDepth: 5, }) }); @@ -172,6 +177,7 @@ export = { Source: { Type: 'BITBUCKET', Location: 'https://bitbucket.org/testowner/testrepo.git', + GitCloneDepth: 5, }, }));