GitHub Tools
/*jshint esversion: 6*/ | |
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var xhub = require('express-x-hub'); | |
var github = require('./modules/github'); | |
var app = express(); | |
// settings | |
app.use(xhub({ algorithm: 'sha1', secret: process.env.XHUB_SECRET })); | |
app.use(bodyParser.json()); // for parsing application/json | |
var port = process.env.PORT || 3000; | |
app.get('/', function(req, res) { | |
res.send('hello world'); | |
}); | |
app.post('/github-hook', function(req, res) { | |
res.status(200).end(); | |
console.log(req.body); | |
}); | |
app.listen(port, function() { | |
console.log(`App listening on port ${port}!`); | |
}); |
/*jshint esversion: 6*/ | |
var github = require('octonode'); | |
function GitHub() {}; | |
GitHub.setCommitStatus = function(repo_name, sha, state, description, context) { | |
var ghrepo = github.client(process.env.GITHUB_API_KEY).repo(repo_name); | |
ghrepo.status(sha, { | |
"state": state, | |
"description": description, | |
"context": context | |
}, function(err, data, headers) { | |
if (err) { | |
console.log("error: " + err); | |
console.log("data: " + data); | |
console.log("headers:" + headers); | |
return; | |
} | |
console.log('Commit status successfully set'); | |
}); | |
}; | |
module.exports = GitHub; |
{ | |
"version": "0.2.0", | |
"configurations": [{ | |
"type": "node", | |
"request": "launch", | |
"name": "Launch Program", | |
"program": "${workspaceRoot}/${relativeFile}", | |
"envFile": "${workspaceRoot}/.env", | |
"cwd": "${workspaceRoot}" | |
}] | |
} |
{ | |
"name": "github-tools", | |
"version": "1.0.0", | |
"description": "API tools to interact with GitHub", | |
"main": "app.js", | |
"author": "Jan De Dobbeleer <jan.de.dobbeleer@gmail.com>", | |
"license": "MIT", | |
"dependencies": { | |
"body-parser": "^1.17.2", | |
"express": "^4.15.4", | |
"express-x-hub": "^1.0.4", | |
"octonode": "^0.8.0" | |
}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "node app.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment