Skip to content

Instantly share code, notes, and snippets.

@gdamjan
Created October 3, 2011 00:47
Show Gist options
  • Select an option

  • Save gdamjan/1258194 to your computer and use it in GitHub Desktop.

Select an option

Save gdamjan/1258194 to your computer and use it in GitHub Desktop.
CouchDB update function to collect data from the github POST hook
/*
see http://wiki.apache.org/couchdb/Document_Update_Handlers
in a couchapp this would be updates/new.js or something
you then setup githubs POST hook to this update function, something like:
http://hostname.example.net/database/_design/github/_update/new
see http://help.github.com/post-receive-hooks/
*/
function (_doc, req) {
if (req.method !== 'POST') {
return [null, 'only POST allowed']
}
if (!req.form && !req.form.payload) {
return [null, 'you must POST something']
}
var doc = JSON.parse(req.form.payload);
doc._id = req.uuid;
return [doc, 'ok'];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment