1.6.0 • Published 11 months ago

@hive-o/nest-probot v1.6.0

Weekly downloads
-
License
LGPL-3.0-only
Repository
-
Last release
11 months ago

@hive-o/nest-probot

Integrate Probot with NestJS

Description

This module provides access to the Probot library which is used for building GitHub apps.

Motivation

NestJS and Probot are great frameworks that helps bootstrap projects for creating complex applications. That being said both have different configuration patterns and overall execution style. So to simplify Probot configuration and leverage the full extent of NestJS capabilities in such a way the building probot based github applications becomes declarative using decorators and event-handlers, we created this module.

Usage

Before you can start testing probot with nestjs you will need to create a github app Please follow the instructions: how to create a github app?

Install

# NPM
npm i --save @hive-o/nest-probot

# Yarn
yarn add @hive-o/nest-probot

Import

Import and add ProbotModule to the imports section of your nestjs app module. It's common to inject it directly into app Module's constructor so that it can be used during the onModuleInit lifecycle hook at application startup.

Using synchronous configuration

app.module.ts

import { ProbotModule } from '@hive-o/nest-probot';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    ProbotModule.forRoot({
      config: {
        appId: envConfig.GH_APP_ID,
        clientId: envConfig.GH_CLIENT_ID,
        clientSecret: envConfig.GH_CLIENT_SECRET,
        privateKey: envConfig.GH_PRIVATE_KEY, // base64 converted value of your github private key
        webhookSecret: envConfig.GH_WEBHOOK_SECRET, // optional
        webhookProxy: envConfig.GH_WEBHOOK_PROXY, // optional
        webhookPath: envConfig.GH_WEBHOOK_PATH, // optional
      },
    })
  ]
})
export class ExampleModule {}

app.controller.ts

import { Controller, Get, Req } from '@nestjs/common';
import { Hook, ProbotService } from '@hive-o/nest-probot';

@Controller()
export class AppController {
  constructor(private readonly probot: ProbotService) {}

  @Get()
  getHello(): string {
    return 'Hello World!';
  }

  // Add the handler to recieve github hook
  @Post("/hook")
  async hooks(@Req() req) {
    await this.probot.receiveHook(req);
  }

  @Hook(['issue_comment.created'])
  async hook(context) {
    console.log(context);
  }
}

Using asynchronous configuration

app.module.ts

import { ProbotModule } from '@hive-o/nest-probot';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    ProbotModule.forRootAsync({
      isGlobal: true, // (optional), defaults to true
      useFactory: (envConfig: ConfigService) => ({
        appId: envConfig.get('GH_APP_ID'),
        clientId: envConfig.get('GH_CLIENT_ID'),
        clientSecret: envConfig.get('GH_CLIENT_SECRET'),
        privateKey: envConfig.get('GH_PRIVATE_KEY'), // base64 converted value of your github private key
        webhookSecret: envConfig.get('GH_WEBHOOK_SECRET'), // optional
        webhookProxy: envConfig.get('GH_WEBHOOK_PROXY'), // optional
        webhookPath: envConfig.get('GH_WEBHOOK_PATH'), // optional
      }),
      inject: [ConfigService],
    })
  ]
})
export class ExampleModule {}

app.controller.ts

import { Controller, Get, Req } from '@nestjs/common';
import { Hook, ProbotService } from '@hive-o/nest-probot';

@Controller()
export class AppController {
  constructor(private readonly probot: ProbotService) {}

  @Get()
  getHello(): string {
    return 'Hello World!';
  }

  // Add the handler to recieve github hook
  @Post("/hook")
  async hooks(@Req() req) {
    await this.probot.receiveHook(req);
  }

  @Hook(['issue_comment.created'])
  async hook(context) {
    console.log(context);
  }
}
1.6.0

11 months ago

1.5.0

11 months ago

1.4.0

11 months ago

1.3.0

11 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago