Skip to content

Instantly share code, notes, and snippets.

@digitaljhelms
Forked from wynst/README.MD
Created November 4, 2011 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digitaljhelms/1340205 to your computer and use it in GitHub Desktop.
Save digitaljhelms/1340205 to your computer and use it in GitHub Desktop.
A Thor Task to unwatch *all* Github watched repositories (excluding owned) and optionally export to delicious.

A Thor Task to unwatch all Github watched repositories (excluding owned) and optionally export to delicious.

Sorry Github, for I have sinned. I use the Watch feature as a bookmarker.

Install required gems:

gem install thor rest-client

Use it as such: # will not unwatch repo, only share repo bookmarks to delicious thor github:reset_watch --keep --share -d user:name pass:word --tags='watch repo github'

#yes, I'd rather code than manually unwatch my 129 repos.
require 'yaml'
require 'rubygems'
require 'restclient'
class Github < Thor
desc "reset_watch",
"reset watched repos (by unwatching all except owned) and export to delicious\n use --keep if you don't want to unwatch\n use --share if you want the delicious bookmark public."
method_options :keep => false,
:share => false,
:tags => "watch repo github",
%w( delicious -d ) => {}
def reset_watch
@gh_login = `git config --global --get github.user `.strip
@gh_token = `git config --global --get github.token`.strip
if @gh_login.empty? || @gh_token.empty?
puts "No Github Account.\nUpdate Github credentials from your github.com Account Settings"
return
end
res = RestClient.post "https://github.com/api/v2/yaml%s" %
("/repos/watched/%s" % @gh_login),
:login => @gh_login,
:token => @gh_token
#File.open('repo.yml','w') { |f| f.write(res) }
yml = YAML::load(res)
yml['repositories'].each do |repo|
if repo[:owner] == @gh_login
puts "repo: %s -- SKIP" % repo[:name]
next
end
puts "repo: %s" % repo[:name]
unless options[:delicious].empty?
puts " post to delicious.."
RestClient.post "https://%s:%s@api.del.icio.us/v1/posts/add?" %
[ options[:delicious]['user'], options[:delicious]['pass'] ],
:url => repo[:url],
:description => repo[:name],
:extended => repo[:description],
:tags => options[:tags],
:replace => 'yes',
:shared => (options.share? ? 'yes' : 'no')
end
unless options.keep?
sleep 1
puts " unwatching.."
RestClient.post "https://github.com/api/v2/yaml%s" %
("/repos/unwatch/%s/%s" % [ repo[:owner], repo[:name] ]),
:login => @gh_login,
:token => @gh_token
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment