Skip to content

Commit

Permalink
aws#907 Makes github codebuild sources take prop interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
eaddingtonwhite committed Oct 12, 2018
1 parent ddffe24 commit ee1b38c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
31 changes: 24 additions & 7 deletions packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,36 @@ export class CodePipelineSource extends BuildSource {
}
}

export interface GithubSourceProps {
/**
* The git url to clone for this code build project.
*/
cloneUrl: string;

/**
* The oAuthToken used to authenticate when cloning source git repo.
*/
oauthToken: cdk.Secret;

}

/**
* GitHub Source definition for a CodeBuild project
*/
export class GitHubSource extends BuildSource {
constructor(private readonly httpscloneUrl: string, private readonly oauthToken: cdk.Secret) {
private cloneUrl: string;
private oauthToken: cdk.Secret;
constructor(props: GithubSourceProps) {
super();
this.httpscloneUrl = httpscloneUrl;
this.oauthToken = oauthToken;
this.cloneUrl = props.cloneUrl;
this.oauthToken = props.oauthToken;
}

public toSourceJSON(): cloudformation.ProjectResource.SourceProperty {
return {
type: SourceType.GitHub,
auth: this.oauthToken != null ? { type: 'OAUTH', resource: this.oauthToken } : undefined,
location: this.httpscloneUrl
location: this.cloneUrl
};
}
}
Expand All @@ -95,10 +110,12 @@ export class GitHubSource extends BuildSource {
* GitHub Enterprise Source definition for a CodeBuild project
*/
export class GitHubEnterpriseSource extends BuildSource {
constructor(private readonly cloneUrl: string, private readonly oauthToken: cdk.Secret) {
private cloneUrl: string;
private oauthToken: cdk.Secret;
constructor(props: GithubSourceProps) {
super();
this.cloneUrl = cloneUrl;
this.oauthToken = oauthToken;
this.cloneUrl = props.cloneUrl;
this.oauthToken = props.oauthToken;
}

public toSourceJSON(): cloudformation.ProjectResource.SourceProperty {
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-codebuild/test/test.project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export = {

// WHEN
new codebuild.Project(stack, 'Project', {
source: new codebuild.GitHubEnterpriseSource("https://mycompany.github.com", "my_oauth_token")
source: new codebuild.GitHubEnterpriseSource({
cloneUrl: "https://mycompany.github.com",
oauthToken: new cdk.Secret("my_oauth_token")
})
});

// THEN
Expand Down

0 comments on commit ee1b38c

Please sign in to comment.