Skip to main content

CodeCommit pull request approval rules to enforcing your pull request workflow

Project description

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

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file cloudcomponents.cdk-pull-request-approval-rule-2.4.0.tar.gz.

File metadata

File hashes

Hashes for cloudcomponents.cdk-pull-request-approval-rule-2.4.0.tar.gz
Algorithm Hash digest
SHA256 fff9b374fa8a1a95e605eff7d83189a641e0b35d563018dbf0c947ba24e70bdd
MD5 fd9ecd2967784ddaad617e1ddaa93b04
BLAKE2b-256 387f7287fc1db032b911f15203b6e03affad5a3333b7dc48c3be2f25904bad42

See more details on using hashes here.

File details

Details for the file cloudcomponents.cdk_pull_request_approval_rule-2.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudcomponents.cdk_pull_request_approval_rule-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c485ef804c8761696d234fc574b9e89bd02e6c60c6eb6df61b6f13b9a838c7f
MD5 9dd67967e2a4f5427461ca50d187777b
BLAKE2b-256 2f4d6db02015837cc45c917df638e3e6c859f81d1a4f5dbfb21c316d8922054f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page