Skip to content

Instantly share code, notes, and snippets.

@pbrisbin
Last active Dec 31, 2015
Embed
What would you like to do?
Show repos which you own but are not yourself watching.
#!/usr/bin/env ruby
#
# $ curl -o watchme.rb 'https://gist.github.com/pbrisbin/8030960/raw/watchme.rb'
# $ ruby ./watchme.rb
#
###
require 'json'
class GitHub
def initialize(username, password)
@username = username
@password = password
end
def repos
get_all(repos_url).map { |repo| repo['full_name'] }
end
def subscriptions
get_all(subscriptions_url).map { |repo| repo['full_name'] }
end
private
attr_reader :username, :password
def repos_url
user_json['repos_url']
end
def subscriptions_url
user_json['subscriptions_url']
end
def user_json
@user_json ||= get(user_url.sub('{user}', @username))
end
def user_url
root_json['user_url']
end
def root_json
@root_json ||= get('https://api.github.com')
end
def get_all(url, page = 1)
objects = get("#{url}?per_page=100&page=#{page}")
if objects.empty?
objects
else
objects + get_all(url, page + 1)
end
end
def get(url)
JSON.parse(`curl --silent -u '#{username}:#{password}' '#{url}'`)
end
end
begin
print "username: "
username = $stdin.gets.chomp
print "password: "
system("stty -echo") # hides pw as it's typed
password = $stdin.gets.chomp
ensure
system("stty echo")
puts
end
github = GitHub.new(username, password)
watchme = github.repos - github.subscriptions
if watchme.any?
puts "You own but are not watching the following:"
watchme.each do |repo|
puts "https://github.com/#{repo}"
end
else
puts "You're watching all your own repos. Nice."
end
@pbrisbin
Copy link
Author

pbrisbin commented Dec 18, 2013

Note: no error handling whatsoever, doesn't handle 2-factor auth, and may overflow (get_all is recursive) if you own or watch more than 100*STACK_MAX repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment