Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/node
- var https = require('https');
- var token, username;
- var tenxer = 'tenxer';
- var shitsFucked = 0;
- var shitsUnfucked = 0;
- var reposCount = 0;
- process.argv.forEach(function (arg) {
- var args = arg.split('=');
- if (args[0] === '--token') {
- token = args[1];
- }
- if (args[0] === '--username') {
- username = args[1];
- }
- });
- if (!token || !username) {
- console.log("Need --username && --token");
- process.exit(1);
- }
- console.log('Unfucking your shit with token:', token);
- //Unfuck user
- var user = {login: username};
- request('GET', '/users/' + username + '/repos', null,
- function (resp) {
- unFuckRepo(user, resp);
- });
- //Get a list of your orgs.
- request('GET', '/user/orgs', null, function (resp) {
- var orgs = JSON.parse(resp)
- orgs.forEach(function (org) {
- console.log('Searching through org:', org.login);
- //Get a list of each repo for org.
- var path = '/orgs/' + org.login + '/repos';
- console.log('\n\n\npath', path);
- request('GET', path, null,
- function (resp) {
- unFuckRepo(org, resp);
- });
- });
- });
- function unFuckRepo(org, resp) {
- if (!resp) {
- return;
- }
- var repos = JSON.parse(resp);
- console.log('repos?', repos instanceof Array);
- if (!(repos instanceof Array)) {
- console.log('return');
- return
- }
- repos.forEach(function (repo) {
- //Get a list of hooks for each repo.
- console.log(org.login, '/', repo.name, ' count: ', ++reposCount);
- request('GET', '/repos/' + org.login + '/' + repo.name + '/hooks',
- null, function (hooks) {
- JSON.parse(hooks).forEach(function (hook) {
- if (hook.config && hook.config.url &&
- //Delete that fucker if it's from tenexer.
- hook.config.url.indexOf(tenxer) != -1) {
- console.log('url', hook.config.url);
- console.log('id', hook.id);
- console.log('shitsFucked:', ++shitsFucked);
- request('DELETE',
- ['/repos/', org.login, '/', repo.name, '/hooks/',
- hook.id].join(''),
- '', function (resp) {
- console.log('unfuck resp', resp);
- console.log('Shit unfucked:', ++shitsUnfucked);
- });
- }
- });
- });
- });
- };
- function request(method, path, data, callback) {
- var url = 'api.github.com';
- var headers = {
- 'Authorization': 'token ' + token,
- 'Content-Type': 'application/json',
- };
- if (data != null) {
- headers['Content-Type'] = 'application/json';
- headers['Content-Length'] = Buffer.byteLength(data,'utf8');
- }
- var options = {
- host: 'api.github.com',
- path: path,
- method: method
- };
- options.headers = headers;
- var request = https.request(options, function (res) {
- res.setEncoding('utf8');
- var chunks = [];
- res.on('data', function(chunk) {
- chunks.push(chunk);
- });
- res.on('end', function () {
- callback(chunks.join(''));
- });
- });
- request.on('error', function (err) {
- console.log('err', err);
- });
- data ? request.write(data) : request.write('');
- request.end();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement