From ce19080150d7dd2d6c881e0ff4b791cd4b2b55f9 Mon Sep 17 00:00:00 2001 From: kdirschl Date: Tue, 20 Jul 2021 19:08:01 -0400 Subject: [PATCH 01/11] Added CodeCommit repository as source for notification rule --- .../lib/notification-rule.ts | 2 +- .../aws-codestarnotifications/test/helpers.ts | 11 ++++++++++ .../test/notification-rule.test.ts | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-codestarnotifications/lib/notification-rule.ts b/packages/@aws-cdk/aws-codestarnotifications/lib/notification-rule.ts index 0796557e38a77..f30cf11f58a99 100644 --- a/packages/@aws-cdk/aws-codestarnotifications/lib/notification-rule.ts +++ b/packages/@aws-cdk/aws-codestarnotifications/lib/notification-rule.ts @@ -62,7 +62,7 @@ export interface NotificationRuleProps extends NotificationRuleOptions { /** * The Amazon Resource Name (ARN) of the resource to associate with the notification rule. - * Currently, Supported sources include pipelines in AWS CodePipeline and build projects in AWS CodeBuild in this L2 constructor. + * Currently, Supported sources include pipelines in AWS CodePipeline, build projects in AWS CodeBuild, and repositories in AWS CodeCommit in this L2 constructor. * @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codestarnotifications-notificationrule.html#cfn-codestarnotifications-notificationrule-resource */ readonly source: INotificationRuleSource; diff --git a/packages/@aws-cdk/aws-codestarnotifications/test/helpers.ts b/packages/@aws-cdk/aws-codestarnotifications/test/helpers.ts index bf1d335c94d9f..3acf5e33ca334 100644 --- a/packages/@aws-cdk/aws-codestarnotifications/test/helpers.ts +++ b/packages/@aws-cdk/aws-codestarnotifications/test/helpers.ts @@ -22,6 +22,17 @@ export class FakeCodePipeline implements notifications.INotificationRuleSource { } } +export class FakeCodeCommit implements notifications.INotificationRuleSource { + readonly repositoryArn = 'arn:aws:codecommit::1234567890:MyCodecommitProject'; + readonly repositoryName = 'test-repository'; + + bindAsNotificationRuleSource(): notifications.NotificationRuleSourceConfig { + return { + sourceArn: this.repositoryArn, + }; + } +} + export class FakeSnsTopicTarget implements notifications.INotificationRuleTarget { readonly topicArn = 'arn:aws:sns::1234567890:MyTopic'; diff --git a/packages/@aws-cdk/aws-codestarnotifications/test/notification-rule.test.ts b/packages/@aws-cdk/aws-codestarnotifications/test/notification-rule.test.ts index a155b3583a524..332e808ca3176 100644 --- a/packages/@aws-cdk/aws-codestarnotifications/test/notification-rule.test.ts +++ b/packages/@aws-cdk/aws-codestarnotifications/test/notification-rule.test.ts @@ -4,6 +4,7 @@ import * as notifications from '../lib'; import { FakeCodeBuild, FakeCodePipeline, + FakeCodeCommit, FakeSlackTarget, FakeSnsTopicTarget, } from './helpers'; @@ -29,6 +30,26 @@ describe('NotificationRule', () => { }); }); + test('created new notification rule from repository source', () => { + const repository = new FakeCodeCommit(); + + new notifications.NotificationRule(stack, 'MyNotificationRule', { + source: repository, + events: [ + 'codecommit-repository-pull-request-created', + 'codecommit-repository-pull-request-merged', + ], + }); + + expect(stack).toHaveResourceLike('AWS::CodeStarNotifications::NotificationRule', { + Resource: repository.repositoryArn, + EventTypeIds: [ + 'codecommit-repository-pull-request-created', + 'codecommit-repository-pull-request-merged', + ], + }); + }); + test('created new notification rule with all parameters in constructor props', () => { const project = new FakeCodeBuild(); const slack = new FakeSlackTarget(); From 8e21ebfb197d3f4de8d7141b2eab75651949953a Mon Sep 17 00:00:00 2001 From: kdirschl Date: Wed, 21 Jul 2021 12:31:43 -0400 Subject: [PATCH 02/11] In progress. Pull request create and merge only events so far --- .../@aws-cdk/aws-codecommit/lib/repository.ts | 87 ++++++++++++++++++- packages/@aws-cdk/aws-codecommit/package.json | 1 + 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index 495be2f981d86..e28c1679655b8 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -1,10 +1,19 @@ +import * as notifications from '@aws-cdk/aws-codestarnotifications'; import * as events from '@aws-cdk/aws-events'; import * as iam from '@aws-cdk/aws-iam'; import { IResource, Lazy, Resource, Stack } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { CfnRepository } from './codecommit.generated'; -export interface IRepository extends IResource { +/** + * Additional options to pass to the notification rule + */ +export interface RepositoryNotifyOnOptions extends notifications.NotificationRuleOptions { + //@TODO add reference link + readonly events: RepositoryNotificationEvents[]; +} + +export interface IRepository extends IResource, notifications.InotificationRuleSource { /** * The ARN of this Repository. * @attribute @@ -110,8 +119,37 @@ export interface IRepository extends IResource { * Grant the given identity permissions to read this repository. */ grantRead(grantee: iam.IGrantable): iam.Grant; + + /** + * + * @TODO description here + * + * @param id + * @param target + * @param options + */ + notifyOn( + id: string, + target: notifications.INotificationRuleTarget, + options: RepositoryNotifyOnOptions, + ): notifications.INotificationRule; + + // @TODO rest of events need to be added + notifyOnPullRequestCreated( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + notifiyOnPullRequestMerged( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; } + + /** * Options for the onCommit() method */ @@ -268,6 +306,46 @@ abstract class RepositoryBase extends Resource implements IRepository { 'codecommit:Describe*', ); } + + public notifyOn( + id: string, + target: notifications.INotificationRuleTarget, + options: RepositoryNotifyOnOptions, + ): notifications.INotificationRule { + return new notifications.NotificationRule(this, id, { + ...options, + source: this, + targets: [target], + }); + } + + public notifyOnPullRequestCreated( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.PULL_REQUEST_CREATED], + }); + } + + public notifiyOnPullRequestMerged( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.PULL_REQUEST_MERGED], + }); + } + + public bindAsNotificationRuleSource(_scope: Construct): notifications.NotificationRuleSourceConfig { + return { + sourceArn: this.repositoryArn, + }; + } } export interface RepositoryProps { @@ -448,3 +526,10 @@ function makeCloneUrl(stack: Stack, repositoryName: string, protocol: 'https' | return `codecommit::${region ?? stack.region}://${repositoryName}`; } } + +//@TODO rest of events here plus documentation +export enum RepositoryNotificationEvents { + PULL_REQUEST_CREATED = 'codecommit-repository-pull-request-created', + + PULL_REQUEST_MERGED = 'codecommit-repository-pull-request-merged', +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codecommit/package.json b/packages/@aws-cdk/aws-codecommit/package.json index 6d622f85d076a..c28bced23b3c0 100644 --- a/packages/@aws-cdk/aws-codecommit/package.json +++ b/packages/@aws-cdk/aws-codecommit/package.json @@ -88,6 +88,7 @@ "@aws-cdk/assert-internal": "0.0.0" }, "dependencies": { + "@aws-cdk/aws-codestarnotifications": "0.0.0", "@aws-cdk/aws-events": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", "@aws-cdk/core": "0.0.0", From 62a1b697cbcd76bd64b91c110466cd5f8e147b96 Mon Sep 17 00:00:00 2001 From: kdirschl Date: Wed, 21 Jul 2021 14:27:32 -0400 Subject: [PATCH 03/11] Added rest of events to ENUM and RepositoryBase --- .../@aws-cdk/aws-codecommit/lib/repository.ts | 157 +++++++++++++++++- 1 file changed, 155 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index e28c1679655b8..1a54c4b466228 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -13,7 +13,7 @@ export interface RepositoryNotifyOnOptions extends notifications.NotificationRul readonly events: RepositoryNotificationEvents[]; } -export interface IRepository extends IResource, notifications.InotificationRuleSource { +export interface IRepository extends IResource, notifications.INotificationRuleSource { /** * The ARN of this Repository. * @attribute @@ -319,6 +319,50 @@ abstract class RepositoryBase extends Resource implements IRepository { }); } + public notifyOnCommentOnCommits( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.COMMENT_ON_COMMITS], + }); + } + + public notifyOnCommentOnPullRequests( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.COMMENT_ON_PULL_REQUESTS], + }); + } + + public notifyOnApprovalsStatusChanged( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.APPROVALS_STATUS_CHANGED], + }); + } + + public notifyOnApprovalsRuleOverride( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.APPROVALS_RULE_OVERRIDE], + }); + } + public notifyOnPullRequestCreated( id: string, target: notifications.INotificationRuleTarget, @@ -330,6 +374,28 @@ abstract class RepositoryBase extends Resource implements IRepository { }); } + public notifyOnPullRequestSourceUpdated( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.PULL_REQUEST_SOURCE_UPDATED], + }); + } + + public notifyOnPullRequestStatusChanged( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.PULL_REQUEST_STATUS_CHANGED], + }); + } + public notifiyOnPullRequestMerged( id: string, target: notifications.INotificationRuleTarget, @@ -341,6 +407,39 @@ abstract class RepositoryBase extends Resource implements IRepository { }); } + public notifyOnBranchesAndTagsCreated( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.BRANCHES_AND_TAGS_CREATED], + }); + } + + public notifyOnBranchesAndTagsDeleted( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.BRANCHES_AND_TAGS_DELETED], + }); + } + + public notifyOnBranchesAndTagsUpdated( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule { + return this.notifyOn(id, target, { + ...options, + events: [RepositoryNotificationEvents.BRANCHES_AND_TAGS_UPDATED], + }); + } + public bindAsNotificationRuleSource(_scope: Construct): notifications.NotificationRuleSourceConfig { return { sourceArn: this.repositoryArn, @@ -527,9 +626,63 @@ function makeCloneUrl(stack: Stack, repositoryName: string, protocol: 'https' | } } -//@TODO rest of events here plus documentation +/** + * List of event types for AWS CodeCommit + * @see https://docs.aws.amazon.com/dtconsole/latest/userguide/concepts.html#events-ref-repositories + */ export enum RepositoryNotificationEvents { + /** + * Trigger notication when comment made on commit + */ + COMMENT_ON_COMMITS = 'codecommit-repository-comments-on-commits', + + /** + * Trigger notification when comment made on pull request + */ + COMMENT_ON_PULL_REQUESTS = 'codecommit-repository-comments-on-pull-requests', + + /** + * Trigger notification when approval status changed + */ + APPROVALS_STATUS_CHANGED = 'codecommit-repository-approvals-status-changed', + + /** + * Trigger notifications when approval rule is overridden + */ + APPROVALS_RULE_OVERRIDE = 'codecommit-repository-approvals-rule-override', + + /** + * Trigger notification when pull request created + */ PULL_REQUEST_CREATED = 'codecommit-repository-pull-request-created', + + /** + * Trigger notification when pull request source updated + */ + PULL_REQUEST_SOURCE_UPDATED = 'codecommit-repository-pull-request-source-updated', + + /** + * Trigger notification when pull request status is changed + */ + PULL_REQUEST_STATUS_CHANGED = 'codecommit-repository-pull-request-status-changed', + /** + * Trigger notification when pull requset is merged + */ PULL_REQUEST_MERGED = 'codecommit-repository-pull-request-merged', + + /** + * Trigger notification when a branch or tag is created + */ + BRANCHES_AND_TAGS_CREATED = 'codecommit-repository-branches-and-tags-created', + + /** + * Trigger notification when a branch or tag is deleted + */ + BRANCHES_AND_TAGS_DELETED = 'codecommit-repository-branches-and-tags-deleted', + + /** + * Trigger notification when a branch or tag is updated + */ + BRANCHES_AND_TAGS_UPDATED = 'codecommit-repository-branches-and-tags-updated', } \ No newline at end of file From 0e1f890c690c9602c079bdca8316098a55731790 Mon Sep 17 00:00:00 2001 From: kdirschl Date: Wed, 21 Jul 2021 14:55:06 -0400 Subject: [PATCH 04/11] updated IRepository interface and read me --- packages/@aws-cdk/aws-codecommit/README.md | 13 +++ .../@aws-cdk/aws-codecommit/lib/repository.ts | 102 +++++++++++++++++- 2 files changed, 112 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-codecommit/README.md b/packages/@aws-cdk/aws-codecommit/README.md index 3d4ef1c3ba46c..3040e11f844f2 100644 --- a/packages/@aws-cdk/aws-codecommit/README.md +++ b/packages/@aws-cdk/aws-codecommit/README.md @@ -55,3 +55,16 @@ const rule = repo.onCommentOnPullRequest('CommentOnPullRequest', { target: new targets.SnsTopic(myTopic), }); ``` + +## CodeStar Notifications + +To define CodeStar Notification rules for Repositories, use one of the `notifyOnXxx()` methods. +They are very similar to `onXxx()` methods for CloudWatch events: + +```ts +const target = new chatbot.SlackChannelConfiguration(stack, 'MySlackChannel', { + slackChannelConfigurationName: 'YOUR_CHANNEL_NAME', + slackWorkspaceId: 'YOUR_SLACK_WORKSPACE_ID', + slackChannelId: 'YOUR_SLACK_CHANNEL_ID', +}); +const rule = repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index 1a54c4b466228..c33e8cddacd97 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -9,7 +9,11 @@ import { CfnRepository } from './codecommit.generated'; * Additional options to pass to the notification rule */ export interface RepositoryNotifyOnOptions extends notifications.NotificationRuleOptions { - //@TODO add reference link + /** + * A list of event types associated with this notification rule for CodeCommit repositories. + * For a complete list of event types and IDs, see Notification concepts in the Developer Tools Console User Guide. + * @see https://docs.aws.amazon.com/dtconsole/latest/userguide/concepts.html#concepts-api + */ readonly events: RepositoryNotificationEvents[]; } @@ -120,13 +124,19 @@ export interface IRepository extends IResource, notifications.INotificationRuleS */ grantRead(grantee: iam.IGrantable): iam.Grant; + /** * - * @TODO description here + * Defines a CodeStar Notification rule triggered when the project + * events specified by you are emitted. Similar to `onEvent` API. + * + * You can also use the methods to define rules for the specific event emitted. + * eg: `notifyOnPullRequstCreated` * * @param id * @param target * @param options + * @returns CodeStar Notifications rule associated with this repository */ notifyOn( id: string, @@ -134,18 +144,104 @@ export interface IRepository extends IResource, notifications.INotificationRuleS options: RepositoryNotifyOnOptions, ): notifications.INotificationRule; - // @TODO rest of events need to be added + /** + * Defines a CodeStar Notification rule which triggers when a comment is made on a commit. + */ + notifyOnCommentOnCommits( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when a comment is made on a pull request + */ + notifyOnCommentOnPullRequests( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when an approval status is changed + */ + notifyOnApprovalsStatusChanged( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when an approval rule is overridden + */ + notifyOnApprovalsRuleOverride( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when a pull request is created + */ notifyOnPullRequestCreated( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule; + /** + * Defines a CodeStar Notification rule which triggers when a pull request source is updated + */ + notifyOnPullRequestSourceUpdated( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when a pull request status has changed + */ + notifyOnPullRequestStatusChanged( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when a pull request is merged + */ notifiyOnPullRequestMerged( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when a new branch or tag are created + */ + notifyOnBranchesAndTagsCreated( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when a branch or tag is deleted + */ + notifyOnBranchesAndTagsDeleted( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; + + /** + * Defines a CodeStar Notification rule which triggers when a branch or tag is updated + */ + notifyOnBranchesAndTagsUpdated( + id: string, + target: notifications.INotificationRuleTarget, + options?: notifications.NotificationRuleOptions, + ): notifications.INotificationRule; } From 373ab8ab19023d9bfd58eb9f46fc0bb468da0184 Mon Sep 17 00:00:00 2001 From: kdirschl Date: Thu, 22 Jul 2021 15:53:39 -0400 Subject: [PATCH 05/11] test push from WSL2 --- packages/@aws-cdk/aws-codecommit/README.md | 2 +- .../@aws-cdk/aws-codecommit/lib/repository.ts | 26 ++++++++++++------- packages/@aws-cdk/aws-codecommit/package.json | 3 ++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/@aws-cdk/aws-codecommit/README.md b/packages/@aws-cdk/aws-codecommit/README.md index 3040e11f844f2..7dd08eef3bb82 100644 --- a/packages/@aws-cdk/aws-codecommit/README.md +++ b/packages/@aws-cdk/aws-codecommit/README.md @@ -67,4 +67,4 @@ const target = new chatbot.SlackChannelConfiguration(stack, 'MySlackChannel', { slackWorkspaceId: 'YOUR_SLACK_WORKSPACE_ID', slackChannelId: 'YOUR_SLACK_CHANNEL_ID', }); -const rule = repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target); \ No newline at end of file +const rule = repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target); diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index c33e8cddacd97..5435cdd61f8f2 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -126,16 +126,16 @@ export interface IRepository extends IResource, notifications.INotificationRuleS /** - * + * * Defines a CodeStar Notification rule triggered when the project * events specified by you are emitted. Similar to `onEvent` API. - * + * * You can also use the methods to define rules for the specific event emitted. * eg: `notifyOnPullRequstCreated` - * - * @param id - * @param target - * @param options + * + * @param id + * @param target + * @param options * @returns CodeStar Notifications rule associated with this repository */ notifyOn( @@ -162,7 +162,7 @@ export interface IRepository extends IResource, notifications.INotificationRuleS options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule; - /** + /** * Defines a CodeStar Notification rule which triggers when an approval status is changed */ notifyOnApprovalsStatusChanged( @@ -245,7 +245,6 @@ export interface IRepository extends IResource, notifications.INotificationRuleS } - /** * Options for the onCommit() method */ @@ -403,6 +402,13 @@ abstract class RepositoryBase extends Resource implements IRepository { ); } + /** + * Defines a CodeStar Notification rule + * + * @param id + * @param target + * @param options + */ public notifyOn( id: string, target: notifications.INotificationRuleTarget, @@ -731,7 +737,7 @@ export enum RepositoryNotificationEvents { * Trigger notication when comment made on commit */ COMMENT_ON_COMMITS = 'codecommit-repository-comments-on-commits', - + /** * Trigger notification when comment made on pull request */ @@ -761,7 +767,7 @@ export enum RepositoryNotificationEvents { * Trigger notification when pull request status is changed */ PULL_REQUEST_STATUS_CHANGED = 'codecommit-repository-pull-request-status-changed', - + /** * Trigger notification when pull requset is merged */ diff --git a/packages/@aws-cdk/aws-codecommit/package.json b/packages/@aws-cdk/aws-codecommit/package.json index c28bced23b3c0..8adf4d16dd6c2 100644 --- a/packages/@aws-cdk/aws-codecommit/package.json +++ b/packages/@aws-cdk/aws-codecommit/package.json @@ -99,7 +99,8 @@ "@aws-cdk/aws-events": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", "@aws-cdk/core": "0.0.0", - "constructs": "^3.3.69" + "constructs": "^3.3.69", + "@aws-cdk/aws-codestarnotifications": "0.0.0" }, "engines": { "node": ">= 10.13.0 <13 || >=13.7.0" From 652007fb78af9a6367bce91d2d755c4f892297b6 Mon Sep 17 00:00:00 2001 From: kdirschl Date: Thu, 22 Jul 2021 19:27:44 -0400 Subject: [PATCH 06/11] tests in progress --- ...nteg.codecommit-notification.expected.json | 185 ++++++++++++++++++ .../test/integ.repository-notification.ts | 18 ++ .../test/test.notification-rule.ts | 66 +++++++ 3 files changed, 269 insertions(+) create mode 100644 packages/@aws-cdk/aws-codecommit/test/integ.codecommit-notification.expected.json create mode 100644 packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts create mode 100644 packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts diff --git a/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-notification.expected.json b/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-notification.expected.json new file mode 100644 index 0000000000000..e292837b50ac6 --- /dev/null +++ b/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-notification.expected.json @@ -0,0 +1,185 @@ +{ + "Resources": { + "MyRepositoryRole8TR43567": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "codecommit.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "MyRepositoryDefaultRolePolicyJ4578T45": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codecommit/", + { + "Ref": "MyRepositoryT5458715" + } + ] + ] + }, + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":logs:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":log-group:/aws/codecommit/", + { + "Ref": "MyRepositoryT5458715" + }, + ":*" + ] + ] + } + ] + }, + { + "Action": [ + "codecommit:CreateRepository", + "codecommit:CreatePullRequest", + "codecommit:MergePullRequestByFastForward" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":codecommit:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":report-group/", + { + "Ref": "MyRepository54G12ED7" + }, + "-*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyRepositoryDefaultRolePolicyJ4578T45", + "Roles": [ + { + "Ref": "MyRepositoryRole8TR43567" + } + ] + } + }, + "MyRepository54G12ED7": { + "Type": "AWS::CodeCommit::Repository", + "Properties": { + "RepositoryName": "my-test-repository" + } + }, + "MyRepositoryNotifyOnPullRequestCreated225C467F": { + "Type": "AWS::CodeStarNotifications::NotificationRule", + "Properties": { + "DetailType": "FULL", + "EventTypeIds": [ + "codecommit-repository-pull-request-created" + ], + "Name": "awscdkcodecommitrepositorynotificationMyRepositoryNotifyOnPullRequestCreated45127895", + "Resource": { + "Fn::GetAtt": [ + "MyRepositoryT5458715", + "Arn" + ] + }, + "Targets": [ + { + "TargetAddress": { + "Ref": "MyTopic75489871" + }, + "TargetType": "SNS" + } + ] + } + }, + "MyTopic75489871": { + "Type": "AWS::SNS::Topic" + }, + "MyTopicPolicy12A5EC17": { + "Type": "AWS::SNS::TopicPolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:Publish", + "Effect": "Allow", + "Principal": { + "Service": "codestar-notifications.amazonaws.com" + }, + "Resource": { + "Ref": "MyTopic75489871" + }, + "Sid": "0" + } + ], + "Version": "2012-10-17" + }, + "Topics": [ + { + "Ref": "MyTopic75489871" + } + ] + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts b/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts new file mode 100644 index 0000000000000..e739c637cca6e --- /dev/null +++ b/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts @@ -0,0 +1,18 @@ +#!/usr/bin/env node +import * as sns from '@aws-cdk/aws-sns'; +import * as cdk from '@aws-cdk/core'; +import * as codecommit from '../lib'; + +const app = new cdk.App(); + +const stack = new cdk.Stack(app, 'aws-cdk-codecommit-repository-notification'); + +const repository = new codecommit.Repository(stack, 'Repository', { + repositoryName: 'aws-cdk-repository-notification', +}); + +const target = new sns.Topic(stack, 'MyTopic'); + +repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target); + +app.synth(); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts b/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts new file mode 100644 index 0000000000000..fc63b7d449859 --- /dev/null +++ b/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts @@ -0,0 +1,66 @@ +import { expect, haveResource } from '@aws-cdk/assert-internal'; +import * as sns from '@aws-cdk/aws-sns'; +import * as cdk from '@aws-cdk/core'; +import { Test } from 'nodeunit'; +import * as codecommit from '../lib'; + +export = { + 'notifications rule'(test: Test) { + const stack = new cdk.Stack(); + const repository = new codecommit.Repository(stack, 'MyRepository', { + repositoryName: 'my-test-repository', + }); + + const target = new sns.Topic(stack, 'MyTopic'); + + repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target); + + repository.notifiyOnPullRequestMerged('NotifyOnPullRequestMerged', target); + + expect(stack).to(haveResource('AWS::CodeStarNotifications::NotificationRule', { + Name: 'MyRepositoryNotifyOnPullRequestCreated45127895', + DetailType: 'FULL', + EventTypeIds: [ + 'codecommit-repository-pull-request-created', + ], + Resource: { + 'Fn::GetAtt': [ + 'MyRepositoryT5458715', + 'Arn', + ], + }, + Targets: [ + { + TargetAddress: { + Ref: 'MyTopic75489871', + }, + TargetType: 'SNS', + }, + ], + })); + + // expect(stack).to(haveResource('AWS::CodeStarNotifications::NotificationRule', { + // Name: 'MyRepositoryNotifyOnPullRequestMerged47215469', + // DetailType: 'FULL', + // EventTypeIds: [ + // 'codecommit-repository-pull-request-merged', + // ], + // Resource: { + // 'Fn::GetAtt': [ + // 'MyRepositoryT5458715', + // 'Arn', + // ], + // }, + // Targets: [ + // { + // TargetAddress: { + // Ref: 'MyTopic75489871', + // }, + // TargetType: 'SNS', + // }, + // ], + // })); + + test.done(); + }, +}; \ No newline at end of file From 3838f2c400b26c58776f3c2f8072a10ee651ae74 Mon Sep 17 00:00:00 2001 From: kdirschl Date: Fri, 23 Jul 2021 14:26:31 -0400 Subject: [PATCH 07/11] Integration tests now passing --- ...nteg.codecommit-notification.expected.json | 185 ------------------ ...nteg.repository-notification.expected.json | 87 ++++++++ .../test/integ.repository-notification.ts | 7 +- .../test/test.notification-rule.ts | 50 ++--- 4 files changed, 116 insertions(+), 213 deletions(-) delete mode 100644 packages/@aws-cdk/aws-codecommit/test/integ.codecommit-notification.expected.json create mode 100644 packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.expected.json diff --git a/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-notification.expected.json b/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-notification.expected.json deleted file mode 100644 index e292837b50ac6..0000000000000 --- a/packages/@aws-cdk/aws-codecommit/test/integ.codecommit-notification.expected.json +++ /dev/null @@ -1,185 +0,0 @@ -{ - "Resources": { - "MyRepositoryRole8TR43567": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "codecommit.amazonaws.com" - } - } - ], - "Version": "2012-10-17" - } - } - }, - "MyRepositoryDefaultRolePolicyJ4578T45": { - "Type": "AWS::IAM::Policy", - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "logs:CreateLogGroup", - "logs:CreateLogStream", - "logs:PutLogEvents" - ], - "Effect": "Allow", - "Resource": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":logs:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":log-group:/aws/codecommit/", - { - "Ref": "MyRepositoryT5458715" - } - ] - ] - }, - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":logs:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":log-group:/aws/codecommit/", - { - "Ref": "MyRepositoryT5458715" - }, - ":*" - ] - ] - } - ] - }, - { - "Action": [ - "codecommit:CreateRepository", - "codecommit:CreatePullRequest", - "codecommit:MergePullRequestByFastForward" - ], - "Effect": "Allow", - "Resource": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":codecommit:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":report-group/", - { - "Ref": "MyRepository54G12ED7" - }, - "-*" - ] - ] - } - } - ], - "Version": "2012-10-17" - }, - "PolicyName": "MyRepositoryDefaultRolePolicyJ4578T45", - "Roles": [ - { - "Ref": "MyRepositoryRole8TR43567" - } - ] - } - }, - "MyRepository54G12ED7": { - "Type": "AWS::CodeCommit::Repository", - "Properties": { - "RepositoryName": "my-test-repository" - } - }, - "MyRepositoryNotifyOnPullRequestCreated225C467F": { - "Type": "AWS::CodeStarNotifications::NotificationRule", - "Properties": { - "DetailType": "FULL", - "EventTypeIds": [ - "codecommit-repository-pull-request-created" - ], - "Name": "awscdkcodecommitrepositorynotificationMyRepositoryNotifyOnPullRequestCreated45127895", - "Resource": { - "Fn::GetAtt": [ - "MyRepositoryT5458715", - "Arn" - ] - }, - "Targets": [ - { - "TargetAddress": { - "Ref": "MyTopic75489871" - }, - "TargetType": "SNS" - } - ] - } - }, - "MyTopic75489871": { - "Type": "AWS::SNS::Topic" - }, - "MyTopicPolicy12A5EC17": { - "Type": "AWS::SNS::TopicPolicy", - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": "sns:Publish", - "Effect": "Allow", - "Principal": { - "Service": "codestar-notifications.amazonaws.com" - }, - "Resource": { - "Ref": "MyTopic75489871" - }, - "Sid": "0" - } - ], - "Version": "2012-10-17" - }, - "Topics": [ - { - "Ref": "MyTopic75489871" - } - ] - } - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.expected.json b/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.expected.json new file mode 100644 index 0000000000000..c2f386ccebe0e --- /dev/null +++ b/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.expected.json @@ -0,0 +1,87 @@ +{ + "Resources": { + "MyCodecommitRepository26DB372B": { + "Type": "AWS::CodeCommit::Repository", + "Properties": { + "RepositoryName": "my-test-repository" + } + }, + "MyCodecommitRepositoryNotifyOnPullRequestCreated4CAB0621": { + "Type": "AWS::CodeStarNotifications::NotificationRule", + "Properties": { + "DetailType": "FULL", + "EventTypeIds": [ + "codecommit-repository-pull-request-created" + ], + "Name": "decommitMyCodecommitRepositoryNotifyOnPullRequestCreated65969BCB", + "Resource": { + "Fn::GetAtt": [ + "MyCodecommitRepository26DB372B", + "Arn" + ] + }, + "Targets": [ + { + "TargetAddress": { + "Ref": "MyTopic86869434" + }, + "TargetType": "SNS" + } + ] + } + }, + "MyCodecommitRepositoryNotifyOnPullRequestMerged80574FED": { + "Type": "AWS::CodeStarNotifications::NotificationRule", + "Properties": { + "DetailType": "FULL", + "EventTypeIds": [ + "codecommit-repository-pull-request-merged" + ], + "Name": "odecommitMyCodecommitRepositoryNotifyOnPullRequestMergedF426197C", + "Resource": { + "Fn::GetAtt": [ + "MyCodecommitRepository26DB372B", + "Arn" + ] + }, + "Targets": [ + { + "TargetAddress": { + "Ref": "MyTopic86869434" + }, + "TargetType": "SNS" + } + ] + } + }, + "MyTopic86869434": { + "Type": "AWS::SNS::Topic" + }, + "MyTopicPolicy12A5EC17": { + "Type": "AWS::SNS::TopicPolicy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:Publish", + "Effect": "Allow", + "Principal": { + "Service": "codestar-notifications.amazonaws.com" + }, + "Resource": { + "Ref": "MyTopic86869434" + }, + "Sid": "0" + } + ], + "Version": "2012-10-17" + }, + "Topics": [ + { + "Ref": "MyTopic86869434" + } + ] + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts b/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts index e739c637cca6e..4f7a5926a47ac 100644 --- a/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts +++ b/packages/@aws-cdk/aws-codecommit/test/integ.repository-notification.ts @@ -5,14 +5,15 @@ import * as codecommit from '../lib'; const app = new cdk.App(); -const stack = new cdk.Stack(app, 'aws-cdk-codecommit-repository-notification'); +const stack = new cdk.Stack(app, 'aws-cdk-codecommit'); -const repository = new codecommit.Repository(stack, 'Repository', { - repositoryName: 'aws-cdk-repository-notification', +const repository = new codecommit.Repository(stack, 'MyCodecommitRepository', { + repositoryName: 'my-test-repository', }); const target = new sns.Topic(stack, 'MyTopic'); repository.notifyOnPullRequestCreated('NotifyOnPullRequestCreated', target); +repository.notifiyOnPullRequestMerged('NotifyOnPullRequestMerged', target); app.synth(); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts b/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts index fc63b7d449859..352db47ffe5fc 100644 --- a/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts +++ b/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts @@ -7,7 +7,7 @@ import * as codecommit from '../lib'; export = { 'notifications rule'(test: Test) { const stack = new cdk.Stack(); - const repository = new codecommit.Repository(stack, 'MyRepository', { + const repository = new codecommit.Repository(stack, 'MyCodecommitRepository', { repositoryName: 'my-test-repository', }); @@ -18,48 +18,48 @@ export = { repository.notifiyOnPullRequestMerged('NotifyOnPullRequestMerged', target); expect(stack).to(haveResource('AWS::CodeStarNotifications::NotificationRule', { - Name: 'MyRepositoryNotifyOnPullRequestCreated45127895', + Name: 'MyCodecommitRepositoryNotifyOnPullRequestCreatedBB14EA32', DetailType: 'FULL', EventTypeIds: [ 'codecommit-repository-pull-request-created', ], Resource: { 'Fn::GetAtt': [ - 'MyRepositoryT5458715', + 'MyCodecommitRepository26DB372B', 'Arn', ], }, Targets: [ { TargetAddress: { - Ref: 'MyTopic75489871', + Ref: 'MyTopic86869434', }, TargetType: 'SNS', }, ], })); - // expect(stack).to(haveResource('AWS::CodeStarNotifications::NotificationRule', { - // Name: 'MyRepositoryNotifyOnPullRequestMerged47215469', - // DetailType: 'FULL', - // EventTypeIds: [ - // 'codecommit-repository-pull-request-merged', - // ], - // Resource: { - // 'Fn::GetAtt': [ - // 'MyRepositoryT5458715', - // 'Arn', - // ], - // }, - // Targets: [ - // { - // TargetAddress: { - // Ref: 'MyTopic75489871', - // }, - // TargetType: 'SNS', - // }, - // ], - // })); + expect(stack).to(haveResource('AWS::CodeStarNotifications::NotificationRule', { + Name: 'MyCodecommitRepositoryNotifyOnPullRequestMerged34A7EDF1', + DetailType: 'FULL', + EventTypeIds: [ + 'codecommit-repository-pull-request-merged', + ], + Resource: { + 'Fn::GetAtt': [ + 'MyCodecommitRepository26DB372B', + 'Arn', + ], + }, + Targets: [ + { + TargetAddress: { + Ref: 'MyTopic86869434', + }, + TargetType: 'SNS', + }, + ], + })); test.done(); }, From bdabea8bb582d45c4c10d8bce6aecf83b5ed5f7d Mon Sep 17 00:00:00 2001 From: kdirschl Date: Fri, 23 Jul 2021 17:05:32 -0400 Subject: [PATCH 08/11] changed name of test to match existing --- packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts b/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts index 352db47ffe5fc..aa0e48a51a3ac 100644 --- a/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts +++ b/packages/@aws-cdk/aws-codecommit/test/test.notification-rule.ts @@ -5,7 +5,7 @@ import { Test } from 'nodeunit'; import * as codecommit from '../lib'; export = { - 'notifications rule'(test: Test) { + 'CodeCommit Repositories - can create notification rule'(test: Test) { const stack = new cdk.Stack(); const repository = new codecommit.Repository(stack, 'MyCodecommitRepository', { repositoryName: 'my-test-repository', From 8137be840a56f983bc6711471b517f39c5c168a8 Mon Sep 17 00:00:00 2001 From: kdirschl Date: Fri, 30 Jul 2021 12:09:25 -0400 Subject: [PATCH 09/11] suggested changes in progress --- .../@aws-cdk/aws-codecommit/lib/repository.ts | 32 ++++++------------- packages/@aws-cdk/aws-codecommit/package.json | 4 +-- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index 5435cdd61f8f2..34f096e0cab9b 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -124,19 +124,14 @@ export interface IRepository extends IResource, notifications.INotificationRuleS */ grantRead(grantee: iam.IGrantable): iam.Grant; - /** - * * Defines a CodeStar Notification rule triggered when the project * events specified by you are emitted. Similar to `onEvent` API. * * You can also use the methods to define rules for the specific event emitted. - * eg: `notifyOnPullRequstCreated` + * eg: `notifyOnPullRequstCreated`. * - * @param id - * @param target - * @param options - * @returns CodeStar Notifications rule associated with this repository + * @returns CodeStar Notifications rule associated with this repository. */ notifyOn( id: string, @@ -147,7 +142,7 @@ export interface IRepository extends IResource, notifications.INotificationRuleS /** * Defines a CodeStar Notification rule which triggers when a comment is made on a commit. */ - notifyOnCommentOnCommits( + notifyOnCommitComment( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, @@ -156,7 +151,7 @@ export interface IRepository extends IResource, notifications.INotificationRuleS /** * Defines a CodeStar Notification rule which triggers when a comment is made on a pull request */ - notifyOnCommentOnPullRequests( + notifyOnPullRequestComment( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, @@ -402,13 +397,6 @@ abstract class RepositoryBase extends Resource implements IRepository { ); } - /** - * Defines a CodeStar Notification rule - * - * @param id - * @param target - * @param options - */ public notifyOn( id: string, target: notifications.INotificationRuleTarget, @@ -421,25 +409,25 @@ abstract class RepositoryBase extends Resource implements IRepository { }); } - public notifyOnCommentOnCommits( + public notifyOnCommitComment( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule { return this.notifyOn(id, target, { ...options, - events: [RepositoryNotificationEvents.COMMENT_ON_COMMITS], + events: [RepositoryNotificationEvents.COMMIT_COMMENT], }); } - public notifyOnCommentOnPullRequests( + public notifyOnPullRequestComment( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule { return this.notifyOn(id, target, { ...options, - events: [RepositoryNotificationEvents.COMMENT_ON_PULL_REQUESTS], + events: [RepositoryNotificationEvents.PULL_REQUEST_COMMENT], }); } @@ -736,12 +724,12 @@ export enum RepositoryNotificationEvents { /** * Trigger notication when comment made on commit */ - COMMENT_ON_COMMITS = 'codecommit-repository-comments-on-commits', + COMMIT_COMMENT = 'codecommit-repository-comments-on-commits', /** * Trigger notification when comment made on pull request */ - COMMENT_ON_PULL_REQUESTS = 'codecommit-repository-comments-on-pull-requests', + PULL_REQUEST_COMMENT = 'codecommit-repository-comments-on-pull-requests', /** * Trigger notification when approval status changed diff --git a/packages/@aws-cdk/aws-codecommit/package.json b/packages/@aws-cdk/aws-codecommit/package.json index 8adf4d16dd6c2..325c75e846904 100644 --- a/packages/@aws-cdk/aws-codecommit/package.json +++ b/packages/@aws-cdk/aws-codecommit/package.json @@ -96,11 +96,11 @@ }, "homepage": "https://github.com/aws/aws-cdk", "peerDependencies": { + "@aws-cdk/aws-codestarnotifications": "0.0.0", "@aws-cdk/aws-events": "0.0.0", "@aws-cdk/aws-iam": "0.0.0", "@aws-cdk/core": "0.0.0", - "constructs": "^3.3.69", - "@aws-cdk/aws-codestarnotifications": "0.0.0" + "constructs": "^3.3.69" }, "engines": { "node": ">= 10.13.0 <13 || >=13.7.0" From bcba6cd315510a8c1f1adf117d6471944e257ebf Mon Sep 17 00:00:00 2001 From: kdirschl Date: Sun, 1 Aug 2021 19:08:57 -0400 Subject: [PATCH 10/11] completed suggested changes --- .../@aws-cdk/aws-codecommit/lib/repository.ts | 150 +++++------------- 1 file changed, 44 insertions(+), 106 deletions(-) diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index 34f096e0cab9b..6e389a7a01499 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -6,7 +6,7 @@ import { Construct } from 'constructs'; import { CfnRepository } from './codecommit.generated'; /** - * Additional options to pass to the notification rule + * Additional options to pass to the notification rule. */ export interface RepositoryNotifyOnOptions extends notifications.NotificationRuleOptions { /** @@ -31,19 +31,19 @@ export interface IRepository extends IResource, notifications.INotificationRuleS readonly repositoryName: string; /** - * The HTTP clone URL + * The HTTP clone URL. * @attribute */ readonly repositoryCloneUrlHttp: string; /** - * The SSH clone URL + * The SSH clone URL. * @attribute */ readonly repositoryCloneUrlSsh: string; /** - * The HTTPS (GRC) clone URL + * The HTTPS (GRC) clone URL. * * HTTPS (GRC) is the protocol to use with git-remote-codecommit (GRC). * @@ -105,7 +105,7 @@ export interface IRepository extends IResource, notifications.INotificationRuleS onCommit(id: string, options?: OnCommitOptions): events.Rule; /** - * Grant the given principal identity permissions to perform the actions on this repository + * Grant the given principal identity permissions to perform the actions on this repository. */ grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant; @@ -149,7 +149,7 @@ export interface IRepository extends IResource, notifications.INotificationRuleS ): notifications.INotificationRule; /** - * Defines a CodeStar Notification rule which triggers when a comment is made on a pull request + * Defines a CodeStar Notification rule which triggers when a comment is made on a pull request. */ notifyOnPullRequestComment( id: string, @@ -158,25 +158,25 @@ export interface IRepository extends IResource, notifications.INotificationRuleS ): notifications.INotificationRule; /** - * Defines a CodeStar Notification rule which triggers when an approval status is changed + * Defines a CodeStar Notification rule which triggers when an approval status is changed. */ - notifyOnApprovalsStatusChanged( + notifyOnApprovalStatusChanged( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule; /** - * Defines a CodeStar Notification rule which triggers when an approval rule is overridden + * Defines a CodeStar Notification rule which triggers when an approval rule is overridden. */ - notifyOnApprovalsRuleOverride( + notifyOnApprovalRuleOverridden( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule; /** - * Defines a CodeStar Notification rule which triggers when a pull request is created + * Defines a CodeStar Notification rule which triggers when a pull request is created. */ notifyOnPullRequestCreated( id: string, @@ -185,25 +185,7 @@ export interface IRepository extends IResource, notifications.INotificationRuleS ): notifications.INotificationRule; /** - * Defines a CodeStar Notification rule which triggers when a pull request source is updated - */ - notifyOnPullRequestSourceUpdated( - id: string, - target: notifications.INotificationRuleTarget, - options?: notifications.NotificationRuleOptions, - ): notifications.INotificationRule; - - /** - * Defines a CodeStar Notification rule which triggers when a pull request status has changed - */ - notifyOnPullRequestStatusChanged( - id: string, - target: notifications.INotificationRuleTarget, - options?: notifications.NotificationRuleOptions, - ): notifications.INotificationRule; - - /** - * Defines a CodeStar Notification rule which triggers when a pull request is merged + * Defines a CodeStar Notification rule which triggers when a pull request is merged. */ notifiyOnPullRequestMerged( id: string, @@ -212,39 +194,28 @@ export interface IRepository extends IResource, notifications.INotificationRuleS ): notifications.INotificationRule; /** - * Defines a CodeStar Notification rule which triggers when a new branch or tag are created - */ - notifyOnBranchesAndTagsCreated( - id: string, - target: notifications.INotificationRuleTarget, - options?: notifications.NotificationRuleOptions, - ): notifications.INotificationRule; - - /** - * Defines a CodeStar Notification rule which triggers when a branch or tag is deleted + * Defines a CodeStar Notification rule which triggers when a new branch or tag is created. */ - notifyOnBranchesAndTagsDeleted( + notifyOnBranchOrTagCreated( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule; /** - * Defines a CodeStar Notification rule which triggers when a branch or tag is updated + * Defines a CodeStar Notification rule which triggers when a branch or tag is deleted. */ - notifyOnBranchesAndTagsUpdated( + notifyOnBranchOrTagDeleted( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule; } - /** - * Options for the onCommit() method + * Options for the onCommit() method. */ export interface OnCommitOptions extends events.OnEventOptions { - /** * The branch to monitor. * @@ -431,25 +402,25 @@ abstract class RepositoryBase extends Resource implements IRepository { }); } - public notifyOnApprovalsStatusChanged( + public notifyOnApprovalStatusChanged( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule { return this.notifyOn(id, target, { ...options, - events: [RepositoryNotificationEvents.APPROVALS_STATUS_CHANGED], + events: [RepositoryNotificationEvents.APPROVAL_STATUS_CHANGED], }); } - public notifyOnApprovalsRuleOverride( + public notifyOnApprovalRuleOverridden( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule { return this.notifyOn(id, target, { ...options, - events: [RepositoryNotificationEvents.APPROVALS_RULE_OVERRIDE], + events: [RepositoryNotificationEvents.APPROVAL_RULE_OVERRIDDEN], }); } @@ -464,28 +435,6 @@ abstract class RepositoryBase extends Resource implements IRepository { }); } - public notifyOnPullRequestSourceUpdated( - id: string, - target: notifications.INotificationRuleTarget, - options?: notifications.NotificationRuleOptions, - ): notifications.INotificationRule { - return this.notifyOn(id, target, { - ...options, - events: [RepositoryNotificationEvents.PULL_REQUEST_SOURCE_UPDATED], - }); - } - - public notifyOnPullRequestStatusChanged( - id: string, - target: notifications.INotificationRuleTarget, - options?: notifications.NotificationRuleOptions, - ): notifications.INotificationRule { - return this.notifyOn(id, target, { - ...options, - events: [RepositoryNotificationEvents.PULL_REQUEST_STATUS_CHANGED], - }); - } - public notifiyOnPullRequestMerged( id: string, target: notifications.INotificationRuleTarget, @@ -497,36 +446,25 @@ abstract class RepositoryBase extends Resource implements IRepository { }); } - public notifyOnBranchesAndTagsCreated( - id: string, - target: notifications.INotificationRuleTarget, - options?: notifications.NotificationRuleOptions, - ): notifications.INotificationRule { - return this.notifyOn(id, target, { - ...options, - events: [RepositoryNotificationEvents.BRANCHES_AND_TAGS_CREATED], - }); - } - - public notifyOnBranchesAndTagsDeleted( + public notifyOnBranchOrTagCreated( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule { return this.notifyOn(id, target, { ...options, - events: [RepositoryNotificationEvents.BRANCHES_AND_TAGS_DELETED], + events: [RepositoryNotificationEvents.BRANCH_OR_TAG_CREATED], }); } - public notifyOnBranchesAndTagsUpdated( + public notifyOnBranchOrTagDeleted( id: string, target: notifications.INotificationRuleTarget, options?: notifications.NotificationRuleOptions, ): notifications.INotificationRule { return this.notifyOn(id, target, { ...options, - events: [RepositoryNotificationEvents.BRANCHES_AND_TAGS_UPDATED], + events: [RepositoryNotificationEvents.BRANCH_OR_TAG_DELETED], }); } @@ -555,7 +493,7 @@ export interface RepositoryProps { } /** - * Provides a CodeCommit Repository + * Provides a CodeCommit Repository. */ export class Repository extends RepositoryBase { @@ -668,7 +606,7 @@ export class Repository extends RepositoryBase { */ export interface RepositoryTriggerOptions { /** - * A name for the trigger.Triggers on a repository must have unique names + * A name for the trigger.Triggers on a repository must have unique names. */ readonly name?: string; @@ -704,7 +642,7 @@ export enum RepositoryEventTrigger { } /** - * Returns the clone URL for a protocol + * Returns the clone URL for a protocol. */ function makeCloneUrl(stack: Stack, repositoryName: string, protocol: 'https' | 'ssh' | 'grc', region?: string) { switch (protocol) { @@ -722,57 +660,57 @@ function makeCloneUrl(stack: Stack, repositoryName: string, protocol: 'https' | */ export enum RepositoryNotificationEvents { /** - * Trigger notication when comment made on commit + * Trigger notication when comment made on commit. */ COMMIT_COMMENT = 'codecommit-repository-comments-on-commits', /** - * Trigger notification when comment made on pull request + * Trigger notification when comment made on pull request. */ PULL_REQUEST_COMMENT = 'codecommit-repository-comments-on-pull-requests', /** - * Trigger notification when approval status changed + * Trigger notification when approval status changed. */ - APPROVALS_STATUS_CHANGED = 'codecommit-repository-approvals-status-changed', + APPROVAL_STATUS_CHANGED = 'codecommit-repository-approvals-status-changed', /** - * Trigger notifications when approval rule is overridden + * Trigger notifications when approval rule is overridden. */ - APPROVALS_RULE_OVERRIDE = 'codecommit-repository-approvals-rule-override', + APPROVAL_RULE_OVERRIDDEN = 'codecommit-repository-approvals-rule-override', /** - * Trigger notification when pull request created + * Trigger notification when pull request created. */ PULL_REQUEST_CREATED = 'codecommit-repository-pull-request-created', /** - * Trigger notification when pull request source updated + * Trigger notification when pull request source updated. */ PULL_REQUEST_SOURCE_UPDATED = 'codecommit-repository-pull-request-source-updated', /** - * Trigger notification when pull request status is changed + * Trigger notification when pull request status is changed. */ PULL_REQUEST_STATUS_CHANGED = 'codecommit-repository-pull-request-status-changed', /** - * Trigger notification when pull requset is merged + * Trigger notification when pull requset is merged. */ PULL_REQUEST_MERGED = 'codecommit-repository-pull-request-merged', /** - * Trigger notification when a branch or tag is created + * Trigger notification when a branch or tag is created. */ - BRANCHES_AND_TAGS_CREATED = 'codecommit-repository-branches-and-tags-created', + BRANCH_OR_TAG_CREATED = 'codecommit-repository-branches-and-tags-created', /** - * Trigger notification when a branch or tag is deleted + * Trigger notification when a branch or tag is deleted. */ - BRANCHES_AND_TAGS_DELETED = 'codecommit-repository-branches-and-tags-deleted', + BRANCH_OR_TAG_DELETED = 'codecommit-repository-branches-and-tags-deleted', /** - * Trigger notification when a branch or tag is updated + * Trigger notification when a branch or tag is updated. */ - BRANCHES_AND_TAGS_UPDATED = 'codecommit-repository-branches-and-tags-updated', + BRANCH_OR_TAG_UPDATED = 'codecommit-repository-branches-and-tags-updated', } \ No newline at end of file From e0a4028b57e7097f59adcd83ca96ec1e62418905 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Wed, 25 Aug 2021 21:23:26 +0200 Subject: [PATCH 11/11] Remove notifyOnCommitComment() --- .../@aws-cdk/aws-codecommit/lib/repository.ts | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/packages/@aws-cdk/aws-codecommit/lib/repository.ts b/packages/@aws-cdk/aws-codecommit/lib/repository.ts index 6e389a7a01499..e55053c0249be 100644 --- a/packages/@aws-cdk/aws-codecommit/lib/repository.ts +++ b/packages/@aws-cdk/aws-codecommit/lib/repository.ts @@ -139,15 +139,6 @@ export interface IRepository extends IResource, notifications.INotificationRuleS options: RepositoryNotifyOnOptions, ): notifications.INotificationRule; - /** - * Defines a CodeStar Notification rule which triggers when a comment is made on a commit. - */ - notifyOnCommitComment( - id: string, - target: notifications.INotificationRuleTarget, - options?: notifications.NotificationRuleOptions, - ): notifications.INotificationRule; - /** * Defines a CodeStar Notification rule which triggers when a comment is made on a pull request. */ @@ -380,17 +371,6 @@ abstract class RepositoryBase extends Resource implements IRepository { }); } - public notifyOnCommitComment( - id: string, - target: notifications.INotificationRuleTarget, - options?: notifications.NotificationRuleOptions, - ): notifications.INotificationRule { - return this.notifyOn(id, target, { - ...options, - events: [RepositoryNotificationEvents.COMMIT_COMMENT], - }); - } - public notifyOnPullRequestComment( id: string, target: notifications.INotificationRuleTarget,