@cloudcomponents/cdk-pull-request-approval-rule
v2.4.0
Published
CodeCommit pull request approval rules to enforcing your pull request workflow
Downloads
2,974
Maintainers
Readme
@cloudcomponents/cdk-pull-request-approval-rule
CodeCommit pull request approval rules to enforcing your pull request workflow
Install
TypeScript/JavaScript:
npm i @cloudcomponents/cdk-pull-request-approval-rule
Python:
pip install cloudcomponents.cdk-pull-request-approval-rule
How to use
import { ApprovalRuleTemplate, ApprovalRuleTemplateRepositoryAssociation } from '@cloudcomponents/cdk-pull-request-approval-rule';
import { PullRequestCheck } from '@cloudcomponents/cdk-pull-request-check';
import { Stack, StackProps } from 'aws-cdk-lib';
import { BuildSpec } from 'aws-cdk-lib/aws-codebuild';
import { Repository } from 'aws-cdk-lib/aws-codecommit';
import { Construct } from 'constructs';
export class PullRequestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const repository = new Repository(this, 'Repository', {
repositoryName: 'pr-check-repository',
});
const { approvalRuleTemplateName } = new ApprovalRuleTemplate(this, 'ApprovalRuleTemplate', {
approvalRuleTemplateName: 'template-name',
template: {
approvers: {
numberOfApprovalsNeeded: 1,
},
},
});
new ApprovalRuleTemplateRepositoryAssociation(this, 'ApprovalRuleTemplateRepositoryAssociation', {
approvalRuleTemplateName,
repository,
});
new PullRequestCheck(this, 'PullRequestCheck', {
repository,
buildSpec: BuildSpec.fromSourceFilename('prcheck.yml'),
});
}
}
ApprovalRuleOverridden notification
import { ApprovalRuleTemplate, ApprovalRuleTemplateRepositoryAssociation } from '@cloudcomponents/cdk-pull-request-approval-rule';
import { PullRequestCheck } from '@cloudcomponents/cdk-pull-request-check';
import { Stack, StackProps } from 'aws-cdk-lib';
import { BuildSpec } from 'aws-cdk-lib/aws-codebuild';
import { Repository } from 'aws-cdk-lib/aws-codecommit';
import { SnsTopic } from 'aws-cdk-lib/aws-events-targets';
import { Topic } from 'aws-cdk-lib/aws-sns';
import { Construct } from 'constructs';
export class PullRequestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const repository = new Repository(this, 'Repository', {
repositoryName: 'pr-check-repository',
});
const { approvalRuleTemplateName } = new ApprovalRuleTemplate(
this,
'ApprovalRuleTemplate',
{
approvalRuleTemplateName: 'template-name',
template: {
approvers: {
numberOfApprovalsNeeded: 1,
},
},
},
);
const ruleAsscociation = new ApprovalRuleTemplateRepositoryAssociation(
stack,
'ApprovalRuleTemplateRepositoryAssociation',
{
approvalRuleTemplateName,
repository,
},
);
const topic = new Topic(stack, 'Topic');
ruleAsscociation.onOverridden('overridden', {
target: new SnsTopic(topic),
});
// Approves the pull request
new PullRequestCheck(this, 'PullRequestCheck', {
repository,
buildSpec: BuildSpec.fromSourceFilename('prcheck.yml'),
});
}
}
API Reference
See API.md.
Example
See more complete examples.