Last active
December 25, 2015 18:09
-
-
Save anaisbetts/7018565 to your computer and use it in GitHub Desktop.
Unsubscribe from all repos that you have not contributed to
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
#!/usr/bin/env ruby | |
require 'octokit' | |
pass_re = /^password: "(.*)"$/ | |
token = `security find-generic-password -s "GitHub API Token" -g 2>&1 | grep "password"`.match(pass_re)[1] | |
c = Octokit::Client.new(:access_token => token) | |
user_login = c.user.login | |
puts "Finding your mentions...\n" | |
notifications = 50.times.map {|x| c.notifications(:page => x+1)}.take_while {|x| x.count > 1}.inject([]) {|acc,x| acc.concat(x); acc} | |
repos = notifications.map {|x| x.repository.full_name}.sort.uniq | |
puts "Fetching contributors from #{repos.count} repos...\n" | |
contrib = repos.map {|x| [x, c.contributors(x)]} | |
to_unsub = contrib.select {|x| ! x[1].any? {|y| y[:login] == user_login } }.map {|x| x[0]} | |
if (ARGV[0] == "-f") | |
puts "Unsubscribing from #{to_unsub.count} repos..." | |
to_unsub.each {|x| puts x; c.delete_subscription(x) } | |
else | |
puts "\nYou should unsubscribe from:" | |
to_unsub.each {|x| puts x} | |
puts "\nRerun with -f to unsubscribe" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment