gitlab-webhook-listener-bot
TypeScript icon, indicating that this package has built-in type declarations

0.19.7 • Public • Published

Gitlab WebHook Listener Bot

This project will listen for GitLab webhook events, and do actions based on context.

The project acts as a building block for you to create your own handlers.

Example

This will execute code to re-run renovate bot if the [x] check is checked.

import { main, logger, MergeRequestHandler } from "gitlab-webhook-listener-bot";

class RenovateRebase extends MergeRequestHandler {
  public async handle(payload: MergeRequestPayload): Promise<void> {
    this.logger.debug("Renovate bot wants rebase");
    // TODO: create pipeline
    // code here to do the actual action
  }

  /**
   * Must be an opened mr whose status is updated
   * and branch is renovate branch
   * and rebase checkbox is checked.
   */
  public isValid(payload: MergeRequestPayload): boolean {
    const {
      object_attributes: {
        source_branch,
        action,
        state,
      },
      changes: {
        description,
      },
    } = payload;

    return (
      state === "opened" &&
      action === "update" &&
      source_branch.startsWith("renovate/") &&
      (description?.current || "").includes("[x] <!-- rebase-check -->")
    );
  }
}

main({
  logger,
  handlers: [
    new RenovateRebase(logger),
  ],
});

Demo

There's standalone project that you can copy and start your own project from it:

Similar projects

Package Sidebar

Install

npm i gitlab-webhook-listener-bot

Weekly Downloads

0

Version

0.19.7

License

MIT

Unpacked Size

71.2 kB

Total Files

161

Last publish

Collaborators

  • glen