CodeCommit pull request approval rules to enforcing your pull request workflow
TypeScript/JavaScript:
npm i @cloudcomponents/cdk-pull-request-approval-rule
Python:
pip install cloudcomponents.cdk-pull-request-approval-rule
import { Construct, Stack, StackProps } from '@aws-cdk/core';
import { Repository } from '@aws-cdk/aws-codecommit';
import { BuildSpec } from '@aws-cdk/aws-codebuild';
import { PullRequestCheck } from '@cloudcomponents/cdk-pull-request-check';
import {
ApprovalRuleTemplate,
ApprovalRuleTemplateRepositoryAssociation,
} from '@cloudcomponents/cdk-pull-request-approval-rule';
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'),
});
}
}
import { Construct, Stack, StackProps } from '@aws-cdk/core';
import { Repository } from '@aws-cdk/aws-codecommit';
import { BuildSpec } from '@aws-cdk/aws-codebuild';
import { PullRequestCheck } from '@cloudcomponents/cdk-pull-request-check';
import {
ApprovalRuleTemplate,
ApprovalRuleTemplateRepositoryAssociation,
} from '@cloudcomponents/cdk-pull-request-approval-rule';
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'),
});
}
}
See API.md.
See more complete examples.