diff --git a/packages/@aws-cdk/aws-codebuild/lib/source.ts b/packages/@aws-cdk/aws-codebuild/lib/source.ts index 2fef03ce0db39..f95efb4a56b68 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/source.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/source.ts @@ -92,18 +92,20 @@ export class GitHubSource extends BuildSource { } /** - * GitHub Enterprice Source definition for a CodeBuild project + * GitHub Enterprise Source definition for a CodeBuild project */ export class GitHubEnterpriseSource extends BuildSource { - constructor(private readonly cloneUrl: string) { + constructor(private readonly cloneUrl: string, private readonly oauthToken: any) { super(); this.cloneUrl = cloneUrl; + this.oauthToken = oauthToken; } public toSourceJSON(): cloudformation.ProjectResource.SourceProperty { return { type: SourceType.GitHubEnterPrise, location: this.cloneUrl, + auth: this.oauthToken != null ? { type: 'OAUTH', resource: this.oauthToken } : undefined, }; } } diff --git a/packages/@aws-cdk/aws-codebuild/test/test.project.ts b/packages/@aws-cdk/aws-codebuild/test/test.project.ts index 9c42173536d58..854e7f43c0d79 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.project.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.project.ts @@ -34,7 +34,7 @@ export = { // WHEN new codebuild.Project(stack, 'Project', { source: new codebuild.CodePipelineSource(), - buildSpec: { phases: [ 'say hi' ] } + buildSpec: { phases: ['say hi'] } }); // THEN @@ -47,6 +47,30 @@ export = { test.done(); }, + 'github enterprise auth test'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + new codebuild.Project(stack, 'Project', { + source: new codebuild.GitHubEnterpriseSource("https://mycompany.github.com", "my_oauth_token") + }); + + // THEN + expect(stack).to(haveResource('AWS::CodeBuild::Project', { + Source: { + Type: "GITHUB_ENTERPRISE", + Auth: { + Type: 'OAUTH', + Resource: 'my_oauth_token' + }, + Location: 'https://mycompany.github.com' + } + })); + + test.done(); + }, + 'construct from asset'(test: Test) { // GIVEN const stack = new cdk.Stack(); @@ -70,10 +94,12 @@ export = { { Name: "SCRIPT_S3_KEY", Type: "PLAINTEXT", - Value: { "Fn::Join": [ "", [ - { "Fn::Select": [ 0, { "Fn::Split": [ "||", { Ref: "AssetS3VersionKeyA852DDAE" } ] } ] }, - { "Fn::Select": [ 1, { "Fn::Split": [ "||", { Ref: "AssetS3VersionKeyA852DDAE" } ] } ] } - ] ] } + Value: { + "Fn::Join": ["", [ + { "Fn::Select": [0, { "Fn::Split": ["||", { Ref: "AssetS3VersionKeyA852DDAE" }] }] }, + { "Fn::Select": [1, { "Fn::Split": ["||", { Ref: "AssetS3VersionKeyA852DDAE" }] }] } + ]] + } } ], },