Created
January 11, 2017 20:18
-
-
Save lekkas/0c3960117d49cbacd8ec07deed40fb08 to your computer and use it in GitHub Desktop.
PoC webhook integration
This file contains 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
Promise = require('bluebird') | |
_ = require('lodash') | |
express = require('express') | |
bodyParser = require('body-parser') | |
GithubApi = require('github') | |
Response = | |
state: [ 'success', 'error', 'failure' ] | |
description: [ 'Versionist passed!', 'Error: missing versionist conventions', 'Failed to apply versionist' ] | |
GithubApi({ Promise: Promise }) | |
github = new GithubApi() | |
github.authenticate | |
type: 'token' | |
token: process.env.TOKEN | |
app = express() | |
app.use(bodyParser.json()) | |
app.post '/payload', (req, res) -> | |
index = _.random(0, 2) | |
{ head } = req.body.pull_request | |
github.repos.createStatus | |
owner: head.user.login | |
repo: head.repo.name | |
sha: head.sha | |
state: Response.state[index] | |
description: Response.description[index] | |
context: 'versionist' | |
.then (data) -> | |
console.log 'state successfully set: ', data.state | |
res.sendStatus(200) | |
.catch (err) -> | |
console.log 'could not set status', err | |
app.listen 3000, -> | |
console.log 'listening on 3000' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment