-
-
Save JanDeDobbeleer/71180e7346573e2313480adf817f6107 to your computer and use it in GitHub Desktop.
GitHub Tools
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
XHUB_SECRET=your_secret | |
GITHUB_API_KEY=your_personal_access_token |
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
/*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}!`); | |
}); |
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
/*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; |
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
{ | |
"version": "0.2.0", | |
"configurations": [{ | |
"type": "node", | |
"request": "launch", | |
"name": "Launch Program", | |
"program": "${workspaceRoot}/${relativeFile}", | |
"envFile": "${workspaceRoot}/.env", | |
"cwd": "${workspaceRoot}" | |
}] | |
} |
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
{ | |
"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