Skip to content

Commit 5408a53

Browse files
authored
feat(codebuild): add support for setting the gitCloneDepth property on Project sources. (#1798)
Also fixed the weird casing of the 'GitHubEnterPrise' SourceType enum value while I was in the area. Fixes #1789
1 parent 940a860 commit 5408a53

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

packages/@aws-cdk/aws-codebuild/lib/source.ts

+41-10
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,48 @@ export class NoSource extends BuildSource {
7171
}
7272
}
7373

74+
/**
75+
* The construction properties common to all build sources that are backed by Git.
76+
*/
77+
export interface GitBuildSourceProps extends BuildSourceProps {
78+
/**
79+
* The depth of history to download. Minimum value is 0.
80+
* If this value is 0, greater than 25, or not provided,
81+
* then the full history is downloaded with each build of the project.
82+
*/
83+
cloneDepth?: number;
84+
}
85+
86+
/**
87+
* A common superclass of all build sources that are backed by Git.
88+
*/
89+
export abstract class GitBuildSource extends BuildSource {
90+
private readonly cloneDepth?: number;
91+
92+
protected constructor(props: GitBuildSourceProps) {
93+
super(props);
94+
95+
this.cloneDepth = props.cloneDepth;
96+
}
97+
98+
public toSourceJSON(): CfnProject.SourceProperty {
99+
const ret = super.toSourceJSON();
100+
ret.gitCloneDepth = this.cloneDepth;
101+
return ret;
102+
}
103+
}
104+
74105
/**
75106
* Construction properties for {@link CodeCommitSource}.
76107
*/
77-
export interface CodeCommitSourceProps extends BuildSourceProps {
108+
export interface CodeCommitSourceProps extends GitBuildSourceProps {
78109
repository: codecommit.IRepository;
79110
}
80111

81112
/**
82113
* CodeCommit Source definition for a CodeBuild project.
83114
*/
84-
export class CodeCommitSource extends BuildSource {
115+
export class CodeCommitSource extends GitBuildSource {
85116
public readonly type: SourceType = SourceType.CodeCommit;
86117
private readonly repo: codecommit.IRepository;
87118

@@ -153,7 +184,7 @@ export class CodePipelineSource extends BuildSource {
153184
/**
154185
* Construction properties for {@link GitHubSource} and {@link GitHubEnterpriseSource}.
155186
*/
156-
export interface GitHubSourceProps extends BuildSourceProps {
187+
export interface GitHubSourceProps extends GitBuildSourceProps {
157188
/**
158189
* The GitHub account/user that owns the repo.
159190
*
@@ -193,7 +224,7 @@ export interface GitHubSourceProps extends BuildSourceProps {
193224
/**
194225
* GitHub Source definition for a CodeBuild project.
195226
*/
196-
export class GitHubSource extends BuildSource {
227+
export class GitHubSource extends GitBuildSource {
197228
public readonly type: SourceType = SourceType.GitHub;
198229
private readonly httpsCloneUrl: string;
199230
private readonly oauthToken: cdk.Secret;
@@ -228,7 +259,7 @@ export class GitHubSource extends BuildSource {
228259
/**
229260
* Construction properties for {@link GitHubEnterpriseSource}.
230261
*/
231-
export interface GitHubEnterpriseSourceProps extends BuildSourceProps {
262+
export interface GitHubEnterpriseSourceProps extends GitBuildSourceProps {
232263
/**
233264
* The HTTPS URL of the repository in your GitHub Enterprise installation.
234265
*/
@@ -250,8 +281,8 @@ export interface GitHubEnterpriseSourceProps extends BuildSourceProps {
250281
/**
251282
* GitHub Enterprise Source definition for a CodeBuild project.
252283
*/
253-
export class GitHubEnterpriseSource extends BuildSource {
254-
public readonly type: SourceType = SourceType.GitHubEnterPrise;
284+
export class GitHubEnterpriseSource extends GitBuildSource {
285+
public readonly type: SourceType = SourceType.GitHubEnterprise;
255286
private readonly httpsCloneUrl: string;
256287
private readonly oauthToken: cdk.Secret;
257288
private readonly ignoreSslErrors?: boolean;
@@ -275,7 +306,7 @@ export class GitHubEnterpriseSource extends BuildSource {
275306
/**
276307
* Construction properties for {@link BitBucketSource}.
277308
*/
278-
export interface BitBucketSourceProps extends BuildSourceProps {
309+
export interface BitBucketSourceProps extends GitBuildSourceProps {
279310
/**
280311
* The BitBucket account/user that owns the repo.
281312
*
@@ -294,7 +325,7 @@ export interface BitBucketSourceProps extends BuildSourceProps {
294325
/**
295326
* BitBucket Source definition for a CodeBuild project.
296327
*/
297-
export class BitBucketSource extends BuildSource {
328+
export class BitBucketSource extends GitBuildSource {
298329
public readonly type: SourceType = SourceType.BitBucket;
299330
private readonly httpsCloneUrl: any;
300331

@@ -318,7 +349,7 @@ export enum SourceType {
318349
CodeCommit = 'CODECOMMIT',
319350
CodePipeline = 'CODEPIPELINE',
320351
GitHub = 'GITHUB',
321-
GitHubEnterPrise = 'GITHUB_ENTERPRISE',
352+
GitHubEnterprise = 'GITHUB_ENTERPRISE',
322353
BitBucket = 'BITBUCKET',
323354
S3 = 'S3',
324355
}

packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export = {
142142

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

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

147147
new codebuild.Project(stack, 'MyProject', {
148148
source
@@ -282,6 +282,7 @@ export = {
282282
"CloneUrlHttp"
283283
]
284284
},
285+
"GitCloneDepth": 2,
285286
"Type": "CODECOMMIT"
286287
}
287288
}

packages/@aws-cdk/aws-codebuild/test/test.project.ts

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export = {
5757
source: new codebuild.GitHubSource({
5858
owner: 'testowner',
5959
repo: 'testrepo',
60+
cloneDepth: 3,
6061
oauthToken: new cdk.Secret("test_oauth_token")
6162
})
6263
});
@@ -71,6 +72,7 @@ export = {
7172
},
7273
Location: 'https://github.com/testowner/testrepo.git',
7374
ReportBuildStatus: true,
75+
GitCloneDepth: 3,
7476
}
7577
}));
7678

@@ -135,6 +137,7 @@ export = {
135137
source: new codebuild.GitHubEnterpriseSource({
136138
httpsCloneUrl: 'https://github.testcompany.com/testowner/testrepo',
137139
ignoreSslErrors: true,
140+
cloneDepth: 4,
138141
oauthToken: new cdk.Secret("test_oauth_token")
139142
})
140143
});
@@ -148,6 +151,7 @@ export = {
148151
Resource: 'test_oauth_token'
149152
},
150153
InsecureSsl: true,
154+
GitCloneDepth: 4,
151155
Location: 'https://github.testcompany.com/testowner/testrepo'
152156
}
153157
}));
@@ -164,6 +168,7 @@ export = {
164168
source: new codebuild.BitBucketSource({
165169
owner: 'testowner',
166170
repo: 'testrepo',
171+
cloneDepth: 5,
167172
})
168173
});
169174

@@ -172,6 +177,7 @@ export = {
172177
Source: {
173178
Type: 'BITBUCKET',
174179
Location: 'https://bitbucket.org/testowner/testrepo.git',
180+
GitCloneDepth: 5,
175181
},
176182
}));
177183

0 commit comments

Comments
 (0)