Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-codecommit): New method addToPipelineStage on Repository #616

Merged
merged 1 commit into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is artifact name required? Can we get rid of them already (okay if we do that in a subsequent commit). But as far as I understand, they are only needed for referencing in the pipeline model, and in the CDK we can just use an artifact object instead and generate the Artifact name from eg the uniqueId for the Action construct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We have an issue opened for getting rid of (or at least defaulting) them.


/**
* 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}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - the {@link}isn't going to render properly in our Sphinx documentation (not that this isn't something we should fix :D)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually just a moved comment, so it doesn't bother me that much... yet ;)

*/
export interface PipelineSourceProps extends CommonPipelineSourceProps, codepipeline.CommonActionProps {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid multiple inheritance if possible (I think CommonPiplineSourceProps should just extend CommonActionProps)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CommonPiplineSourceProps cannot extend CommonActionProps, because CommonActionProps contain the required stage attribute, which we don't need to provide when calling Repository#addToPipeline(Stage, name: string, props: CommonPiplineSourceProps).

I don't believe it's possible to avoid multiple inheritance here.

/**
* 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