Skip to content

Commit

Permalink
feat(aws-codecommit): New method addToPipelineStage on Repository. (#616
Browse files Browse the repository at this point in the history
)

See #265 for the discussion about this feature.
  • Loading branch information
skinny85 committed Aug 29, 2018
1 parent 4463cfd commit 54c202a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-codecommit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 14 additions & 7 deletions packages/@aws-cdk/aws-codecommit/lib/pipeline-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
*/
Expand All @@ -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.
*/
Expand Down
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-codecommit/lib/repository.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 54c202a

Please sign in to comment.