Created
January 26, 2017 23:06
-
-
Save robbiet480/2f095c910e56255c412d850400e90b07 to your computer and use it in GitHub Desktop.
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
// Delete webhooks created by Real Artists Ship | |
// Author: Robbie Trencheny | |
// License: MIT | |
// Run npm install github first | |
// Must set GITHUB_TOKEN environment variable | |
var GitHubApi = require("github"); | |
var github = new GitHubApi(); | |
github.authenticate({ | |
type: "oauth", | |
token: process.env.GITHUB_TOKEN | |
}); | |
var allRepos = []; | |
var req = github.repos.getAll({ per_page: 100}, getRepos); | |
function getRepos(err, res) { | |
if (err) { | |
return false; | |
} | |
allRepos = allRepos.concat(res); | |
if (github.hasNextPage(res)) { | |
github.getNextPage(res, getRepos) | |
} else { | |
getHooks(); | |
} | |
} | |
function getHooks() { | |
allRepos.forEach(function(repo){ | |
github.repos.getHooks({ | |
owner: repo.owner.login, | |
repo: repo.name, | |
per_page: 100 | |
}, function(err, hooks){ | |
if(err) { | |
console.error('Error when getting hooks for repo', repo.full_name, Error(err)); | |
return | |
} | |
console.log('Processing repo', repo.full_name, repo.id) | |
var badUrl = 'https://hub.realartists.com/webhook/repo/'+repo.id; | |
hooks.forEach(function(hook){ | |
if(hook.config && hook.config.url && hook.config.url == badUrl) { | |
console.log('Found bad hook'); | |
github.repos.deleteHook({ | |
owner: repo.owner.login, | |
repo: repo.name, | |
id: hook.id | |
}, function(err, ress){ | |
if(err) { | |
console.error('Error when deleting bad hook for', repo.full_name, Error(err)); | |
return | |
} | |
console.log('Deleted bad hook from', repo.full_name); | |
}); | |
} | |
}); | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment