An app that listens to GitHub PR webhooks and parses out Trello ticket IDs so it can attach the PR to them. It was written in Go and uses the gin-tonic framework for routing and exception handling. Hosting should be on Heroku due to it being created from a starter boilerplate repo for it.
The app looks for a Trello ticket ID format (encoded string of 8 alphanumeric characters) in either the PR title or branch name.
In the PR title, the format must include square brackets around it such as [ticket ID] Fixed specs
. The ID can be parsed from any location in the title, not just the beginning.
The branch name must have the ID with either double dashes following it (ticketId--fixed-specs
) or a forward slash (ticketId/fixed-specs
). You may have additional content at the beginning of the branch name such as a prefix (teamName--ticketId--fixed-specs
).
- Go to a repository settings (
https://github.com/username/repo-name/settings
). - Go to Webhooks (
https://github.com/username/repo-name/settings/hooks
). - Click "Add webhook".
- Enter Payload URL of
https://your-host-name.herokuapp.com/webhook
. - Choose content type of
application/json
. - Generate a secret token in your terminal with
ruby -rsecurerandom -e 'puts SecureRandom.hex(20)'
. - Enter the output from the terminal into the Secret field. (Also save this token for later)
- Under "Which events would you like to trigger this webhook?", select "Let me select individual events."
- Check off "Pull requests" (and probably uncheck the default "Pushes")
- Submit the form and you're done with this step.
Save the secret you created for the webhook and set it as an environment variable, either in .env
locally or on the server as heroku config:set SECRET=token here
.
- Generate a set of credentials
- Set these as
TRELLO_KEY
andTRELLO_TOKEN
as environment variables.
You should be all setup and the app should run.
Make sure you have Go version 1.12 or newer and the Heroku Toolbelt installed.
$ git clone https://github.com/heroku/go-getting-started.git
$ cd go-getting-started
$ go build -o bin/card-linker -v .
github.com/mattn/go-colorable
gopkg.in/bluesuncorp/validator.v5
golang.org/x/net/context
github.com/heroku/x/hmetrics
github.com/gin-gonic/gin/render
github.com/manucorporat/sse
github.com/heroku/x/hmetrics/onload
github.com/gin-gonic/gin/binding
github.com/gin-gonic/gin
github.com/heroku/go-getting-started
$ heroku local
Your app should now be running on localhost:5000.
$ heroku create
$ git push heroku master
$ heroku open
- Secure request with hash
- Parse out ticket ID from branch
- Add more events like "edited"
This application started from the heroku Go boilerplate article Getting Started with Go on Heroku.