daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Oct 20th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/local/bin/node
  2.  
  3. var https = require('https');
  4.  
  5. var token, username;
  6. var tenxer = 'tenxer';
  7. var shitsFucked = 0;
  8. var shitsUnfucked = 0;
  9.     var reposCount = 0;
  10. process.argv.forEach(function (arg) {
  11.   var args = arg.split('=');
  12.   if (args[0] === '--token') {
  13.     token = args[1];
  14.   }
  15.   if (args[0] === '--username') {
  16.     username = args[1];
  17.   }
  18. });
  19. if (!token || !username) {
  20.   console.log("Need --username && --token");
  21.   process.exit(1);
  22. }
  23. console.log('Unfucking your shit with token:', token);
  24. //Unfuck user
  25. var user = {login: username};
  26. request('GET', '/users/' + username + '/repos', null,
  27.   function (resp) {
  28.   unFuckRepo(user, resp);
  29. });
  30. //Get a list of your orgs.
  31. request('GET', '/user/orgs', null, function (resp) {
  32.   var orgs = JSON.parse(resp)
  33.   orgs.forEach(function (org) {
  34.     console.log('Searching through org:', org.login);
  35.     //Get a list of each repo for org.
  36.     var path = '/orgs/' + org.login + '/repos';
  37.     console.log('\n\n\npath', path);
  38.     request('GET', path, null,
  39.       function (resp) {
  40.         unFuckRepo(org, resp);
  41.       });
  42.   });
  43. });
  44.  
  45.  
  46.  
  47. function unFuckRepo(org, resp) {
  48.   if (!resp) {
  49.     return;
  50.   }
  51.   var repos = JSON.parse(resp);
  52.   console.log('repos?', repos instanceof Array);
  53.   if (!(repos instanceof Array)) {
  54.     console.log('return');
  55.     return
  56.   }
  57.   repos.forEach(function (repo) {
  58.   //Get a list of hooks for each repo.
  59.    console.log(org.login, '/', repo.name, ' count: ', ++reposCount);
  60.    request('GET', '/repos/' + org.login + '/' + repo.name + '/hooks',
  61.      null, function (hooks) {
  62.        JSON.parse(hooks).forEach(function (hook) {
  63.          if (hook.config && hook.config.url &&
  64.     //Delete that fucker if it's from tenexer.
  65.            hook.config.url.indexOf(tenxer) != -1) {
  66.            console.log('url', hook.config.url);
  67.            console.log('id', hook.id);
  68.            console.log('shitsFucked:', ++shitsFucked);
  69.            request('DELETE',
  70.              ['/repos/', org.login, '/', repo.name, '/hooks/',
  71.              hook.id].join(''),
  72.              '', function (resp) {
  73.                console.log('unfuck resp', resp);
  74.                console.log('Shit unfucked:',  ++shitsUnfucked);
  75.              });
  76.          }
  77.        });
  78.      });
  79.   });
  80. };
  81.  
  82. function request(method, path, data, callback) {
  83.   var url = 'api.github.com';
  84.   var headers = {
  85.     'Authorization': 'token ' + token,
  86.     'Content-Type': 'application/json',
  87.   };
  88.   if (data != null) {
  89.     headers['Content-Type'] = 'application/json';
  90.     headers['Content-Length'] = Buffer.byteLength(data,'utf8');
  91.   }
  92.   var options = {
  93.     host: 'api.github.com',
  94.     path: path,
  95.     method: method
  96.   };
  97.   options.headers = headers;
  98.   var request = https.request(options, function (res) {
  99.     res.setEncoding('utf8');
  100.     var chunks = [];
  101.     res.on('data', function(chunk) {
  102.       chunks.push(chunk);
  103.     });
  104.     res.on('end', function () {
  105.       callback(chunks.join(''));
  106.     });
  107.   });
  108.   request.on('error', function (err) {
  109.     console.log('err', err);
  110.   });
  111.   data ? request.write(data) : request.write('');
  112.   request.end();
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top