Created
October 3, 2011 00:47
-
-
Save gdamjan/1258194 to your computer and use it in GitHub Desktop.
CouchDB update function to collect data from the github POST hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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