Skip to content

20minutes/serverless-github-check

Repository files navigation

Serverless GitHub Check

serverless Build Status

Apply some simple checks on each PR.

example

Use Cases

We have 4 functions available:

  • specification: It validates GitHub Pull Requests against some specifications:
    • body should be at least 8 characters long
    • title should be at least 8 characters long
  • label: It checks if there is a blocking label in the GitHub Pull Request
    • if one blocking label (default: Work In Progress, Waiting For Change, Waiting For Travis) is found, PR is blocked
    • if no labels are defined in the PR, PR is blocked
    • if no blocking labels are defined, PR is validated
  • fixup: It checks if there is some fixup! commits in the PR history
    • if at least one fixup commit are found, PR is blocked
    • if no fixup commits are found, PR is validated
  • autoMerge: It merges PR from @dependabot when the update it for a patch or a minor version
    • the repo must have the auto merge option enabled

Prerequisites

  • Node.js 20
  • Serverless CLI v3 (npm install -g serverless@3)
  • An AWS account
  • Defined provider credentials

Setup

Deploy the code

By default

  • it'll use the AWS profile default, but you can use your own using (be sure it's defined in your ~/.aws/credentials): serverless deploy --aws-profile myprofile
  • it'll be deployed to the AWS region eu-west-1 but you can change it using: serverless deploy --region us-east-1

Setup GitHub webhook

Configure the webhook in the GitHub repository settings.

  • In the Payload URL, enter the URL you received after deploying. It would be something like https://<your_url>.amazonaws.com/dev/webhook.
  • Choose the "application/json" in Content type.
  • In the types of events to trigger the webhook, select "Let me select individual events", then select at least Pull Requests.

Some options

You can update some options from the serverless.yml file:

  • NAMESPACE: change the namespace used in the PR check (displayed at the bottom of each PR)
  • CHECK_BODY_LENGTH: change the minimun length of the body of the PR
  • CHECK_TITLE_LENGTH: change the minimun length of the title of the PR
  • BLOCK_LABELS: define which label will block a PR (coma separated strings)

Info

This little project is part of the #NoServerNovember challenge.