@cloudcomponents/cdk-github-webhook
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

cloudcomponents Logo

@cloudcomponents/cdk-github-webhook

Build Status cdkdx typescript python Mentioned in Awesome CDK

Create, update and delete github webhooks with your app deployment

Install

TypeScript/JavaScript:

npm i @cloudcomponents/cdk-github-webhook

Python:

pip install cloudcomponents.cdk-github-webhook

How to use

import { GithubWebhook } from '@cloudcomponents/cdk-github-webhook';
import { SecretKey } from '@cloudcomponents/cdk-secret-key';
import { Stack, StackProps, aws_apigateway } from 'aws-cdk-lib';
import { Construct } from 'constructs';

export class GithubWebhookStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const api = new aws_apigateway.RestApi(this, 'github-webhook');
    api.root.addMethod('POST');

    if (typeof process.env.API_TOKEN === 'undefined') {
      throw new Error('environment variable API_TOKEN undefined');
    }
    const githubApiToken = SecretKey.fromPlainText(process.env.API_TOKEN);

    // @example https://github.com/cloudcomponents/cdk-constructs
    if (typeof process.env.REPO_URL === 'undefined') {
      throw new Error('environment variable REPO_URL undefined');
    }
    const githubRepoUrl = process.env.REPO_URL;

    // @see https://developer.github.com/v3/activity/events/types/
    const events = ['*'];

    new GithubWebhook(this, 'GithubWebhook', {
      githubApiToken,
      githubRepoUrl,
      payloadUrl: api.url,
      events,
      logLevel: 'debug',
    });
  }
}

API Reference

See API.md.

Example

See more complete examples.

License

MIT

Package Sidebar

Install

npm i @cloudcomponents/cdk-github-webhook

Weekly Downloads

53

Version

2.3.0

License

MIT

Unpacked Size

13.9 MB

Total Files

12

Last publish

Collaborators

  • hupe1980