No description
  • JavaScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Mark Tareshawty 7d9bd472ec
Merge pull request #95 from github/dependabot/npm_and_yarn/npm_and_yarn-bb3626eb1a
Bump minimatch from 3.1.2 to 3.1.5 in the npm_and_yarn group across 1 directory
2026-04-23 14:49:49 -04:00
.github/workflows fix: replace npm install with npm ci in linting workflow (alert #2) 2026-04-23 17:46:52 +00:00
.env.sample Initial commit 2023-03-27 11:03:23 -04:00
.gitignore Initial commit 2023-03-27 11:03:23 -04:00
app.js Format project with standard 2023-05-03 10:37:57 -04:00
CODE_OF_CONDUCT.md Add supporting markdown file 2023-05-03 10:53:58 -04:00
CODEOWNERS Update CODEOWNERS to change reviewer group 2026-04-23 13:53:23 -04:00
CONTRIBUTING.md Remove note about tests since there aren't any 2023-05-03 12:54:20 -04:00
LICENSE Add MIT License 2023-04-18 20:07:30 -04:00
message.md Initial commit 2023-03-27 11:03:23 -04:00
package-lock.json Bump minimatch in the npm_and_yarn group across 1 directory 2026-04-23 18:20:11 +00:00
package.json Drop unnecessary dev dependency 2025-02-18 18:02:37 -05:00
README.md update node version 2024-02-19 12:03:53 +11:00
SECURITY.md Add supporting markdown file 2023-05-03 10:53:58 -04:00
SUPPORT.md Add supporting markdown file 2023-05-03 10:53:58 -04:00

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 20 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.