Contribute Bot
Contribute Bot is a small service (written using Go Cloud!) that performs
automated checks on issues and pull requests to help keep contributions
organized and easy to triage for maintainers.
Contribute Bot has two servers: a webhook endpoint and an event listener. The
webhook endpoint publishes events to a Cloud Pub/Sub topic that are eventually
processed by the event listener. GitHub has a
10 second webhook response time limit combined with a
5000 request/hour API rate limit, so this adds buffering
with the assumption that incoming events are bursty.
Setup
To set up your own instance of Contribute Bot for local testing or deployment:
- Create a new GCP project.
- Set your project using
gcloud config set project PROJECTID
, where
PROJECTID
is the project's ID.
- Download default application credentials with
gcloud auth application-default login
.
- Enable App Engine with
gcloud app create
.
- Copy the
prod
directory to a directory called dev
.
- In
dev/main.tf
, remove the backend "gcs"
block and change the project
IDs to your new GCP project.
- Run
terraform init
from the new dev
directory.
- Run
terraform apply
to set up the infrastructure.
- Deploy the webhook, creating a random webhook secret.
- Create the GitHub application, setting the webhook URL to
https://PROJECTID.appspot.com/webhook
, where PROJECTID
is your GCP
project ID.
- Set the
Webhook secret
to the random webhook secret you created above.
- Make sure to give Read & Write access to Issues, Pull Requests,
Checks, and Read-only access to Repository metadata.
- Subscribe to pull request and issue events.
- Download a GitHub application secret key and copy the contents into a new
Terraform variable file in the
dev
directory, setting the
github_app_key
variable. It's useful to use a "here doc". Then run
terraform apply
again to update the secret material. Your variable file
should look something like this:
contributebot/dev$ cat terraform.tfvars
github_app_key = <<EOF
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
EOF
Developing
To run Contribute Bot locally for testing:
- Create a GitHub repository for testing.
- Install the GitHub application on your test repository (
Settings > Developer Settings > Github Apps
, then Edit
your app and select Install App
).
- Download a GitHub application secret key for your test application.
- Run
contributebot
, setting the flags for your test GCP project and GitHub
application. You can find the App ID under About
on the Github page for
your app. Example:
go run . --project=your-project-name --github_app=42 --github_key=/foo.pem
Deploying
To production
To deploy an updated Contribute Bot to production, follow these steps.
# Build Docker image.
gcloud builds submit --config cloudbuild.yaml ../.. --project=go-cloud-contribute-bot
# Edit prod/k8s/contributebot.yaml and replace the image with the one
# you just created.
# Apply to cluster. Replace project and zone with the actual values.
gcloud container clusters get-credentials \
--project=go-cloud-contribute-bot \
--zone=us-central1-c \
contributebot-cluster
kubectl apply -f prod/k8s
# Send a PR with the updated .yaml file.
Somewhere else
If you want to deploy to your own cluster, modify k8s/contributebot.yaml
to
replace go-cloud-contribute-bot
with your own project ID, and 15206
with
your own Github App ID. Run the commands above, using your own project ID
in the command line arguments instead of go-cloud-contribute-bot
.