GitHub Integration
Squawk works as a CLI tool but can also create comments on GitHub PullRequests using theupload-to-github
subcommand.
Here's a screenshot of an example comment created bysquawk
using theexample.sql
in the repo:
https://github.com/sbdchd/squawk/pull/14#issuecomment-647009446
This document provides instructions for using the Squawk GitHub Action and using Squawk as GitHub App.
If you're using GitHub Actions, we recommend using thesquawk-action. If you're using Squawk outside of GitHub Actions, like on CircleCI for example, you should configure Squawk as aGitHub App.
#
Squawk GitHub ActionThis easiest way to integrate Squawk with GitHub is theSquawk GitHub Action.
For more information, see theSquawk GitHub Action documentation.
#
Custom GitHub ActionIf you want to make your own GitHub Action, you can call Squawk using the following code:
#
Squawk as a GitHub AppIf you use Squawk outside of a GitHub Actions, we recommend configuring Squawk as a GitHub App.
To use Squawk as a GitHub App, Squawk needs a corresponding GitHub App so it can talk to GitHub.
Create the app
head over tohttps://github.com/settings/apps/new
add an app name & homepage url
Uncheck the
active
checkbox under Webhookadd permissions
name kind why Pull Requests Write to comment on PRs hit create and copy the
App ID
under the "About" section. The page URL should be:https://github.com/settings/apps/$YOUR_APP_NAME
Head down the the bottom of the page under the "Private Keys" section andhit "Generate a private key"
The key should automatically download after a couple seconds. Hold onto this key, we'll need it later.
We now have an
App ID
and aPrivate Key
, which is everything we neeed to install the GitHub App.Install the GitHub App & get the Install ID
Head tohttps://github.com/settings/apps/$YOUR_APP_NAME/installations and click "Install"
GitHub should have redirected you to thehttps://github.com/settings/installations/$INSTALL_ID page where
$INSTALL_ID
is some number.Save this ID for later.
Now we have our
SQUAWK_GITHUB_APP_ID
,SQUAWK_GITHUB_PRIVATE_KEY
,SQUAWK_GITHUB_INSTALL_ID
.Squawk needs the pull request related values:
SQUAWK_GITHUB_REPO_NAME
,SQUAWK_GITHUB_REPO_OWNER
, andSQUAWK_GITHUB_PR_NUMBER
.Where to find these varies depending how you're running squawk, but for thenext step I'm assuming you're running Squawk as a CircleCI job.
Finding the Pull Request variables
#
CircleCIhttps://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
CIRCLE_PULL_REQUEST
has the content we needexample:
https://github.com/recipeyak/recipeyak/pull/567
Now we need to split this to get the repo name, repo owner, and pullrequeset id.
With a bit of help from
# extract org, repo, pr numberecho"https://github.com/recipeyak/recipeyak/pull/567"|awk -F/'{print$4 " "$5 " "$7}'recipeyak recipeyak567# store org, repo, and pr number in Squawk's variables.SQUAWK_GITHUB_REPO_OWNER=$(echo $CIRCLE_PULL_REQUEST|awk -F/'{print$4}')SQUAWK_GITHUB_REPO_NAME=$(echo $CIRCLE_PULL_REQUEST|awk -F/'{print$5}')SQUAWK_GITHUB_PR_NUMBER=$(echo $CIRCLE_PULL_REQUEST|awk -F/'{print$7}')Conclusion
Wrapping it all up we should have the following env vars:
SQUAWK_GITHUB_APP_ID=# fill in with id found in step 5SQUAWK_GITHUB_INSTALL_ID=# fill in with id found in step 7# downloaded via step 6, your key will have a different nameSQUAWK_GITHUB_PRIVATE_KEY=$(cat ./cool-bot-name.private-key.pem)# can also use the SQUAWK_GITHUB_PRIVATE_KEY_BASE64 instead ^SQUAWK_GITHUB_REPO_OWNER=$(echo $CIRCLE_PULL_REQUEST|awk -F/'{print$4}')SQUAWK_GITHUB_REPO_NAME=$(echo $CIRCLE_PULL_REQUEST|awk -F/'{print$5}')SQUAWK_GITHUB_PR_NUMBER=$(echo $CIRCLE_PULL_REQUEST|awk -F/'{print$7}')We can pass this into the env before running squawk or we can translatethem to the command line flag. Whatever's easiest for you.
An example run will look like the following (assuming the env vars are set):
squawk upload-to-github example.sqlwhich creates a comment like the following:
https://github.com/sbdchd/squawk/pull/14#issuecomment-647009446