Create a GitHub pull request after a successful Codeship build
I use Codeship to automate test builds whenever I commit to the development branch of my repo. If the build is successful, I manually merge the branch into my production branch, and Codeship deploys it to my CDN and production servers.
I wanted to skip the manual merge process and automate that step using pull requests. To do that, I added a custom deployment script on Codeship for my development branch. (Deployment scripts only fire if a test build is successful, as you might expect.)
This deployment script issues one curl request to GitHub's REST API, which creates the pull request for me.
curl --user "your_username:your_password" --request POST --data '{ "title": "Deploy build to production", "body": "Codeship test build was successful. Merge this pull request to push to production, or dismiss it to skip this build.", "head": "master", "base": "production" }' https://api.github.com/repos/repo_owner/repo_name/pulls
You can learn more about this API call from GitHub's API docs.
Now whenever a test build is successful, I can simply load up GitHub from anywhere, accept the pull request and deploy to my production servers. Easy peasy.
Written by Evan Sims
Related protips
1 Response
How to automatically merge the pull request?