Skip to content

Instantly share code, notes, and snippets.

@pksunkara
Last active Mar 13, 2021
Embed
What would you like to do?
Delete github repo hooks
// TODO: Github Apps
const client = require('octonode').client(process.env.GITHUB_TOKEN);
const async = require('async');
const colors = require('colors');
const inquirer = require('inquirer');
const program = require('commander');
// TODO: Github Org
program
.version('0.1.0')
.parse(process.argv);
const ghme = client.me();
const hookQuestion = {
type: 'confirm',
name: 'remove',
message: 'Delete this hook?',
default: false,
};
ghme.repos({ per_page: 100, type: 'owner'}, (err, b, h) => {
if (err) console.log(err);
async.eachSeries(b, (repo, repocallback) => {
client.get(`/repos/${repo.full_name}/hooks`, (err, s, b, h) => {
if (err) console.log(err);
console.log((`${repo.full_name.cyan} has ${(b.length + '').yellow} hooks!`).bold);
async.eachSeries(b, (hook, hookcallback) => {
console.log(`${((hook.active ? 'Active '.green : 'Disabled '.red) + hook.name.magenta + ' hook!').bold}`);
console.log(hook.config);
inquirer.prompt([ hookQuestion ]).then(answers => {
if (answers.remove) {
client.del(`/repos/${repo.full_name}/hooks/${hook.id}`, {}, (err, s) => {
if (err) console.log(err);
if (s == 204) console.log('Successfully deleted this hook.'.green);
hookcallback();
});
} else {
hookcallback();
}
});
}, err => {
if (err) console.log(err);
repocallback();
});
});
}, err => {
if (err) console.log(err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment