Neolithic Programming Machine

    @cloudcomponents/cdk-pull-request-approval-rule
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.0 • Public • Published

    cloudcomponents Logo

    @cloudcomponents/cdk-pull-request-approval-rule

    Build Status cdkdx typescript python

    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.

    License

    MIT

    Install

    npm i @cloudcomponents/cdk-pull-request-approval-rule

    DownloadsWeekly Downloads

    283

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    992 kB

    Total Files

    18

    Last publish

    Collaborators

    • hupe1980