drnic-github 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +15 -0
- data/Manifest +14 -2
- data/Rakefile +5 -2
- data/github.gemspec +9 -6
- data/lib/commands/commands.rb +8 -6
- data/lib/commands/helpers.rb +19 -0
- data/lib/github/ui.rb +7 -2
- data/spec/commands/command_browse_spec.rb +36 -0
- data/spec/commands/command_clone_spec.rb +87 -0
- data/spec/commands/command_create-from-local_spec.rb +7 -0
- data/spec/commands/command_fetch_spec.rb +56 -0
- data/spec/commands/command_fork_spec.rb +44 -0
- data/spec/commands/command_helper.rb +170 -0
- data/spec/commands/command_home_spec.rb +20 -0
- data/spec/commands/command_info_spec.rb +23 -0
- data/spec/commands/command_network_spec.rb +21 -0
- data/spec/commands/command_pull-request_spec.rb +51 -0
- data/spec/commands/command_pull_spec.rb +82 -0
- data/spec/commands/command_search_spec.rb +34 -0
- data/spec/commands/command_track_spec.rb +82 -0
- data/spec/commands_spec.rb +49 -0
- data/spec/helper_spec.rb +16 -0
- metadata +28 -5
- data/spec/ui_spec.rb +0 -700
data/History.txt
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
== 0.3.10
|
2
|
+
|
3
|
+
* gh clone --search query -- now includes project descriptions
|
4
|
+
* bugfix
|
5
|
+
* added highline dependency
|
6
|
+
|
7
|
+
== 0.3.9
|
8
|
+
|
9
|
+
* gh clone --search query -- to search for a repo and then clone it
|
10
|
+
* fixed all the specs and started covering some commands that did not already have specs
|
11
|
+
|
12
|
+
== 0.3.X
|
13
|
+
|
14
|
+
* Some stuff done by some people
|
15
|
+
|
1
16
|
== 0.1.4
|
2
17
|
|
3
18
|
* Added usage notes to commands. [topfunky]
|
data/Manifest
CHANGED
@@ -5,7 +5,6 @@ README
|
|
5
5
|
Rakefile
|
6
6
|
bin/gh
|
7
7
|
bin/github
|
8
|
-
github.gemspec
|
9
8
|
lib/commands/commands.rb
|
10
9
|
lib/commands/helpers.rb
|
11
10
|
lib/commands/issues.rb
|
@@ -17,9 +16,22 @@ lib/github/helper.rb
|
|
17
16
|
lib/github/ui.rb
|
18
17
|
setup.rb
|
19
18
|
spec/command_spec.rb
|
19
|
+
spec/commands/command_browse_spec.rb
|
20
|
+
spec/commands/command_clone_spec.rb
|
21
|
+
spec/commands/command_create-from-local_spec.rb
|
22
|
+
spec/commands/command_fetch_spec.rb
|
23
|
+
spec/commands/command_fork_spec.rb
|
24
|
+
spec/commands/command_helper.rb
|
25
|
+
spec/commands/command_home_spec.rb
|
26
|
+
spec/commands/command_info_spec.rb
|
27
|
+
spec/commands/command_network_spec.rb
|
28
|
+
spec/commands/command_pull-request_spec.rb
|
29
|
+
spec/commands/command_pull_spec.rb
|
30
|
+
spec/commands/command_search_spec.rb
|
31
|
+
spec/commands/command_track_spec.rb
|
32
|
+
spec/commands_spec.rb
|
20
33
|
spec/extensions_spec.rb
|
21
34
|
spec/github_spec.rb
|
22
35
|
spec/helper_spec.rb
|
23
36
|
spec/spec_helper.rb
|
24
|
-
spec/ui_spec.rb
|
25
37
|
spec/windoze_spec.rb
|
data/Rakefile
CHANGED
@@ -4,14 +4,17 @@ require 'rake'
|
|
4
4
|
begin
|
5
5
|
require 'echoe'
|
6
6
|
|
7
|
-
Echoe.new('github', '0.3.
|
7
|
+
Echoe.new('github', '0.3.10') do |p|
|
8
8
|
p.rubyforge_name = 'github'
|
9
9
|
p.summary = "The official `github` command line helper for simplifying your GitHub experience."
|
10
10
|
p.description = "The official `github` command line helper for simplifying your GitHub experience."
|
11
11
|
p.url = "http://github.com/"
|
12
12
|
p.author = ['Chris Wanstrath', 'Kevin Ballard', 'Scott Chacon']
|
13
13
|
p.email = "chris@ozmm.org"
|
14
|
-
p.dependencies = [
|
14
|
+
p.dependencies = [
|
15
|
+
"text-format >=1.0.0",
|
16
|
+
"highline ~>1.5.1"
|
17
|
+
]
|
15
18
|
end
|
16
19
|
|
17
20
|
rescue LoadError => boom
|
data/github.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{drnic-github}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.10"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Chris Wanstrath, Kevin Ballard, Scott Chacon"]
|
9
|
-
s.date = %q{2009-11-
|
9
|
+
s.date = %q{2009-11-05}
|
10
10
|
s.description = %q{The official `github` command line helper for simplifying your GitHub experience.}
|
11
11
|
s.email = %q{chris@ozmm.org}
|
12
12
|
s.executables = ["gh", "github"]
|
13
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", "
|
14
|
+
s.files = ["History.txt", "LICENSE", "Manifest", "README", "Rakefile", "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", "setup.rb", "spec/command_spec.rb", "spec/commands/command_browse_spec.rb", "spec/commands/command_clone_spec.rb", "spec/commands/command_create-from-local_spec.rb", "spec/commands/command_fetch_spec.rb", "spec/commands/command_fork_spec.rb", "spec/commands/command_helper.rb", "spec/commands/command_home_spec.rb", "spec/commands/command_info_spec.rb", "spec/commands/command_network_spec.rb", "spec/commands/command_pull-request_spec.rb", "spec/commands/command_pull_spec.rb", "spec/commands/command_search_spec.rb", "spec/commands/command_track_spec.rb", "spec/commands_spec.rb", "spec/extensions_spec.rb", "spec/github_spec.rb", "spec/helper_spec.rb", "spec/spec_helper.rb", "spec/windoze_spec.rb", "github.gemspec"]
|
15
15
|
s.homepage = %q{http://github.com/}
|
16
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Github", "--main", "README"]
|
17
17
|
s.require_paths = ["lib"]
|
@@ -24,11 +24,14 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.specification_version = 3
|
25
25
|
|
26
26
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
-
s.add_runtime_dependency(%q<text-format>, [">= 0"])
|
27
|
+
s.add_runtime_dependency(%q<text-format>, [">= 1.0.0"])
|
28
|
+
s.add_runtime_dependency(%q<highline>, ["~> 1.5.1"])
|
28
29
|
else
|
29
|
-
s.add_dependency(%q<text-format>, [">= 0"])
|
30
|
+
s.add_dependency(%q<text-format>, [">= 1.0.0"])
|
31
|
+
s.add_dependency(%q<highline>, ["~> 1.5.1"])
|
30
32
|
end
|
31
33
|
else
|
32
|
-
s.add_dependency(%q<text-format>, [">= 0"])
|
34
|
+
s.add_dependency(%q<text-format>, [">= 1.0.0"])
|
35
|
+
s.add_dependency(%q<highline>, ["~> 1.5.1"])
|
33
36
|
end
|
34
37
|
end
|
data/lib/commands/commands.rb
CHANGED
@@ -37,7 +37,6 @@ command :open do |arg|
|
|
37
37
|
helper.open "http://github.com/#{arg}"
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
40
|
desc "Info about this project."
|
42
41
|
command :info do
|
43
42
|
puts "== Info for #{helper.project}"
|
@@ -133,9 +132,12 @@ command :clone do |user, repo, dir|
|
|
133
132
|
query = [user, repo, dir].compact.join(" ")
|
134
133
|
data = JSON.parse(open("http://github.com/api/v1/json/search/#{URI.escape query}").read)
|
135
134
|
if (repos = data['repositories']) && !repos.nil? && repos.length > 0
|
136
|
-
|
137
|
-
|
138
|
-
|
135
|
+
repo_list = repos.map do |r|
|
136
|
+
{ "name" => "#{r['username']}/#{r['name']}", "description" => r['description'] }
|
137
|
+
end
|
138
|
+
formatted_list = helper.format_list(repo_list).split("\n")
|
139
|
+
if user_repo = GitHub::UI.display_select_list(formatted_list)
|
140
|
+
user, repo = user_repo.strip.split('/', 2)
|
139
141
|
end
|
140
142
|
end
|
141
143
|
die "Perhaps try another search" unless user && repo
|
@@ -159,7 +161,7 @@ end
|
|
159
161
|
|
160
162
|
desc "Generate the text for a pull request."
|
161
163
|
usage "github pull-request [user] [branch]"
|
162
|
-
command 'pull-request' do |user, branch|
|
164
|
+
command :'pull-request' do |user, branch|
|
163
165
|
if helper.project
|
164
166
|
die "Specify a user for the pull request" if user.nil?
|
165
167
|
user, branch = user.split('/', 2) if branch.nil?
|
@@ -224,7 +226,7 @@ end
|
|
224
226
|
|
225
227
|
desc "Create a new GitHub repository from the current local repository"
|
226
228
|
flags :private => 'Create private repository'
|
227
|
-
command 'create-from-local' do
|
229
|
+
command :'create-from-local' do
|
228
230
|
cwd = sh "pwd"
|
229
231
|
repo = File.basename(cwd)
|
230
232
|
is_repo = !git("status").match(/fatal/)
|
data/lib/commands/helpers.rb
CHANGED
@@ -454,6 +454,25 @@ helper :format_issue do |issue, options|
|
|
454
454
|
report.join("\n")
|
455
455
|
end
|
456
456
|
|
457
|
+
# Converts an array of {"name" => "foo", "description" => "some description"} items
|
458
|
+
# as a string list like:
|
459
|
+
# foo # some description
|
460
|
+
# bar-tar # another description
|
461
|
+
helper :format_list do |items|
|
462
|
+
longest_name = items.inject("") do |name, item|
|
463
|
+
name = item["name"] if item["name"] && item["name"].size > name.size
|
464
|
+
name
|
465
|
+
end
|
466
|
+
longest = longest_name.size + 1
|
467
|
+
lines = items.map do |item|
|
468
|
+
cmdstr = "%-#{longest}s" % item["name"]
|
469
|
+
if (description = item["description"]) && description.length > 0
|
470
|
+
cmdstr += "# #{description}"
|
471
|
+
end
|
472
|
+
cmdstr
|
473
|
+
end.join("\n")
|
474
|
+
end
|
475
|
+
|
457
476
|
helper :filter_issue do |issue, options|
|
458
477
|
if options[:after] && ! options[:after].instance_of?(Time)
|
459
478
|
options[:after] = Time.parse(options[:after]) rescue (puts 'cant parse after date')
|
data/lib/github/ui.rb
CHANGED
@@ -3,12 +3,17 @@ require "highline"
|
|
3
3
|
module GitHub
|
4
4
|
module UI
|
5
5
|
extend self
|
6
|
+
# Take a list of items, including optional ' # some description' on each and
|
7
|
+
# return the selected item (without the description)
|
6
8
|
def display_select_list(list)
|
7
9
|
HighLine.track_eof = false
|
8
|
-
HighLine.new.choose do |menu|
|
9
|
-
list.
|
10
|
+
long_result = HighLine.new.choose do |menu|
|
11
|
+
list.each_with_index do |item, i|
|
12
|
+
menu.choice((i < 9) ? " #{item}" : item)
|
13
|
+
end
|
10
14
|
menu.header = "Select a repository to clone"
|
11
15
|
end
|
16
|
+
long_result && long_result.gsub(/\s+#.*$/,'').gsub(/^\ /,'')
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require File.dirname(__FILE__) + '/command_helper'
|
3
|
+
|
4
|
+
describe "github browse" do
|
5
|
+
include CommandHelper
|
6
|
+
|
7
|
+
specify "browse should open the project home page with the current branch" do
|
8
|
+
running :browse do
|
9
|
+
setup_url_for
|
10
|
+
setup_user_and_branch("user", "test-branch")
|
11
|
+
@helper.should_receive(:open).once.with("https://github.com/user/project/tree/test-branch")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "browse pending should open the project home page with the 'pending' branch" do
|
16
|
+
running :browse, "pending" do
|
17
|
+
setup_url_for
|
18
|
+
setup_user_and_branch("user", "test-branch")
|
19
|
+
@helper.should_receive(:open).once.with("https://github.com/user/project/tree/pending")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
specify "browse defunkt pending should open the home page of defunkt's fork with the 'pending' branch" do
|
24
|
+
running :browse, "defunkt", "pending" do
|
25
|
+
setup_url_for
|
26
|
+
@helper.should_receive(:open).once.with("https://github.com/defunkt/project/tree/pending")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
specify "browse defunkt/pending should open the home page of defunkt's fork with the 'pending' branch" do
|
31
|
+
running :browse, "defunkt/pending" do
|
32
|
+
setup_url_for
|
33
|
+
@helper.should_receive(:open).once.with("https://github.com/defunkt/project/tree/pending")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require File.dirname(__FILE__) + '/command_helper'
|
3
|
+
|
4
|
+
describe "github clone" do
|
5
|
+
include CommandHelper
|
6
|
+
|
7
|
+
# -- clone --
|
8
|
+
specify "clone should die with no args" do
|
9
|
+
running :clone do
|
10
|
+
@command.should_receive(:die).with("Specify a user to pull from").and_return { raise "Died" }
|
11
|
+
self.should raise_error(RuntimeError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "clone should fall through with just one arg" do
|
16
|
+
running :clone, "git://git.kernel.org/linux.git" do
|
17
|
+
@command.should_receive(:git_exec).with("clone git://git.kernel.org/linux.git")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "clone defunkt github-gem should clone the repo" do
|
22
|
+
running :clone, "defunkt", "github-gem" do
|
23
|
+
@command.should_receive(:current_user?).and_return(nil)
|
24
|
+
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "clone defunkt/github-gem should clone the repo" do
|
29
|
+
running :clone, "defunkt/github-gem" do
|
30
|
+
@command.should_receive(:current_user?).and_return(nil)
|
31
|
+
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "clone --ssh defunkt github-gem should clone the repo using the private URL" do
|
36
|
+
running :clone, "--ssh", "defunkt", "github-gem" do
|
37
|
+
@command.should_receive(:git_exec).with("clone git@github.com:defunkt/github-gem.git")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
specify "clone defunkt github-gem repo should clone the repo into the dir 'repo'" do
|
42
|
+
running :clone, "defunkt", "github-gem", "repo" do
|
43
|
+
@command.should_receive(:current_user?).and_return(nil)
|
44
|
+
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git repo")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
specify "clone defunkt/github-gem repo should clone the repo into the dir 'repo'" do
|
49
|
+
running :clone, "defunkt/github-gem", "repo" do
|
50
|
+
@command.should_receive(:current_user?).and_return(nil)
|
51
|
+
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git repo")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
specify "clone --ssh defunkt github-gem repo should clone the repo using the private URL into the dir 'repo'" do
|
56
|
+
running :clone, "--ssh", "defunkt", "github-gem", "repo" do
|
57
|
+
@command.should_receive(:git_exec).with("clone git@github.com:defunkt/github-gem.git repo")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
specify "clone defunkt/github-gem repo should clone the repo into the dir 'repo'" do
|
62
|
+
running :clone, "defunkt/github-gem", "repo" do
|
63
|
+
@command.should_receive(:current_user?).and_return(nil)
|
64
|
+
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git repo")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
specify "clone a selected repo after showing search results" do
|
69
|
+
running :clone, "--search", "github-gem" do
|
70
|
+
json = StringIO.new '{"repositories":[' +
|
71
|
+
'{"name":"github-gem","size":300,"followers":499,"username":"defunkt","language":"Ruby","fork":false,"id":"repo-1653","type":"repo","pushed":"2008-12-04T03:14:00Z","forks":59,"description":"The official `github` command line helper for simplifying your GitHub experience.","score":3.4152448,"created":"2008-02-28T09:35:34Z"},' +
|
72
|
+
'{"name":"github-gem-builder","size":76,"followers":26,"username":"pjhyett","language":"Ruby","fork":false,"id":"repo-67489","type":"repo","pushed":"2008-11-04T04:54:57Z","forks":3,"description":"The scripts used to build RubyGems on GitHub","score":3.4152448,"created":"2008-10-24T22:29:32Z"}' +
|
73
|
+
']}'
|
74
|
+
json.rewind
|
75
|
+
question_list = <<-LIST.gsub(/^ /, '').split("\n").compact
|
76
|
+
defunkt/github-gem # The official `github` command line helper for simplifying your GitHub experience.
|
77
|
+
pjhyett/github-gem-builder # The scripts used to build RubyGems on GitHub
|
78
|
+
LIST
|
79
|
+
@command.should_receive(:open).with("http://github.com/api/v1/json/search/github-gem").and_return(json)
|
80
|
+
GitHub::UI.should_receive(:display_select_list).with(question_list).
|
81
|
+
and_return("defunkt/github-gem")
|
82
|
+
@command.should_receive(:current_user?).and_return(nil)
|
83
|
+
@command.should_receive(:git_exec).with("clone git://github.com/defunkt/github-gem.git")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require File.dirname(__FILE__) + '/command_helper'
|
3
|
+
|
4
|
+
describe "github fetch" do
|
5
|
+
include CommandHelper
|
6
|
+
|
7
|
+
specify "fetch should die with no args" do
|
8
|
+
running :fetch do
|
9
|
+
@command.should_receive(:die).with("Specify a user to pull from").and_return { raise "Died" }
|
10
|
+
self.should raise_error(RuntimeError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "fetch defunkt should start tracking defunkt if they're not already tracked" do
|
15
|
+
running :fetch, "defunkt" do
|
16
|
+
setup_remote(:origin, :user => "user", :ssh => true)
|
17
|
+
setup_remote(:external, :url => "home:/path/to/project.git")
|
18
|
+
GitHub.should_receive(:invoke).with(:track, "defunkt").and_return { raise "Tracked" }
|
19
|
+
self.should raise_error("Tracked")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
specify "fetch defunkt should create defunkt/master and fetch from the defunkt remote" do
|
24
|
+
running :fetch, "defunkt" do
|
25
|
+
setup_remote(:defunkt)
|
26
|
+
@helper.should_receive(:branch_dirty?).and_return false
|
27
|
+
@command.should_receive(:git).with("fetch defunkt master:refs/remotes/defunkt/master").ordered
|
28
|
+
@command.should_receive(:git).with("update-ref refs/heads/defunkt/master refs/remotes/defunkt/master").ordered
|
29
|
+
@command.should_receive(:git_exec).with("checkout defunkt/master").ordered
|
30
|
+
stdout.should == "Fetching defunkt/master\n"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
specify "fetch defunkt/wip should create defunkt/wip and fetch from wip branch on defunkt remote" do
|
35
|
+
running :fetch, "defunkt/wip" do
|
36
|
+
setup_remote(:defunkt, :remote_branches => ["master", "wip"])
|
37
|
+
@helper.should_receive(:branch_dirty?).and_return false
|
38
|
+
@command.should_receive(:git).with("fetch defunkt wip:refs/remotes/defunkt/wip").ordered
|
39
|
+
@command.should_receive(:git).with("update-ref refs/heads/defunkt/wip refs/remotes/defunkt/wip").ordered
|
40
|
+
@command.should_receive(:git_exec).with("checkout defunkt/wip").ordered
|
41
|
+
stdout.should == "Fetching defunkt/wip\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
specify "fetch --merge defunkt should fetch from defunkt remote into current branch" do
|
46
|
+
running :fetch, "--merge", "defunkt" do
|
47
|
+
setup_remote(:defunkt)
|
48
|
+
@helper.should_receive(:branch_dirty?).and_return false
|
49
|
+
@command.should_receive(:git).with("fetch defunkt master:refs/remotes/defunkt/master").ordered
|
50
|
+
@command.should_receive(:git).with("update-ref refs/heads/defunkt/master refs/remotes/defunkt/master").ordered
|
51
|
+
@command.should_receive(:git_exec).with("checkout defunkt/master").ordered
|
52
|
+
stdout.should == "Fetching defunkt/master\n"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require File.dirname(__FILE__) + '/command_helper'
|
3
|
+
|
4
|
+
describe "github fork" do
|
5
|
+
include CommandHelper
|
6
|
+
|
7
|
+
specify "fork should print out help" do
|
8
|
+
running :fork do
|
9
|
+
@helper.should_receive(:remotes).and_return({})
|
10
|
+
@command.should_receive(:die).with("Specify a user/project to fork, or run from within a repo").and_return { raise "Died" }
|
11
|
+
self.should raise_error(RuntimeError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "fork this repo should create github fork and replace origin remote" do
|
16
|
+
running :fork do
|
17
|
+
setup_github_token
|
18
|
+
setup_url_for "origin", "defunkt", "github-gem"
|
19
|
+
setup_remote "origin", :user => "defunkt", :project => "github-gem"
|
20
|
+
setup_user_and_branch
|
21
|
+
@command.should_receive(:sh).with("curl -F 'login=drnic' -F 'token=MY_GITHUB_TOKEN' http://github.com/defunkt/github-gem/fork")
|
22
|
+
@command.should_receive(:git, "config remote.origin.url git@github.com/drnic/github-gem.git")
|
23
|
+
stdout.should == "defunkt/github-gem forked\n"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
specify "fork a user/project repo" do
|
28
|
+
running :fork, "defunkt/github-gem" do
|
29
|
+
setup_github_token
|
30
|
+
@command.should_receive(:sh).with("curl -F 'login=drnic' -F 'token=MY_GITHUB_TOKEN' http://github.com/defunkt/github-gem/fork")
|
31
|
+
@command.should_receive(:git_exec, "clone git://github.com/defunkt/github-gem.git")
|
32
|
+
stdout.should == "Giving GitHub a moment to create the fork...\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
specify "fork a user project repo" do
|
37
|
+
running :fork, "defunkt", "github-gem" do
|
38
|
+
setup_github_token
|
39
|
+
@command.should_receive("sh").with("curl -F 'login=drnic' -F 'token=MY_GITHUB_TOKEN' http://github.com/defunkt/github-gem/fork")
|
40
|
+
@command.should_receive(:git_exec, "clone git://github.com/defunkt/github-gem.git")
|
41
|
+
stdout.should == "Giving GitHub a moment to create the fork...\n"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
module CommandHelper
|
2
|
+
def running(cmd, *args, &block)
|
3
|
+
Runner.new(self, cmd, *args, &block).run
|
4
|
+
end
|
5
|
+
|
6
|
+
class Runner
|
7
|
+
include SetupMethods
|
8
|
+
|
9
|
+
def initialize(parent, cmd, *args, &block)
|
10
|
+
@cmd_name = cmd.to_s
|
11
|
+
@command = GitHub.find_command(cmd)
|
12
|
+
@helper = @command.helper
|
13
|
+
@args = args
|
14
|
+
@block = block
|
15
|
+
@parent = parent
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
self.instance_eval &@block
|
20
|
+
mock_remotes unless @remotes.nil?
|
21
|
+
GitHub.should_receive(:load).with(GitHub::BasePath + "/commands/commands.rb")
|
22
|
+
GitHub.should_receive(:load).with(GitHub::BasePath + "/commands/helpers.rb")
|
23
|
+
GitHub.should_receive(:load).with(GitHub::BasePath + "/commands/network.rb")
|
24
|
+
GitHub.should_receive(:load).with(GitHub::BasePath + "/commands/issues.rb")
|
25
|
+
args = @args.clone
|
26
|
+
GitHub.parse_options(args) # strip out the flags
|
27
|
+
GitHub.should_receive(:invoke).with(@cmd_name, *args).and_return do
|
28
|
+
GitHub.send(GitHub.send(:__mock_proxy).send(:munge, :invoke), @cmd_name, *args)
|
29
|
+
end
|
30
|
+
invoke = lambda { GitHub.activate([@cmd_name, *@args]) }
|
31
|
+
if @expected_result
|
32
|
+
expectation, result = @expected_result
|
33
|
+
case result
|
34
|
+
when Spec::Matchers::RaiseError, Spec::Matchers::Change, Spec::Matchers::ThrowSymbol
|
35
|
+
invoke.send expectation, result
|
36
|
+
else
|
37
|
+
invoke.call.send expectation, result
|
38
|
+
end
|
39
|
+
else
|
40
|
+
invoke.call
|
41
|
+
end
|
42
|
+
@stdout_mock.invoke unless @stdout_mock.nil?
|
43
|
+
@stderr_mock.invoke unless @stderr_mock.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def setup_remote(remote, options = {:user => nil, :project => "project", :remote_branches => nil})
|
47
|
+
@remotes ||= {}
|
48
|
+
@remote_branches ||= {}
|
49
|
+
user = options[:user] || remote
|
50
|
+
project = options[:project]
|
51
|
+
ssh = options[:ssh]
|
52
|
+
url = options[:url]
|
53
|
+
remote_branches = options[:remote_branches] || ["master"]
|
54
|
+
if url
|
55
|
+
@remotes[remote] = url
|
56
|
+
elsif ssh
|
57
|
+
@remotes[remote] = "git@github.com:#{user}/#{project}.git"
|
58
|
+
else
|
59
|
+
@remotes[remote] = "git://github.com/#{user}/#{project}.git"
|
60
|
+
end
|
61
|
+
|
62
|
+
@remote_branches[remote] = (@remote_branches[remote] || Array.new) | remote_branches
|
63
|
+
@helper.should_receive(:remote_branch?).any_number_of_times.and_return do |remote, branch|
|
64
|
+
@remote_branches.fetch(remote.to_sym,[]).include?(branch)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def mock_remotes()
|
69
|
+
@helper.should_receive(:remotes).any_number_of_times.and_return(@remotes)
|
70
|
+
end
|
71
|
+
|
72
|
+
def mock_members(members)
|
73
|
+
@helper.should_receive(:network_members).any_number_of_times.and_return(members)
|
74
|
+
end
|
75
|
+
|
76
|
+
def should(result)
|
77
|
+
@expected_result = [:should, result]
|
78
|
+
end
|
79
|
+
|
80
|
+
def should_not(result)
|
81
|
+
@expected_result = [:should_not, result]
|
82
|
+
end
|
83
|
+
|
84
|
+
def stdout
|
85
|
+
if @stdout_mock.nil?
|
86
|
+
output = ""
|
87
|
+
@stdout_mock = DeferredMock.new(output)
|
88
|
+
$stdout.should_receive(:write).any_number_of_times do |str|
|
89
|
+
output << str
|
90
|
+
end
|
91
|
+
end
|
92
|
+
@stdout_mock
|
93
|
+
end
|
94
|
+
|
95
|
+
def stderr
|
96
|
+
if @stderr_mock.nil?
|
97
|
+
output = ""
|
98
|
+
@stderr_mock = DeferredMock.new(output)
|
99
|
+
$stderr.should_receive(:write).any_number_of_times do |str|
|
100
|
+
output << str
|
101
|
+
end
|
102
|
+
end
|
103
|
+
@stderr_mock
|
104
|
+
end
|
105
|
+
|
106
|
+
class DeferredMock
|
107
|
+
def initialize(obj = nil)
|
108
|
+
@obj = obj
|
109
|
+
@calls = []
|
110
|
+
@expectations = []
|
111
|
+
end
|
112
|
+
|
113
|
+
attr_reader :obj
|
114
|
+
|
115
|
+
def invoke(obj = nil)
|
116
|
+
obj ||= @obj
|
117
|
+
@calls.each do |sym, args|
|
118
|
+
obj.send sym, *args
|
119
|
+
end
|
120
|
+
@expectations.each do |exp|
|
121
|
+
exp.invoke
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def should(*args)
|
126
|
+
if args.empty?
|
127
|
+
exp = Expectation.new(self, :should)
|
128
|
+
@expectations << exp
|
129
|
+
exp
|
130
|
+
else
|
131
|
+
@calls << [:should, args]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def should_not(*args)
|
136
|
+
if args.empty?
|
137
|
+
exp = Expectation.new(self, :should_not)
|
138
|
+
@expectations << exp
|
139
|
+
exp
|
140
|
+
else
|
141
|
+
@calls << [:should_not, args]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
class Expectation
|
146
|
+
def initialize(mock, call)
|
147
|
+
@mock = mock
|
148
|
+
@call = call
|
149
|
+
@calls = []
|
150
|
+
end
|
151
|
+
|
152
|
+
undef_method *(instance_methods.map { |x| x.to_sym } - [:__id__, :__send__])
|
153
|
+
|
154
|
+
def invoke
|
155
|
+
@calls.each do |sym, args|
|
156
|
+
(@mock.obj.send @call).send sym, *args
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def method_missing(sym, *args)
|
161
|
+
@calls << [sym, args]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def method_missing(sym, *args)
|
167
|
+
@parent.send sym, *args
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|