Skip to content

Commit 6b67e16

Browse files
Merge pull request #1695 from ehuss/gh-api-docs
Add more documentation on setting up local testing.
2 parents b531960 + 835a344 commit 6b67e16

File tree

1 file changed

+73
-25
lines changed

1 file changed

+73
-25
lines changed

README.md

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,86 @@ Some developers may settle with testing in production as the risks tend to be lo
3434

3535
The general overview of what you will need to do:
3636

37-
1. Install Postgres. Look online for any help with installing and setting up Postgres (particularly if you need to create a user and set up permissions).
38-
2. Create a database: `createdb triagebot`
39-
3. Provide a way for GitHub to access the Triagebot webserver.
40-
There are various ways to do this (such as placing it behind a proxy, or poking holes in your firewall).
41-
Or, you can use a service such as https://ngrok.com/ to access on your local dev machine via localhost.
42-
Installation is fairly simple, though requires setting up a (free) account.
43-
Run the command `ngrok http 8000` to forward to port 8000 on localhost.
44-
4. Create a GitHub repo to run some tests on.
45-
5. Configure the webhook in your GitHub repo.
46-
I recommend at least skimming the [GitHub webhook documentation](https://docs.github.com/en/developers/webhooks-and-events/webhooks/about-webhooks) if you are not familiar with webhooks. In short:
47-
48-
1. Go to the settings page.
49-
2. Go to the webhook section.
50-
3. Click "Add webhook"
51-
4. Include the settings:
52-
53-
- Payload URL: This is the URL to your Triagebot server, for example http://7e9ea9dc.ngrok.io/github-hook. This URL is displayed when you ran the `ngrok` command above.
54-
- Content type: application/json
55-
- Secret: Enter a shared secret (some longish random text)
56-
- Events: "Send me everything"
57-
6. Configure the `.env` file:
37+
1. Create a repo on GitHub to run tests on.
38+
2. [Configure a database](#configure-a-database)
39+
3. [Configure webhook forwarding](#configure-webhook-forwarding)
40+
4. Configure the `.env` file:
5841

5942
1. Copy `.env.sample` to `.env`
6043
2. `GITHUB_API_TOKEN`: This is a token needed for Triagebot to send requests to GitHub. Go to GitHub Settings > Developer Settings > Personal Access Token, and create a new token. The `repo` permission should be sufficient.
6144
If this is not set, Triagebot will also look in `~/.gitconfig` in the `github.oauth-token` setting.
62-
3. `DATABASE_URL`: This is the URL to the Postgres database. Something like `postgres://eric@localhost/triagebot` should work, replacing `eric` with your username.
45+
3. `DATABASE_URL`: This is the URL to the database. See [Configuring a database](#configuring-a-database).
6346
4. `GITHUB_WEBHOOK_SECRET`: Enter the secret you entered in the webhook above.
6447
5. `RUST_LOG`: Set this to `debug`.
6548

66-
7. Run `cargo run --bin triagebot`. This starts the http server listening on port 8000.
67-
8. Add a `triagebot.toml` file to the main branch of your GitHub repo with whichever services you want to try out.
68-
9. Try interacting with your repo, such as issuing `@rustbot` commands or interacting with PRs and issues (depending on which services you enabled in `triagebot.toml`). Watch the logs from the server to see what's going on.
49+
5. Run `cargo run --bin triagebot`. This starts the http server listening for webhooks on port 8000.
50+
6. Add a `triagebot.toml` file to the main branch of your GitHub repo with whichever services you want to try out.
51+
7. Try interacting with your repo, such as issuing `@rustbot` commands or interacting with PRs and issues (depending on which services you enabled in `triagebot.toml`). Watch the logs from the server to see what's going on.
52+
53+
### Configure a database
54+
55+
To use Postgres, you will need to install it and configure it:
56+
57+
1. Install Postgres. Look online for any help with installing and setting up Postgres (particularly if you need to create a user and set up permissions).
58+
2. Create a database: `createdb triagebot`
59+
3. In the `.env` file, set the `DATABASE_URL`:
60+
61+
```sh
62+
DATABASE_URL=postgres://eric@localhost/triagebot
63+
```
64+
65+
replacing `eric` with the username on your local system.
66+
67+
### Configure webhook forwarding
68+
69+
I recommend at least skimming the [GitHub webhook documentation](https://docs.github.com/en/developers/webhooks-and-events/webhooks/about-webhooks) if you are not familiar with webhooks.
70+
In order for GitHub's webhooks to reach your triagebot server, you'll need to figure out some way to route them to your machine.
71+
There are various options on how to do this.
72+
You can poke holes into your firewall or use a proxy, but you shouldn't expose your machine to the the internet.
73+
There are various services which help with this problem.
74+
These generally involve running a program on your machine that connects to an external server which relays the hooks into your machine.
75+
There are several to choose from:
76+
77+
* [gh webhook](#gh-webhook) — This is a GitHub-native service. This is the easiest to use.
78+
* [ngrok](#ngrok) — This is pretty easy to use, but requires setting up a free account.
79+
* <https://smee.io/> — This is another service recommended by GitHub.
80+
* <https://localtunnel.github.io/www/> — This is another service recommended by GitHub.
81+
82+
#### gh webhook
83+
84+
The [`gh` CLI](https://github.com/cli/cli) is the official CLI tool which I highly recommend getting familiar with.
85+
There is an official extension which provides webhook forwarding and also takes care of all the configuration.
86+
See [cli/gh-webhook](https://docs.github.com/en/developers/webhooks-and-events/webhooks/receiving-webhooks-with-the-github-cli) for more information on installing it.
87+
88+
This is super easy to use, and doesn't require manually configuring webhook settings.
89+
The command to run looks something like:
90+
91+
```sh
92+
gh webhook forward --repo=ehuss/triagebot-test --events=* \
93+
--url=http://127.0.0.1:8000/github-hook --secret somelongsekrit
94+
```
95+
96+
Where the value in `--secret` is the secret value you place in `GITHUB_WEBHOOK_SECRET` in the `.env` file, and `--repo` is the repo you want to test against.
97+
98+
#### ngrok
99+
100+
The following is an example of using <https://ngrok.com/> to provide webhook forwarding.
101+
You need to sign up for a free account, and also deal with configuring the GitHub webhook settings.
102+
103+
1. Install ngrok.
104+
2. Run `ngrok http 8000`. This will forward webhook events to localhost on port 8000.
105+
3. Configure GitHub webhooks in the test repo you created.
106+
In short:
107+
108+
1. Go to the settings page for your GitHub repo.
109+
2. Go to the webhook section.
110+
3. Click "Add webhook"
111+
4. Include the settings:
112+
113+
* Payload URL: This is the URL to your Triagebot server, for example http://7e9ea9dc.ngrok.io/github-hook. This URL is displayed when you ran the `ngrok` command above.
114+
* Content type: application/json
115+
* Secret: Enter a shared secret (some longish random text)
116+
* Events: "Send me everything"
69117

70118
## License
71119

0 commit comments

Comments
 (0)