This Flask app exposes a single endpoint /pull-request/ to be used as a GitHub webhook for
pull request events and
pull request review events
YouTrack tickets and pull requests are associated by git branch name. Branch names must exactly match YouTrack ticket ids.
Actions taken by the webhook:
- If the event payload
actionfield isreview_requested:- sets the ticket state to "Submitted"
- assigns the ticket to the first listed reviewer on the PR
- comments on the ticket with the url of the PR
- If the event payload
actionfield isclosedandpull_request[merged]is true:- sets the ticket state to "Ready to deploy"
- unassigns the ticket
- If the event payload
actionfield issubmittedandreview[state]is not "approved":- sets the ticket state to "Reopened"
- assigns the ticket back to the PR owner
See the config.json file.
The config requires 4 things:
- the YouTrack instance name
- a permanent YouTrack API access token
- a secret token used by GitHub to secure the webhook: see https://developer.github.com/webhooks/securing/
- a dictionary from GitHub logins to YouTrack usernames
If a config value is provided in the format "VAULT:path:key" in will be resolved by looking up the secret from vault.
The app runs inside a docker container and is mapped to port 4567 on the host machine. We currently have this deployed on support.montagu.dide.ic.ac.uk (see montagu-machine). To deploy:
- if already running, remove the container:
docker rm -f youtrack-integration pip3 install -r requirements.txt./run --use-vaultto first resolve secrets before running the app
To run tests :
pip3 install -r requirements-dev.txt --userpytest
On Buildkite:
./buildkite/test.shruns tests in a docker container./buildkite/build.shbuilds and pushes the docker image
The webhook can be added to a whole organisation or to a repository. For the mrc-ide org it will be most appropriate to only activate individual repositories.
- Go to
https://github.com/:org/:repo/settings/hooksorhttps://github.com/organizations/:org/settings/hooks - Click
Add Webhook - Payload URL is https://montagu.vaccineimpact.org/pull-request/
- Content type is
application/json - Secret from the vault as
vault read secret/youtrack-integration/github - Select "Let me select individual events" and select "Pull requests" and "Pull request reviews"
- Click the big green "Add webhook" button