Skip to content

Testing Probot Locally

clee2000 edited this page Apr 5, 2024 · 1 revision

Test Probot Locally

Possibly not safe

Note that testing via yarn test is probably enough and this is only if you really want to test on real webhooks and api calls.

This wiki explains how to test the Probot Github App pytorch-bot[bot] implemented in torchci (not to be confused with pytorchbot the user account).

  1. Download the smee-client via npm install -g smee-client. Go to smee.io and start a new channel. Copy the Webhook Proxy URL they give you.
  2. Make and register a Github App. Put the Webhook Proxy URL you got from smee as the Webhook URL. Download a private key after the app gets created.
  3. Choose a repository to install the Github App and send webooks from. Install the Github App on this repository. Configure the repository to send webhooks to the URL from step 1.
  4. Comment out all but the functionality you want to test in torchci/lib/bot/index.ts. This isn't necessary, but I imagine you don't want to pollute DynamoDB or even your own repo with unnecessary bot actions.
  5. Ensure the following environment variables are set: APP_ID, PRIVATE_KEY, and WEBHOOK_SECRET, either in your terminal or in .env.local. Information on what to set these to can be found here. PRIVATE_KEY should be base64 encoded from the private key downloaded in step 2 (cat <file> | base64).
  6. In your terminal, run smee -u <URL from step 1> -t http://localhost:3000/api/github/webhooks. In another terminal, run yarn dev.
  7. Take actions in your repository (ex open issue, trigger workflow) to send webhooks which will trigger your bot.
  8. Profit

Troubleshooting:

  • May be due to lack of authentication... The installation ID cannot be determined - Install the Github App on the repo
  • signature does not match event payload and secret - In the webhook configuration settings, ensure that the content type is application/json and not application/x-www-form-urlencoded
  • Missing x-hub-signature-256 (not sure how this exhibits itself, but probably something about signatures) - Ensure that you have picked a webhook secret and put it in the Github App, your environment variables, and in the webhook settings
  • Logging can be done via ctx.log.info("message")

TODO:

  • Check which env vars (APP_ID, PRIVATE_KEY, and WEBHOOK_SECRET) are actually needed
  • Check if PRIVATE_KEY really needs to be base64 encoded
  • Check if we can use the WEBHOOK_PROXY_URL environment variable instead of running smee in a terminal
  • Figure out how to not need to comment out certain bots (webhookToDynamo, not sure what else)

References: https://probot.github.io/docs/development