Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

WebHooks With Google

DZone's Guide to

WebHooks With Google

Check out this post, and learn from Gervais' experience with exposing Google App Script to use it as a WebHook pipe.

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software


Edit (July 13 2016), this Codeship-Bitbukcet integration is native since July 12 2016, https://community.codeship.com/t/now-available-bitbucket-build-status-api/1135



Introduction

I'm sure that you haven't missed the "Google App Script". 

Google Apps Script is a scripting language based on JavaScript that lets you do new and cool things with Google Apps like Docs, Sheets, and Forms. There's nothing to install — we give you a code editor right in your browser, and your scripts run on Google's servers. [1]

I have to admit that I didn't see the awesomeness of this system until a couple of days ago. At least, it is really helpful because it can of course do "cool things with Google Apps" but it can also be exposed as webapp and send HTTP requests. So, yes, it can be used as a WebHook pipe.

A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST...A Pipe happens when your WebHook not oinly receives real-time data, but goes on to do something new and meaningful with it, triggering actions unrelated to the original events. [2]

These are the kinds of recipes I was expecting from IFTTT without success.

Hacking Google Apps Script

Some of my projects (you know, the ones that will make me rich!) are hosted on Bitbucket and built by Codeship. Both work great, but there is no native build status integration between Codeship and Bitbucket. There are some tentatives, but they are not natively integrated into the Bitbucket UI.

So, I decided to use Google Apps Script to create a script who will receive the Codeship POST when a build status changes and call the Bitbucket API to update the build status.

The idea is quite simple and the documentation is clear on both sides [3][4] and, fortunately, Bitbucket API is usable with Basic auth (thank god!). But debugging a Google Apps Script is not so easy, and it took me a while to guess why this "#$!&§" script was not working [5] . But, at the end it was simple and, as a bonus, I have a Google Sheet with the activity log.

Build status from Codeship in Bitbucker

The only alternative that I find is https://www.webscript.io/ but you have to learn "Lua" (that would be cool) and there is only a free trial limited in time. So, once again, Google offer a new, powerful, and free code hosting solution.

The script can be found under this gist: https://gist.github.com/gervaisb/206a3441b2ed454e81d5.js 

Sources:

[1] Google Apps Script :

 - https://developers.google.com/apps-script

 - https://developers.google.com/apps-script/guides/web

[2] WebHooks.org :

 - https://webhooks.pbworks.com/w/page/13385124/FrontPage

[3]  Bitbbucket REST API Version 2 :  
 - https://confluence.atlassian.com/bitbucket/version-2-423626329.html

[4]  Codeship WebHooks : 
 - https://codeship.com/documentation/integrations/webhooks/

[5] Effective way to debug a Google Apps Script Web App on Stackoverflow : 

 - http://stackoverflow.com/questions/11493643/effective-way-to-debug-a-google-apps-script-web-app

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
integration ,javascript ,webhooks

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}