Skip to content

Commit b1e981d

Browse files
committed
docs: add deployment docs (moved from app repo)
1 parent 578ea75 commit b1e981d

File tree

6 files changed

+191
-0
lines changed

6 files changed

+191
-0
lines changed

astro.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export default defineConfig({
6868
{ label: 'implementations', slug: 'project/implementations' },
6969
],
7070
},
71+
72+
{
73+
label: 'Development',
74+
items: [
75+
{ label: 'about', slug: 'development/about-the-bot' },
76+
{ label: 'development', slug: 'development/local-deploy' },
77+
],
78+
},
7179
],
7280
}),
7381
sitemap()

src/assets/app-created.png

43.1 KB
Loading

src/assets/delivery-comment.png

131 KB
Loading
25.7 KB
Loading
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
id: local
3+
title: Testing the All-Contributors App
4+
sidebar_label: Test the Bot Locally
5+
---
6+
7+
## Understanding GitHub Apps and Local Development
8+
9+
### What is a GitHub App?
10+
11+
A GitHub App is how bots interact with GitHub. It's:
12+
13+
- **An account** - GitHub knows "this is the AllContributors bot"
14+
- **A permission system** - defines what the bot can read/write (issues, PRs,
15+
files)
16+
- **A webhook endpoint** - where GitHub sends events (like "someone commented
17+
on an issue")
18+
19+
When someone comments `@all-contributors please add @user for code`, GitHub
20+
sends that comment as a webhook to whatever URL is configured in the GitHub App
21+
settings.
22+
23+
### Why create your own test app?
24+
25+
The production AllContributors app is configured to send webhooks to the
26+
production Vercel deployment. You can't use it for local development because:
27+
28+
1. The webhooks go to production, not your laptop
29+
2. Your changes would affect real repositories
30+
3. You'd need to deploy every change just to test it
31+
32+
### Local development flow:
33+
34+
1. **Create your own GitHub App** - your personal copy with its own settings
35+
2. **Point its webhooks at your local machine** - so events come to you
36+
3. **Install it only on test repos** - isolated from production
37+
4. **Run the bot code locally** - make changes, test immediately
38+
5. **When ready** - deploy to Vercel and test with preview deployments
39+
40+
This gives you a safe sandbox to develop in.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
id: local
3+
title: How to deploy the bot locally
4+
sidebar_label: Help us Improve
5+
---
6+
7+
import { Aside } from "@astrojs/starlight/components";
8+
import { Picture } from "astro:assets";
9+
import appInstalled from "@assets/where-app-is-installed.png";
10+
import appCreated from "@assets/app-created.png";
11+
import deliveryComment from "@assets/delivery-comment.png";
12+
13+
## Local Bot Setup
14+
15+
To test the bot locally, you need to create your own GitHub App and configure
16+
it to point to your local machine.
17+
18+
<Aside type="caution">
19+
Uninstall the production all-contributors bot from your user account before
20+
continuing; if you don't, multiple bots will respond to your GitHub comments.
21+
</Aside>
22+
23+
To get your app running against GitHub:
24+
25+
## 1. Create a GitHub App for testing in your account:
26+
27+
- Go to your account's GitHub
28+
[developer settings](https://github.com/settings/developers)
29+
- Create a [new GitHub app](https://github.com/settings/apps/new)
30+
31+
Required fields are:
32+
33+
- `name`, which can be whatever you like, globally unique on GitHub
34+
- `homepage url`, which can be set to anything
35+
- `webhook url`, which can be set to anything
36+
37+
Important fields are:
38+
39+
- `webhook secret`, set this to `development`
40+
- `Permissions` which should be set
41+
[as defined in the app.yml](https://github.com/all-contributors/all-contributors-bot/blob/main/app.yml#L54),
42+
e.g. set read & write for `Repository contents`, `Issues` and
43+
`Pull Requests`, and read for `Repository Metadata`
44+
- `Subscribe to Events` which should be set
45+
[as defined in the app.yml](https://github.com/all-contributors/all-contributors-bot/blob/main/app.yml#L15),
46+
e.g. check the checkbox for `Issue comment`
47+
- Ensure `Where can this GitHub App be installed?` is set to
48+
`only this account`
49+
50+
<Picture
51+
src={appInstalled}
52+
formats={["avif", "webp"]}
53+
alt="A screenshot ...."
54+
/>
55+
56+
## 2. Configure Your GitHub App for testing
57+
58+
You should now have an app created
59+
60+
<Picture src={appCreated} formats={["avif", "webp"]} alt="A screenshot ...." />
61+
62+
- On the General Tab, Click `Generate Private Key` and download it for later
63+
usage, call it something like `allcontributorsbot.pem`
64+
- On the Install Tab, Install the app/bot on your user
65+
66+
## 3. Configure Your local to talk to the GitHub app
67+
68+
Create a file named `.env` with the following template:
69+
70+
```txt
71+
APP_ID=
72+
WEBHOOK_SECRET=development
73+
PRIVATE_KEY=
74+
```
75+
76+
### Values
77+
78+
- `APP_ID`, you can get this from the General tab on the developer settings for
79+
your app
80+
- `WEBHOOK_SECRET`, leave as development (you set this on app setup)
81+
- `PRIVATE_KEY` when you generated the private key from your app, you should
82+
have a `allcontributorsbot.pem` file locally (or similar). run
83+
`openssl base64 < allcontributorsbot.pem | tr -d '\n' | pbcopy` on the file
84+
which will copy the base64 contents onto your clipboard, paste that into the
85+
line for `PRIVATE_KEY`
86+
87+
## 4. Setup a test GitHub repository/with issues PR
88+
89+
- Setup a repository under your name (the name on GitHub where the bot is
90+
installed)
91+
- Enable issues and pull requests
92+
- Create an issue
93+
- Comment on the issue: `@all-contributors please add @jakebolam for design`
94+
(replace @jakebolam with your username)
95+
96+
To verify if the bot should have seen this goto
97+
[your app settings](https://github.com/settings/apps/). On the Advanced Tab,
98+
Click the most recent deliver to see the payload. It should look something like
99+
this:
100+
101+
<Picture
102+
src={deliveryComment}
103+
formats={["avif", "webp"]}
104+
alt="A screenshot ...."
105+
/>
106+
107+
Copy the payload and save it locally in a file called
108+
`test-webhook-payload.json`. Also make note of the headers under the 'Headers'
109+
section.
110+
111+
## 5. Send your first hook
112+
113+
1. Install the node modules for the bot `yarn install`
114+
2. Run the bot `yarn start`
115+
3. Curl the bot (or use Postman, using the headers you got from the previous
116+
step and the content from `test-webhook-payload.json`) If you're using
117+
`curl`, this will look something like this:
118+
119+
```console
120+
curl -vX POST http://localhost:3000/ -d @test-webhook-payload.json \
121+
--header "Content-Type: application/json" \
122+
--header "User-Agent: GitHub-Hookshot/4d63832" \
123+
--header "X-GitHub-Delivery: 413857f0-8b61-11eb-92be-566b7aa5f6ee" \
124+
--header "X-GitHub-Event: issue_comment" \
125+
--header "X-GitHub-Hook-ID: 297478976" \
126+
--header "X-GitHub-Hook-Installation-Target-ID: 105785" \
127+
--header "X-GitHub-Hook-Installation-Target-Type: integration" \
128+
--header "X-Hub-Signature: sha1=ed222e6750dc2954a422ed8dd371f9da66368104" \
129+
--header "X-Hub-Signature-256: sha256=04d0943f20545ac8df974466c502e4b9743d3618149b03f4ea1a9e658bf31fd0"
130+
```
131+
132+
If there are no errors in the bot console, check your GitHub test issue to see
133+
the bot respond :tada:
134+
135+
## Using [smee.io](https://smee.io/)
136+
137+
Alternatively, instead of having to mock the webhook payload using `curl`, you
138+
can add an additional environment variable called `WEBHOOK_PROXY_URL` and set
139+
it to a [smee.io](https://smee.io) channel URL.
140+
141+
Once you've done that, set the Webhook URL for you app in GitHub to the same
142+
channel URL and, after a server restart, your bot will be able to directly
143+
respond to incoming webhooks.

0 commit comments

Comments
 (0)