self-approval

A GitHub App built with Octotask that allows Pull Request authors to self-approve their Pull Requests.
Screenshot of self-approval app

Repository

self-approval/app

Authors

Cubik65536

Updated

July 26, 2024

A GitHub App built with Octotask that allows Pull Request authors to self-approve their Pull Requests.

Screenshot

Special thanks to dkhmelenko/autoapproval for providing some inspiration and also some code implementation for this App.

Introduction

For some repositories, the Pull Request have to be approved before it can be merged.

This GitHub App allows some whitelisted repository maintainers to self-approve their Pull Requests, so they can directly approve and merge their own Pull Requests.

Local Setup / Server Deployment

Install dependencies

npm install

Build the project

npm run build

Start the server

npm start

Follow the instructions to register a new GitHub app.

Configure the app in the .env file by following the following instructions

Configuration

  1. Copy the .env.example file to .env
  2. Fill in the following values according to the following descriptions:
    • APP_ID: the ID of the app, which you can get from the app settings page.
    • GITHUB_CLIENT_ID: the Client ID of the app, which you can get from the app settings page.
    • GITHUB_CLIENT_SECRET: the Client Secret of the app, which you can generate and get from the app settings page.
    • WEBHOOK_SECRET: the Webhook Secret that you generated when you created the app.
    • PRIVATE_KEY: the contents of the private key you downloaded after creating the app.
  3. [OPTIONAL] Change the PORT to the port you want the app to listen to.
  4. [OPTIONAL] Setup HTTPS and domain name for the app. You can use multiple ways to do this (e.g. Nginx & Certbot).
  5. Set the Webhook URL of your GitHub App in the app settings page to the WEBHOOK_URL you configured in the .env file.

Update the app

If you want to update the app that is deployed on your server, you can follow the following steps:

  1. Stop the server
  2. Pull the latest changes from the repository
  3. Rerun the npm commands shown above

Deploy to Vercel

This app can be continuously deployed to Vercel using the Vercel GitHub app.

Deploying

  1. You have two options to begin with:
  2. Fill the following environment variables according to the following descriptions:
    • APP_ID: the ID of the app, which you can get from the app settings page.
    • GITHUB_CLIENT_ID: the Client ID of the app, which you can get from the app settings page.
    • GITHUB_CLIENT_SECRET: the Client Secret of the app, which you can generate and get from the app settings page.
    • WEBHOOK_SECRET: the Webhook Secret that you generated when you created the app.
    • PRIVATE_KEY: the contents of the private key you downloaded after creating the app.
  3. [OPTIONAL] Set the URL of your Vercel app if you want to use a custom domain.
  4. Set the Webhook URL of your GitHub App in the app settings page to https://<your-vercel-app-url>/api/github/webhooks.

Update the app

If you want to update the app that is deployed on Vercel, you can follow the following steps:

  • If you used the above link to deploy the app
    1. Go to the Vercel dashboard and select the app you deployed
    2. Click on the Git Repository button to go the the GitHub repository
    3. Delete the repository
    4. Redeploy the app using the above guide
  • If you forked the repository and deployed it manually
    1. Go to the Vercel dashboard and select the app you deployed
    2. Click on the Git Repository button to go the the GitHub repository
    3. Sync from the upstream repository
    4. Wait for the Vercel to automatically redeploy the app

Considerations

image

How it works

The api/github/webhooks/index.ts file is handling requests to POST /api/github/webhooks, so make sure to configure your GitHub App registration's webhook URL accordingly.

Configure GitHub Repository

In order to use the bot, the config file should be provided. Config file should be defined in your repository. Config file is the yml file with the path .github/self-approval-pull-request.yml. And the file should have these 3 entries: self_approval_comments, from_author and apply_labels.

self_approval_comments

Define the list of comments that will be considered as self-approval.

self_approval_messages:
  - "I self-approve!"
  - "I self-certify!"

from_author

Define the list of GitHub users who can self-approve their Pull Request.

from_author:
  - "Cubik65536"
  - "<GitHub ID of other project maintainer>"

Assign an empty array if you want everyone can self-approve their Pull Requests (example: from_author: []).

apply_labels

Defines the list of labels on PR, which should be added once PR was approved. For example:

apply_labels:
  - "can-be-merged"
  - "self-approved"

Assign an empty array if no labels should be applied to PRs (example: apply_labels: []).

License

ISC © 2022-2024 iXOR Technology & Cubik65536

Get occasional updates on new apps & features.