Coder Social home page Coder Social logo

github-app-js-sample's Introduction

Sample GitHub App

This sample app showcases how webhooks can be used with a GitHub App's installation token to create a bot that responds to issues. Code uses octokit.js.

Requirements

  • Node.js 12 or higher
  • A GitHub App subscribed to Pull Request events and with the following permissions:
    • Pull requests: Read & write
    • Metadata: Read-only
  • (For local development) A tunnel to expose your local server to the internet (e.g. smee, ngrok or cloudflared)
  • Your GitHub App Webhook must be configured to receive events at a URL that is accessible from the internet.

Setup

  1. Clone this repository.
  2. Create a .env file similar to .env.example and set actual values. If you are using GitHub Enterprise Server, also include a ENTERPRISE_HOSTNAME variable and set the value to the name of your GitHub Enterprise Server instance.
  3. Install dependencies with npm install.
  4. Start the server with npm run server.
  5. Ensure your server is reachable from the internet.
    • If you're using smee, run smee -u <smee_url> -t http://localhost:3000/api/webhook.
  6. Ensure your GitHub App includes at least one repository on its installations.

Usage

With your server running, you can now create a pull request on any repository that your app can access. GitHub will emit a pull_request.opened event and will deliver the corresponding Webhook payload to your server.

The server in this example listens for pull_request.opened events and acts on them by creating a comment on the pull request, with the message in message.md, using the octokit.js rest methods.

Security considerations

To keep things simple, this example reads the GITHUB_APP_PRIVATE_KEY from the environment. A more secure and recommended approach is to use a secrets management system like Vault, or one offered by major cloud providers: Azure Key Vault, AWS Secrets Manager, Google Secret Manager, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.