Skip to content

Instantly share code, notes, and snippets.

@tjfontaine
Created March 19, 2013 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjfontaine/623f36cebd6e3bdeec52 to your computer and use it in GitHub Desktop.
Save tjfontaine/623f36cebd6e3bdeec52 to your computer and use it in GitHub Desktop.
var gh = require('github')
function update(token, repos) {
var github = new gh({
version: "3.0.0",
//debug: true,
});
github.authenticate({
type: 'oauth',
token: token,
});
repos.forEach(function (repo) {
var s = repo.split('/');
var user = s[0];
var name = s[1];
github.repos.getHooks({
user: user,
repo: name,
}, function (err, result) {
var i, hook, found = [];
for (i in result) {
hook = result[i];
if (hook.name === 'web' && hook.config.url.match(/^http:\/\/jenkins.nodejs.org\/github/)) {
console.log(i, hook);
found.push(hook.id);
}
}
hook = found.pop();
if (hook) {
console.log('update hook', hook);
github.repos.updateHook({
user: user,
repo: name,
name: 'web',
id: hook,
config: {
url: 'http://jenkins.nodejs.org/github-webhook/',
content_type: 'json',
},
events: [
'push',
'issues',
'issue_comment',
'pull_request',
'pull_request_review_comment',
'commit_comment',
],
active: true,
}, function (err, res) {
console.log(res);
});
}
if (hook)
return;
});
});
}
var repos = [
'joyent/node',
'joyent/libuv',
];
//var GITHUBTOKEN = '';
//update(GITHUBTOKEN, repos);
var octOAuth = require('octoauth');
var oauth = new octOAuth({
username: SOMEUSERNAME,
password: SOMEPASSWORD,
})
oauth.scopes = ['public_repo'];
oauth.getToken(function (err, token) {
console.log('save this for script reuse -- octoauth token', token);
update(token, repos);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment