Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 106 lines (94 sloc) 4.955 kB
b996880 @cldwalker updated libs to use new naming scheme, tweaked pstore
authored
1 module Github
0e6b169 @cldwalker arg + github cmd tweaks
authored
2 def self.included(mod)
3 require 'cgi'
4 end
5
5ac1b94 @cldwalker cmd tweaks
authored
6 # @render_options :fields=>{:default=>[:name, :watchers, :forks, :homepage, :description, :url],
99ea086 @cldwalker updated user_repos field
authored
7 # :values=>[:homepage, :name, :forks, :private, :watchers, :fork, :url, :description, :owner, :open_issues, :created_at, :pushed_at]},
5ac1b94 @cldwalker cmd tweaks
authored
8 # :max_fields=>{:default=>{:homepage=>0.2, :url=>0.1} }
8d8491f @cldwalker option descriptions for public cmds
authored
9 # @options :user=>{:default=>'cldwalker', :desc=>'Github user' },
27230fe @cldwalker add interesting opt to user_repos cmd
authored
10 # [:forks,:F]=>{:type=>:boolean, :desc=>'Display forked repositories'},
11 # :interesting => {:type => :boolean, :desc => 'Display all repositories except for unpopular forks'}
710e5d9 @cldwalker menu tweaks + moving github menu config into lib itself
authored
12 # @config :menu=>{:command=>:browser, :default_field=>:url}
a3698e8 @cldwalker github tweaks
authored
13 # Displays a user's repositories
14 def user_repos(options={})
6981751 @cldwalker more github apis, whoop
authored
15 repos = github_get("/repos/show/#{options[:user]}")['repositories']
506d4f8 @cldwalker github + pastie tweaks with latest boson tweaks
authored
16 return puts("Invalid user '#{options[:user]}'") unless repos
27230fe @cldwalker add interesting opt to user_repos cmd
authored
17 if options[:forks]
18 repos
19 elsif options[:interesting]
20 forks, originals = repos.partition {|e| e[:fork] }
21 originals + forks.select {|e| e[:watchers] > 3 }
22 else
23 repos.select {|e| ! e[:fork] }
24 end
7bbcc0e @cldwalker added github + httparty libs
authored
25 end
2ecea42 @cldwalker more gem method tweaks, added github issues commands
authored
26
cfb2930 @cldwalker menu-based gist, whoop
authored
27 # @render_options :fields=>[:repo, :description, :created_at]
28 # @options :user=>{:default=>'cldwalker', :desc=>'Github user'}
710e5d9 @cldwalker menu tweaks + moving github menu config into lib itself
authored
29 # @config :menu=>{:template=>'http://gist.github.com/:repo', :command=>:browser}
cfb2930 @cldwalker menu-based gist, whoop
authored
30 # Displays a user's gists
31 def user_gists(options={})
056471c @cldwalker updated for latest boson
authored
32 gists = get("http://gist.github.com/api/v1/yaml/gists/#{options[:user]}", :parse=>true)['gists']
cfb2930 @cldwalker menu-based gist, whoop
authored
33 gists || puts("Invalid user '#{options[:user]}'")
34 end
35
e06860c @cldwalker strings to symbols api change
authored
36 # @render_options :fields=>{:values=>[:score, :name, :size, :language, :followers, :type,
37 # :username, :id, :description, :forks, :fork, :pushed, :created], :default=>[:name, :username,
38 # :followers, :language, :pushed, :score, :description]}, :sort=>'score', :reverse_sort=>true
699934f @cldwalker more github menu tweaks
authored
39 # @config :menu=>{:command=>:browser, :template=>'http://github.com/:username/:name'}
ead0ad2 @cldwalker updated repo search with newer api
authored
40 # @options :page=>1, :language=>:string
a3698e8 @cldwalker github tweaks
authored
41 # Search repositories
ead0ad2 @cldwalker updated repo search with newer api
authored
42 def repo_search(query, options={})
43 github_get("/repos/search/#{CGI.escape(query)}?start_page=#{options[:page]}&language=#{options[:language]}")['repositories']
2ecea42 @cldwalker more gem method tweaks, added github issues commands
authored
44 end
a3698e8 @cldwalker github tweaks
authored
45
46 # @render_options :fields=>{:values=>[:homepage, :name, :watchers, :private, :forks, :fork, :url, :description, :owner, :open_issues],
5ac1b94 @cldwalker cmd tweaks
authored
47 # :default=>[:owner, :watchers, :forks, :homepage, :description, :url]}, :max_fields=>{:default=>{:url=>0.15}}
8d8491f @cldwalker option descriptions for public cmds
authored
48 # @options :user=>{:default=>'cldwalker', :desc=>'Github user'}
710e5d9 @cldwalker menu tweaks + moving github menu config into lib itself
authored
49 # @config :menu=>{:command=>:browser, :default_field=>:url}
a3698e8 @cldwalker github tweaks
authored
50 # Displays network of a given user-repo i.e. wycats-thor or defunkt/rip
51 def repo_network(user_repo, options={})
9ae7e11 @cldwalker added repo_watchers for new github api call
authored
52 github_get("/repos/show/#{filter_user_repo(user_repo, options)}/network")['network']
6981751 @cldwalker more github apis, whoop
authored
53 end
54
55 # @render_options :fields=>{:values=>["score", "name", "language", "followers", "type", "fullname",
56 # "username", "id", "repos", "pushed", "created", "location"], :default=>['name', 'followers', 'repos',
57 # 'pushed', 'language', 'location', 'score']}
710e5d9 @cldwalker menu tweaks + moving github menu config into lib itself
authored
58 # @config :menu=>{:command=>:browser, :template=>'http://github.com/:name'}
6981751 @cldwalker more github apis, whoop
authored
59 # Search users
60 def user_search(query)
0e6b169 @cldwalker arg + github cmd tweaks
authored
61 github_get("/user/search/#{CGI.escape(query)}")['users']
6981751 @cldwalker more github apis, whoop
authored
62 end
63
64 # td: /commits/list/:user_id/:repository/:branch/*path
65 # @render_options :fields=>{:values=>%w{id url committed_date authored_date message},
5ac1b94 @cldwalker cmd tweaks
authored
66 # :default=>%w{id authored_date message url}}, :max_fields=>{:default=>{'url'=>0.1}}
ffc13ef @cldwalker commit_list tweak
authored
67 # @options :branch=>{:default=>'master', :desc=>'Git repo branch'},
68 # :user=>{:default=>'cldwalker', :desc=>'Github user'}
710e5d9 @cldwalker menu tweaks + moving github menu config into lib itself
authored
69 # @config :menu=>{:command=>:browser, :default_field=>'url'}
6981751 @cldwalker more github apis, whoop
authored
70 # List commits of a given user-repo
71 def commit_list(user_repo, options={})
9ae7e11 @cldwalker added repo_watchers for new github api call
authored
72 github_get("/commits/list/#{filter_user_repo(user_repo, options)}/#{options[:branch]}")['commits']
6981751 @cldwalker more github apis, whoop
authored
73 end
74
75 # @render_options :fields=>{:values=>[:owner, :homepage, :open_issues, :name, :url, :private,
76 # :fork, :watchers, :description, :forks], :default=>[:name, :owner, :watchers, :forks, :description]}
699934f @cldwalker more github menu tweaks
authored
77 # @config :menu=>{:command=>:browser, :template=>'http://github.com/:owner/:name'}
6981751 @cldwalker more github apis, whoop
authored
78 # Lists repos watched by user
79 def repos_watched(user)
80 github_get("/repos/watched/#{user}")['repositories'].select {|e| e[:owner] != user }
81 end
82
83 # @render_options {}
9ae7e11 @cldwalker added repo_watchers for new github api call
authored
84 # @options :user=>{:default=>'cldwalker', :desc=>'Github user'}
85 # Lists a repo's watchers
86 def repo_watchers(user_repo, options={})
87 github_get("/repos/show/#{filter_user_repo(user_repo, options)}/watchers")['watchers']
88 end
89
90 # @render_options {}
710e5d9 @cldwalker menu tweaks + moving github menu config into lib itself
authored
91 # @config :menu=>{:command=>:browser, :template=>'http://github.com/:to_s'}
6981751 @cldwalker more github apis, whoop
authored
92 # List users a user follows
93 def user_follows(user)
94 github_get("/user/show/#{user}/following")['users']
a3698e8 @cldwalker github tweaks
authored
95 end
96
c9e8647 @cldwalker adding some render opts, github tweaks
authored
97 private
9ae7e11 @cldwalker added repo_watchers for new github api call
authored
98 def filter_user_repo(user_repo, options)
99 user_repo['/'] ? user_repo : "#{options[:user]}/#{user_repo}"
100 end
101
cfb2930 @cldwalker menu-based gist, whoop
authored
102 def github_get(url)
5b2c19a @cldwalker github fix
authored
103 get("http://github.com/api/v2/yaml#{url}", :parse=>true) || {}
cfb2930 @cldwalker menu-based gist, whoop
authored
104 end
50f0eb9 @cldwalker cmd tweaks
authored
105 end
Something went wrong with that request. Please try again.