Andrew Yurisich a collection of things

Github Pull Request Statuses with

The free CICD site is a really useful, lightweight replacement for Jenkins for free, open source repositories. Being purpose built for just one thing means setting up a new project takes literally a tenth of the time compared to Jenkins.

But one thing it is lacking is the ability to run CICD tests against new pull requests that have had master merged into it first, and updating the status in the pull request while it’s doing that. Most Google searches for help will uncover forum posts with users requesting this feature, followed by promises from the team to get around to adding this functionality in “six to eight weeks”.

Fortunately, you can roll these things out yourself. Just follow these steps:

  • Create an OAuth Token from your github user profile.
  • You only need to enable the public_repo and repo:status scopes.
  • In your settings page, paste the token you got from github into the “Environment Variables” textbox.

For example: project settings page

  • Next, add some code that will allow you to replicate the behavior that is available in other CICD providers, such as TravisCI.
function postStatus {
  curl -so /dev/null -X POST -H "Authorization: token $OAUTH_TOKEN" -d "{\"state\": \"$1\", \"target_url\": \"$DRONE_BUILD_URL\", \"description\": \"Built and tested on\", \"context\": \"Built and tested on\"}"$DRONE_COMMIT;

postStatus pending
git merge master $DRONE_BRANCH
if [ $? -ne "0" ]; then
  echo "Unable to merge master..."
  postStatus error
  exit 1

Finally, add code for your specific project to actually do some testing. Here’s a simple example that you might use for a node app.

npm install --loglevel=warn
if [ $? -ne "0" ]; then
  postStatus error
  exit 1

npm test
if [ $? -eq "0" ]; then
  postStatus success
  postStatus failure

That’s it! Once your vanilla setup with is set up, everything else should just work.