From 54c202abe1300014583dde487043e29e8fc0f443 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Wed, 29 Aug 2018 11:54:17 -0700 Subject: [PATCH] feat(aws-codecommit): New method addToPipelineStage on Repository. (#616) See #265 for the discussion about this feature. --- packages/@aws-cdk/aws-codecommit/README.md | 9 ++++++++ .../aws-codecommit/lib/pipeline-action.ts | 21 ++++++++++++------- .../@aws-cdk/aws-codecommit/lib/repository.ts | 19 +++++++++++++++++ .../test/integ.pipeline-code-commit.ts | 4 +--- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/packages/@aws-cdk/aws-codecommit/README.md b/packages/@aws-cdk/aws-codecommit/README.md index 13f58fe15e663..1d352d1538498 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.addToPipeline(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..32656dd76f303 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#addToPipeline}. */ -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..152a7ff82d4b1 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,23 @@ export abstract class RepositoryRef extends cdk.Construct { }; } + /** + * Convenience method for creating a new {@link PipelineSource} Action, + * and adding it to the given Stage. + * + * @param stage the Pipeline Stage to add the new Action to + * @param name the name of the newly created Action + * @param props the properties of the new Action + * @returns the newly created {@link PipelineSource} Action + */ + public addToPipeline(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..803f323e23411 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.addToPipeline(sourceStage, 'source', { artifactName: 'SourceArtifact', - repository: repo, }); const buildStage = new codepipeline.Stage(stack, 'build', { pipeline });