This document should help you make sense of the codebase and provide guidance on working with it and testing it locally.
Directory structure:
migrations
sqlx
migrations that are the source of truth for database schema
src/bors
- Bors commands and their handlers.
src/database
- Database access layer built on top of
sqlx
.
- Database access layer built on top of
src/github
- Communication with the GitHub API and definitions of GitHub webhook messages.
The following diagram shows a simplified view on the important state entities of Bors. bors_process
handles events generated by webhooks. It uses a shared global state through BorsContext
, which holds a shared connection to the database and a command parser. It also has access to a map of repository state. Each repository state contains an API client for that repository, its loaded config, and permissions loaded from the Team API.
---
title: Important entities
---
flowchart
BorsContext
repo_client_1["GithubRepositoryClient"]
repo_client_2["GithubRepositoryClient"]
repo_state_1["RepositoryState"]
repo_state_2["RepositoryState"]
BorsContext --> repo_state_1 --> repo_client_1 --> repo1
BorsContext --> repo_state_2 --> repo_client_2 --> repo2
repo_state_1 --> cr1["Config (repo 1)"]
repo_state_1 --> pr1["Permissions (repo 1)"]
repo_state_2 --> cr2["Config (repo 2)"]
repo_state_2 --> pr2["Permissions (repo 2)"]
BorsContext --> db[(Database)]
bors_process --> BorsContext
Bors has a cargo
test suite that you can run locally, but sometimes nothing beats an actual test on live, GitHub
repositories. Sadly, the process is currently quite involved, but it can still be done if needed.
Note: we will eventually configure bors to have a staging environment e.g. at https://github.com/rust-lang/bors-kindergarten, however this is not configured yet.
One-time setup:
- Create your own GitHub app.
- Configure its webhook secret.
- Configure its private key.
- Give it permissions for
Actions
(r/w),Checks
(r),Commit statuses
(r),Contents
(r/w),Issues
(r/w) andPull requests
(r/w). - Subscribe it to webhook events
Check suite
,Check run
,Issue comment
,Issues
,Pull request
,Pull request review
,Pull request review comment
andWorkflow run
.
- Install your GitHub app on some test repository where you want to test bors.
- Don't forget to configure
rust-bors.toml
in the root of the repository, and also some CI checks.
- Don't forget to configure
Everytime you want to run bors:
- Run bors locally.
- Set
APP_ID
to the ID of the app - Set
WEBHOOK_SECRET
to the webhook secret of the app. - Set
PRIVATE_KEY
to the private key of the app.
- Set
- Set up some globally reachable URL/IP address for your computer, e.g. using ngrok.
- Configure the webhook URL for your app to point to
<address>/github
.
- Configure the webhook URL for your app to point to
- Try
@bors ping
on some PR on the test repository :)
You must have sqlx-cli
installed for the following commands to work.
$ cargo install sqlx-cli@0.7.4 --no-default-features --features native-tls,postgres
The database can be set up with the docker-compose file in the root of the repository:
$ docker-compose up -d
Then, set the DATABASE_URL
environment variable to the connection string of the database.
The content of the variable is can be found in the .env.example
file.
If an .env
file is present, the environment variable listed in it will be picked up automatically by sqlx
.
$ export DATABASE_URL=postgres://bors:bors@localhost:5432/bors
Having the database up and running, with the DATABASE_URL
set, is required to run the tests.
Make sure to also run cargo sqlx migrate run
to apply the migrations to the database.
- Generate a new migration
$ cargo sqlx migrate add <new-migration>
- Change the migration manually in
migrations/<timestamp>-<new-migration>.sql
. - Apply migrations to the Postgre DB.
$ cargo sqlx migrate run
$ cargo sqlx prepare -- --tests
After that, you should commit the changes to the .sqlx
directory.
By default, logs are disabled in tests. To enable them, add #[traced_test]
on top of the test function.