drnic-github 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,9 @@
1
+ == 0.1.4
2
+
3
+ * Added usage notes to commands. [topfunky]
4
+ * Added config option to set github.user and github.repo. [topfunky]
5
+ * Uses current user to automatically use SSH when cloning own projects.
6
+
7
+ == 0.1.3
8
+
9
+ * Original version
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2008 Chris Wanstrath
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,25 @@
1
+ History.txt
2
+ LICENSE
3
+ Manifest
4
+ README
5
+ Rakefile
6
+ bin/gh
7
+ bin/github
8
+ github.gemspec
9
+ lib/commands/commands.rb
10
+ lib/commands/helpers.rb
11
+ lib/commands/issues.rb
12
+ lib/commands/network.rb
13
+ lib/github.rb
14
+ lib/github/command.rb
15
+ lib/github/extensions.rb
16
+ lib/github/helper.rb
17
+ lib/github/ui.rb
18
+ setup.rb
19
+ spec/command_spec.rb
20
+ spec/extensions_spec.rb
21
+ spec/github_spec.rb
22
+ spec/helper_spec.rb
23
+ spec/spec_helper.rb
24
+ spec/ui_spec.rb
25
+ spec/windoze_spec.rb
data/README ADDED
@@ -0,0 +1,199 @@
1
+ The GitHub Gem
2
+ =============
3
+
4
+ This gem'll work hand-in-hand with GitHub's API to help you out.
5
+
6
+ Catch us in the #github room on freenode if you want to get involved. Or just fork and send a pull request.
7
+
8
+ ===========
9
+ Getting started
10
+ ===========
11
+
12
+ $ gem install defunkt-github -s http://gems.github.com
13
+
14
+ Run it:
15
+
16
+ $ github <command> <args>
17
+
18
+
19
+ =============
20
+ Pulling Upstream Changes
21
+ =============
22
+
23
+ Let's say you just forked `github-gem` on GitHub from defunkt.
24
+
25
+ $ github clone YOU/github-gem
26
+ $ cd github-gem
27
+ $ github pull defunkt
28
+
29
+ This will setup a remote and branch for defunkt's repository at master.
30
+ In this case, a 'defunkt/master' branch.
31
+
32
+ If defunkt makes some changes you want, simply `github pull defunkt`. This will
33
+ leave you in the 'defunkt/master' branch after pulling changes from defunkt's
34
+ remote. After confirming that defunkt's changes were what you wanted, run `git
35
+ checkout master` and then `git merge defunkt/master` to merge defunkt's changes
36
+ into your own master branch. In summary:
37
+
38
+ $ github pull defunkt
39
+ $ github checkout master
40
+ $ github merge defunkt/master
41
+
42
+ If you've already reviewed defunkt's changes and just want to merge them into your
43
+ master branch, use the `merge` flag:
44
+
45
+ $ github pull --merge defunkt
46
+
47
+
48
+ ==========
49
+ Fetching and Evaluating Downstream Changes
50
+ ==========
51
+
52
+ If you are the maintainer of a project, you will often need to fetch commits
53
+ from other developers, evaluate and/or test them, then merge them into the
54
+ project.
55
+
56
+ Let's say you are 'defunkt' and 'mojombo' has forked your 'github-gem' repo,
57
+ made some changes and issues you a pull request for his 'master' branch.
58
+
59
+ From the root of the project, you can do:
60
+
61
+ $ github fetch mojombo master
62
+
63
+ This will leave you in the 'mojombo/master' branch after fetching his commits.
64
+ Your local 'mojombo/master' branch is now at the exact same place as mojombo's
65
+ 'master' branch. You can now run tests or evaluate the code for awesomeness.
66
+
67
+ If mojombo's changes are good, you'll want to merge your 'master' (or another
68
+ branch) into those changes so you can retest post-integration:
69
+
70
+ $ github merge master
71
+
72
+ Test/analyze again and if everything is ok:
73
+
74
+ $ github checkout master
75
+ $ github merge mojombo/master
76
+
77
+ The latter command will be a fast-forward merge since you already did the
78
+ real merge previously.
79
+
80
+ ==========
81
+ Network Patch Queue
82
+ ==========
83
+
84
+ The github gem can also show you all of the commits that exist on any fork of your
85
+ project (your network) that you don't have in your branch yet. In order to see
86
+ the list of the projects that have commits you do not, you can run:
87
+
88
+ $ github network list
89
+
90
+ Which will show you all the forks that have changes. If you want to see what those
91
+ changes are, you can run:
92
+
93
+ $ github network commits
94
+
95
+ which will show you something like this:
96
+
97
+ 9582b9 (jchris/gist) kevin@sb.org Add gist binary 4 months ago
98
+ c1a6f9 (jchris/gist~1) kevin@sb.org Tweak Rakefile spec tasks to be a bi 4 months ago
99
+ d3c332 (jchris/gist~2) kevin@sb.org Pull out two helpers into the shared 4 months ago
100
+ 8f65ab (jchris/gist~3) kevin@sb.org Extract command/helper spec assistan 4 months ago
101
+ 389dbf (jchris/gist~4) kevin@sb.org Rename ui_spec to command_spec 4 months ago
102
+ 670a1a (jchris/gist~5) kevin@sb.org Hoist the specs into a per-binary sp 4 months ago
103
+ 6aa18e (jchris/gist~6) kevin@sb.org Hoist commands/helpers into a per-co 4 months ago
104
+ ee013a (luislavena/master) luislavena@gmail.com Replaced STDOUT by $stdout in specs. 2 weeks ago
105
+ d543c4 (luislavena/master~3) luislavena@gmail.com Exclude package folder. 8 weeks ago
106
+ a8c3eb (luislavena/master~5) luislavena@gmail.com Fixed specs for open under Windows. 5 months ago
107
+ 33d003 (riquedafreak/master) enrique.osuna@gmail. Make sure it exists on the remote an 5 weeks ago
108
+ 157155 (riquedafreak/master~1) enrique.osuna@gmail. Updated specs. 5 weeks ago
109
+ f44e99 (riquedafreak/master~3) enrique.osuna@gmail. Only work with a clean branch. 3 months ago
110
+
111
+ These are all the commits that you don't have in your current branch that have been
112
+ pushed to other forks of your project. If you want to incorporate them, you can use:
113
+
114
+ $ github cherry-pick ee013a
115
+
116
+ for example to apply that single patch to your branch. You can also merge a branch,
117
+ if you want all the changes introduced in another branch:
118
+
119
+ $ github merge jchris/gist
120
+
121
+ The next time you run the 'github network commits' command, you won't see any of the
122
+ patches you have cherry-picked or merged (or rebased). If you want to ignore a
123
+ commit, you can simply run:
124
+
125
+ $ github ignore a8c3eb
126
+
127
+ Then you won't ever see that commit again. Or, if you want to ignore a range of commits,
128
+ you can use the normal Git revision selection shorthands - for example, if you want
129
+ to ignore all 7 jchris/gist commits there, you can run:
130
+
131
+ $ github ignore ..jchris/gist
132
+
133
+ You can also filter the output, if you want to see some subset. You can filter by project,
134
+ author and date range, or (one of the cooler things) you can filter by whether the patch
135
+ applies cleanly to your branch head or not. For instance, I can do this:
136
+
137
+ $ ./bin/github network commits --applies
138
+
139
+ ca15af (jchris/master~1) jchris@grabb.it fixed github gemspecs broken referen 8 weeks ago
140
+ ee013a (luislavena/master) luislavena@gmail.com Replaced STDOUT by $stdout in specs. 2 weeks ago
141
+ 157155 (riquedafreak/master~1) enrique.osuna@gmail. Updated specs. 5 weeks ago
142
+ f44e99 (riquedafreak/master~3) enrique.osuna@gmail. Only work with a clean branch. 3 months ago
143
+
144
+ $ ./bin/github network commits --applies --project=riq
145
+
146
+ 157155 (riquedafreak/master~1) enrique.osuna@gmail. Updated specs. 5 weeks ago
147
+ f44e99 (riquedafreak/master~3) enrique.osuna@gmail. Only work with a clean branch. 3 months ago
148
+
149
+ Pretty freaking sweet. Also, you can supply the --shas option to just get a list of
150
+ the shas instead of the pretty printout here, so you can pipe that into other
151
+ scripts (like 'github ignore' for instance).
152
+
153
+
154
+ ==========
155
+ Issues
156
+ ==========
157
+
158
+ If you'd like to see a summary of the open issues on your project:
159
+
160
+ $ github issues open
161
+
162
+ -----
163
+ Issue #135 (2 votes): Remove Node#collect_namespaces
164
+ * URL: http://github.com/tenderlove/nokogiri/issues/#issue/135
165
+ * Opened 3 days ago by tenderlove
166
+ * Last updated about 1 hour ago
167
+
168
+ I think we should remove Node#collect_namespaces. Since namespace names are not unique, I don't know that this method is very useful.
169
+ -----
170
+ Issue #51 (0 votes): FFI: support varargs in error/exception callbacks
171
+ * URL: http://github.com/tenderlove/nokogiri/issues/#issue/51
172
+ * Opened 4 months ago by flavorjones
173
+ * Last updated about 1 month ago
174
+ * Labels: ffi, mdalessio
175
+
176
+ we should open JIRA tickets for vararg support in FFI callbacks
177
+
178
+ then we should format the libxml error messages properly in the error/exception callbacks
179
+ -----
180
+
181
+ If you want to additionally filter by time:
182
+
183
+ $ github issues open --after=2009-09-14
184
+
185
+ Or filter by label:
186
+
187
+ $ github issues open --label=ffi
188
+
189
+ ==========
190
+ Contributors
191
+ ==========
192
+
193
+ - defunkt
194
+ - maddox
195
+ - halorgium
196
+ - kballard
197
+ - mojombo
198
+ - schacon
199
+
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'echoe'
6
+
7
+ Echoe.new('github', '0.3.9') do |p|
8
+ p.rubyforge_name = 'github'
9
+ p.summary = "The official `github` command line helper for simplifying your GitHub experience."
10
+ p.description = "The official `github` command line helper for simplifying your GitHub experience."
11
+ p.url = "http://github.com/"
12
+ p.author = ['Chris Wanstrath', 'Kevin Ballard', 'Scott Chacon']
13
+ p.email = "chris@ozmm.org"
14
+ p.dependencies = ["text-format"]
15
+ end
16
+
17
+ rescue LoadError => boom
18
+ puts "You are missing a dependency required for meta-operations on this gem."
19
+ puts "#{boom.to_s.capitalize}."
20
+ end
21
+
22
+ # add spec tasks, if you have rspec installed
23
+ begin
24
+ require 'spec/rake/spectask'
25
+
26
+ Spec::Rake::SpecTask.new("spec") do |t|
27
+ t.spec_files = FileList['spec/**/*_spec.rb']
28
+ t.spec_opts = ['--color']
29
+ end
30
+
31
+ task :test do
32
+ Rake::Task['spec'].invoke
33
+ end
34
+
35
+ Spec::Rake::SpecTask.new("rcov_spec") do |t|
36
+ t.spec_files = FileList['spec/**/*_spec.rb']
37
+ t.spec_opts = ['--color']
38
+ t.rcov = true
39
+ t.rcov_opts = ['--exclude', '^spec,/gems/']
40
+ end
41
+ end
data/bin/gh ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
+ $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
5
+
6
+ require 'github'
7
+
8
+ GitHub.activate ARGV
data/bin/github ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
+ $LOAD_PATH.unshift lib_dir if File.directory?(lib_dir)
5
+
6
+ require 'github'
7
+
8
+ GitHub.activate ARGV
data/github.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{drnic-github}
5
+ s.version = "0.3.9"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Chris Wanstrath, Kevin Ballard, Scott Chacon"]
9
+ s.date = %q{2009-11-04}
10
+ s.description = %q{The official `github` command line helper for simplifying your GitHub experience.}
11
+ s.email = %q{chris@ozmm.org}
12
+ s.executables = ["gh", "github"]
13
+ s.extra_rdoc_files = ["LICENSE", "README", "bin/gh", "bin/github", "lib/commands/commands.rb", "lib/commands/helpers.rb", "lib/commands/issues.rb", "lib/commands/network.rb", "lib/github.rb", "lib/github/command.rb", "lib/github/extensions.rb", "lib/github/helper.rb", "lib/github/ui.rb"]
14
+ s.files = ["History.txt", "LICENSE", "Manifest", "README", "Rakefile", "bin/gh", "bin/github", "github.gemspec", "lib/commands/commands.rb", "lib/commands/helpers.rb", "lib/commands/issues.rb", "lib/commands/network.rb", "lib/github.rb", "lib/github/command.rb", "lib/github/extensions.rb", "lib/github/helper.rb", "lib/github/ui.rb", "setup.rb", "spec/command_spec.rb", "spec/extensions_spec.rb", "spec/github_spec.rb", "spec/helper_spec.rb", "spec/spec_helper.rb", "spec/ui_spec.rb", "spec/windoze_spec.rb"]
15
+ s.homepage = %q{http://github.com/}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Github", "--main", "README"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{github}
19
+ s.rubygems_version = %q{1.3.5}
20
+ s.summary = %q{The official `github` command line helper for simplifying your GitHub experience.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<text-format>, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<text-format>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<text-format>, [">= 0"])
33
+ end
34
+ end
@@ -0,0 +1,247 @@
1
+ desc "Open this repo's master branch in a web browser."
2
+ command :home do |user|
3
+ if helper.project
4
+ helper.open helper.homepage_for(user || helper.owner, 'master')
5
+ end
6
+ end
7
+
8
+ desc "Automatically set configuration info, or pass args to specify."
9
+ usage "github config [my_username] [my_repo_name]"
10
+ command :config do |user, repo|
11
+ user ||= ENV['USER']
12
+ repo ||= File.basename(FileUtils.pwd)
13
+ git "config --global github.user #{user}"
14
+ git "config github.repo #{repo}"
15
+ puts "Configured with github.user #{user}, github.repo #{repo}"
16
+ end
17
+
18
+ desc "Open this repo in a web browser."
19
+ usage "github browse [user] [branch]"
20
+ command :browse do |user, branch|
21
+ if helper.project
22
+ # if one arg given, treat it as a branch name
23
+ # unless it maches user/branch, then split it
24
+ # if two args given, treat as user branch
25
+ # if no args given, use defaults
26
+ user, branch = user.split("/", 2) if branch.nil? unless user.nil?
27
+ branch = user and user = nil if branch.nil?
28
+ user ||= helper.branch_user
29
+ branch ||= helper.branch_name
30
+ helper.open helper.homepage_for(user, branch)
31
+ end
32
+ end
33
+
34
+ desc 'Open the given user/project in a web browser'
35
+ usage 'github open [user/project]'
36
+ command :open do |arg|
37
+ helper.open "http://github.com/#{arg}"
38
+ end
39
+
40
+
41
+ desc "Info about this project."
42
+ command :info do
43
+ puts "== Info for #{helper.project}"
44
+ puts "You are #{helper.owner}"
45
+ puts "Currently tracking:"
46
+ helper.tracking.sort { |(a,),(b,)| a == helper.origin ? -1 : b == helper.origin ? 1 : a.to_s <=> b.to_s }.each do |(name,user_or_url)|
47
+ puts " - #{user_or_url} (as #{name})"
48
+ end
49
+ end
50
+
51
+ desc "Track another user's repository."
52
+ usage "github track remote [user]"
53
+ usage "github track remote [user/repo]"
54
+ usage "github track [user]"
55
+ usage "github track [user/repo]"
56
+ flags :private => "Use git@github.com: instead of git://github.com/."
57
+ flags :ssh => 'Equivalent to --private'
58
+ command :track do |remote, user|
59
+ # track remote user
60
+ # track remote user/repo
61
+ # track user
62
+ # track user/repo
63
+ user, remote = remote, nil if user.nil?
64
+ die "Specify a user to track" if user.nil?
65
+ user, repo = user.split("/", 2)
66
+ die "Already tracking #{user}" if helper.tracking?(user)
67
+ repo = @helper.project if repo.nil?
68
+ repo.chomp!(".git")
69
+ remote ||= user
70
+
71
+ if options[:private] || options[:ssh]
72
+ git "remote add #{remote} #{helper.private_url_for_user_and_repo(user, repo)}"
73
+ else
74
+ git "remote add #{remote} #{helper.public_url_for_user_and_repo(user, repo)}"
75
+ end
76
+ end
77
+
78
+ desc "Fetch all refs from a user"
79
+ command :fetch_all do |user|
80
+ GitHub.invoke(:track, user) unless helper.tracking?(user)
81
+ git "fetch #{user}"
82
+ end
83
+
84
+ desc "Fetch from a remote to a local branch."
85
+ command :fetch do |user, branch|
86
+ die "Specify a user to pull from" if user.nil?
87
+ user, branch = user.split("/", 2) if branch.nil?
88
+ branch ||= 'master'
89
+ GitHub.invoke(:track, user) unless helper.tracking?(user)
90
+
91
+ die "Unknown branch (#{branch}) specified" unless helper.remote_branch?(user, branch)
92
+ die "Unable to switch branches, your current branch has uncommitted changes" if helper.branch_dirty?
93
+
94
+ puts "Fetching #{user}/#{branch}"
95
+ git "fetch #{user} #{branch}:refs/remotes/#{user}/#{branch}"
96
+ git "update-ref refs/heads/#{user}/#{branch} refs/remotes/#{user}/#{branch}"
97
+ git_exec "checkout #{user}/#{branch}"
98
+ end
99
+
100
+ desc "Pull from a remote."
101
+ usage "github pull [user] [branch]"
102
+ flags :merge => "Automatically merge remote's changes into your master."
103
+ command :pull do |user, branch|
104
+ die "Specify a user to pull from" if user.nil?
105
+ user, branch = user.split("/", 2) if branch.nil?
106
+
107
+ if !helper.network_members.include?(user)
108
+ git_exec "#{helper.argv.join(' ')}".strip
109
+ return
110
+ end
111
+
112
+ branch ||= 'master'
113
+ GitHub.invoke(:track, user) unless helper.tracking?(user)
114
+
115
+ die "Unable to switch branches, your current branch has uncommitted changes" if helper.branch_dirty?
116
+
117
+ if options[:merge]
118
+ git_exec "pull #{user} #{branch}"
119
+ else
120
+ puts "Switching to #{user}-#{branch}"
121
+ git "fetch #{user}"
122
+ git_exec "checkout -b #{user}/#{branch} #{user}/#{branch}"
123
+ end
124
+ end
125
+
126
+ desc "Clone a repo. Uses ssh if current user is "
127
+ usage "github clone [user] [repo] [dir]"
128
+ flags :ssh => "Clone using the git@github.com style url."
129
+ flags :search => "Search for [user|repo] and clone selected repository"
130
+ command :clone do |user, repo, dir|
131
+ die "Specify a user to pull from" if user.nil?
132
+ if options[:search]
133
+ query = [user, repo, dir].compact.join(" ")
134
+ data = JSON.parse(open("http://github.com/api/v1/json/search/#{URI.escape query}").read)
135
+ if (repos = data['repositories']) && !repos.nil? && repos.length > 0
136
+ repos = repos.map { |r| "#{r['username']}/#{r['name']}"}.sort.uniq
137
+ if user_repo = GitHub::UI.display_select_list(repos)
138
+ user, repo = user_repo.split('/', 2)
139
+ end
140
+ end
141
+ die "Perhaps try another search" unless user && repo
142
+ end
143
+
144
+ if user.include?('/') && !user.include?('@') && !user.include?(':')
145
+ die "Expected user/repo dir, given extra argument" if dir
146
+ (user, repo), dir = [user.split('/', 2), repo]
147
+ end
148
+
149
+ if repo
150
+ if options[:ssh] || current_user?(user)
151
+ git_exec "clone git@github.com:#{user}/#{repo}.git" + (dir ? " #{dir}" : "")
152
+ else
153
+ git_exec "clone git://github.com/#{user}/#{repo}.git" + (dir ? " #{dir}" : "")
154
+ end
155
+ else
156
+ git_exec "#{helper.argv.join(' ')}".strip
157
+ end
158
+ end
159
+
160
+ desc "Generate the text for a pull request."
161
+ usage "github pull-request [user] [branch]"
162
+ command 'pull-request' do |user, branch|
163
+ if helper.project
164
+ die "Specify a user for the pull request" if user.nil?
165
+ user, branch = user.split('/', 2) if branch.nil?
166
+ branch ||= 'master'
167
+ GitHub.invoke(:track, user) unless helper.tracking?(user)
168
+
169
+ git_exec "request-pull #{user}/#{branch} #{helper.origin}"
170
+ end
171
+ end
172
+
173
+ desc "Create a new, empty GitHub repository"
174
+ usage "github create [repo]"
175
+ flags :markdown => 'Create README.markdown'
176
+ flags :mdown => 'Create README.mdown'
177
+ flags :textile => 'Create README.textile'
178
+ flags :rdoc => 'Create README.rdoc'
179
+ flags :rst => 'Create README.rst'
180
+ flags :private => 'Create private repository'
181
+ command :create do |repo|
182
+ sh "curl -F 'repository[name]=#{repo}' -F 'repository[public]=#{!options[:private]}' -F 'login=#{github_user}' -F 'token=#{github_token}' http://github.com/repositories"
183
+ mkdir repo
184
+ cd repo
185
+ git "init"
186
+ extension = options.keys.first
187
+ touch extension ? "README.#{extension}" : "README"
188
+ git "add *"
189
+ git "commit -m 'First commit!'"
190
+ git "remote add origin git@github.com:#{github_user}/#{repo}.git"
191
+ git_exec "push origin master"
192
+ end
193
+
194
+ desc "Forks a GitHub repository"
195
+ usage "github fork"
196
+ usage "github fork [user]/[repo]"
197
+ command :fork do |user, repo|
198
+ if repo.nil?
199
+ if user
200
+ user, repo = user.split('/')
201
+ else
202
+ unless helper.remotes.empty?
203
+ is_repo = true
204
+ user = helper.owner
205
+ repo = helper.project
206
+ else
207
+ die "Specify a user/project to fork, or run from within a repo"
208
+ end
209
+ end
210
+ end
211
+
212
+ sh "curl -F 'login=#{github_user}' -F 'token=#{github_token}' http://github.com/#{user}/#{repo}/fork"
213
+
214
+ url = "git@github.com:#{github_user}/#{repo}.git"
215
+ if is_repo
216
+ git "config remote.origin.url #{url}"
217
+ puts "#{user}/#{repo} forked"
218
+ else
219
+ puts "Giving GitHub a moment to create the fork..."
220
+ sleep 3
221
+ git_exec "clone #{url}"
222
+ end
223
+ end
224
+
225
+ desc "Create a new GitHub repository from the current local repository"
226
+ flags :private => 'Create private repository'
227
+ command 'create-from-local' do
228
+ cwd = sh "pwd"
229
+ repo = File.basename(cwd)
230
+ is_repo = !git("status").match(/fatal/)
231
+ raise "Not a git repository. Use gh create instead" unless is_repo
232
+ sh "curl -F 'repository[name]=#{repo}' -F 'repository[public]=#{!options[:private].inspect} -F 'login=#{github_user}' -F 'token=#{github_token}' http://github.com/repositories"
233
+ git "remote add origin git@github.com:#{github_user}/#{repo}.git"
234
+ git_exec "push origin master"
235
+ end
236
+
237
+ desc "Search GitHub for the given repository name."
238
+ usage "github search [query]"
239
+ command :search do |query|
240
+ die "Usage: github search [query]" if query.nil?
241
+ data = JSON.parse(open("http://github.com/api/v1/json/search/#{URI.escape query}").read)
242
+ if (repos = data['repositories']) && !repos.nil? && repos.length > 0
243
+ puts repos.map { |r| "#{r['username']}/#{r['name']}"}.sort.uniq
244
+ else
245
+ puts "No results found"
246
+ end
247
+ end