diff --git a/packages/@aws-cdk/aws-codecommit/README.md b/packages/@aws-cdk/aws-codecommit/README.md index 13f58fe15e663..4e53bbe549019 100644 --- a/packages/@aws-cdk/aws-codecommit/README.md +++ b/packages/@aws-cdk/aws-codecommit/README.md @@ -49,6 +49,15 @@ const sourceAction = new codecommit.PipelineSource(this, 'CodeCommit', { // use sourceAction.artifact as the inputArtifact to later Actions... ``` +You can also add the Repository to the Pipeline directly: + +```ts +// equivalent to the code above: +const sourceAction = repository.addToPipelineStage(sourceStage, 'CodeCommit', { + artifactName: 'SourceOutput', +}); +``` + ### Events CodeCommit repositories emit CloudWatch events for certain activity. diff --git a/packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts b/packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts index 76a118add732a..5bcfd0a149902 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts @@ -3,20 +3,17 @@ import cdk = require('@aws-cdk/cdk'); import { RepositoryRef } from './repository'; /** - * Construction properties of the {@link PipelineSource CodeCommit source CodePipeline Action}. + * Common properties for creating {@link PipelineSource} - + * either directly, through its constructor, + * or through {@link RepositoryRef#addToPipelineStage}. */ -export interface PipelineSourceProps extends codepipeline.CommonActionProps { +export interface CommonPipelineSourceProps { /** * The name of the source's output artifact. * Output artifacts are used by CodePipeline as inputs into other actions. */ artifactName: string; - /** - * The CodeCommit repository. - */ - repository: RepositoryRef; - /** * @default 'master' */ @@ -31,6 +28,16 @@ export interface PipelineSourceProps extends codepipeline.CommonActionProps { pollForSourceChanges?: boolean; } +/** + * Construction properties of the {@link PipelineSource CodeCommit source CodePipeline Action}. + */ +export interface PipelineSourceProps extends CommonPipelineSourceProps, codepipeline.CommonActionProps { + /** + * The CodeCommit repository. + */ + repository: RepositoryRef; +} + /** * CodePipeline Source that is provided by an AWS CodeCommit repository. */ diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index e000543bb8a4e..ad486918784e7 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -1,6 +1,8 @@ +import actions = require('@aws-cdk/aws-codepipeline-api'); import events = require('@aws-cdk/aws-events'); import cdk = require('@aws-cdk/cdk'); import { cloudformation, RepositoryArn, RepositoryName } from './codecommit.generated'; +import { CommonPipelineSourceProps, PipelineSource } from './pipeline-action'; /** * Properties for the {@link RepositoryRef.import} method. @@ -53,6 +55,14 @@ export abstract class RepositoryRef extends cdk.Construct { }; } + public addToPipelineStage(stage: actions.IStage, name: string, props: CommonPipelineSourceProps): PipelineSource { + return new PipelineSource(this.parent!!, name, { + stage, + repository: this, + ...props, + }); + } + /** * Defines a CloudWatch event rule which triggers for repository events. Use * `rule.addEventPattern(pattern)` to specify a filter. diff --git a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit.ts b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit.ts index 43fabb7e9914f..71e69f8635014 100644 --- a/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit.ts +++ b/packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-code-commit.ts @@ -11,10 +11,8 @@ const repo = new codecommit.Repository(stack, 'MyRepo', { repositoryName: 'my-re const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); const sourceStage = new codepipeline.Stage(pipeline, 'source', { pipeline }); -new codecommit.PipelineSource(stack, 'source', { - stage: sourceStage, +repo.addToPipelineStage(sourceStage, 'source', { artifactName: 'SourceArtifact', - repository: repo, }); const buildStage = new codepipeline.Stage(stack, 'build', { pipeline });