Skip to content

Commit

Permalink
feat(aws-codecommit): New method addToPipelineStage on Repository.
Browse files Browse the repository at this point in the history
See aws#265 for the discussion about this feature.
  • Loading branch information
skinny85 committed Aug 22, 2018
1 parent 0056f35 commit 3e9ed72
Show file tree
Hide file tree
Showing 4 changed files with 34 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.addToPipelineStage(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#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'
*/
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
10 changes: 10 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,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.
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.addToPipelineStage(sourceStage, 'source', {
artifactName: 'SourceArtifact',
repository: repo,
});

const buildStage = new codepipeline.Stage(stack, 'build', { pipeline });
Expand Down

0 comments on commit 3e9ed72

Please sign in to comment.