github 0.1.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.txt +37 -0
  2. data/Manifest +33 -12
  3. data/README.md +187 -0
  4. data/Rakefile +44 -0
  5. data/bin/gh +8 -0
  6. data/bin/github +4 -1
  7. data/github.gemspec +29 -34
  8. data/lib/commands/commands.rb +249 -0
  9. data/lib/commands/helpers.rb +486 -0
  10. data/lib/commands/issues.rb +17 -0
  11. data/lib/commands/network.rb +110 -0
  12. data/lib/github.rb +117 -29
  13. data/lib/github/command.rb +69 -14
  14. data/lib/github/extensions.rb +39 -0
  15. data/lib/github/ui.rb +19 -0
  16. data/setup.rb +1551 -0
  17. data/spec/command_spec.rb +82 -0
  18. data/spec/commands/command_browse_spec.rb +36 -0
  19. data/spec/commands/command_clone_spec.rb +87 -0
  20. data/spec/commands/command_create-from-local_spec.rb +7 -0
  21. data/spec/commands/command_fetch_spec.rb +56 -0
  22. data/spec/commands/command_fork_spec.rb +44 -0
  23. data/spec/commands/command_helper.rb +170 -0
  24. data/spec/commands/command_home_spec.rb +20 -0
  25. data/spec/commands/command_info_spec.rb +23 -0
  26. data/spec/commands/command_issues_spec.rb +97 -0
  27. data/spec/commands/command_network_spec.rb +30 -0
  28. data/spec/commands/command_pull-request_spec.rb +51 -0
  29. data/spec/commands/command_pull_spec.rb +82 -0
  30. data/spec/commands/command_search_spec.rb +34 -0
  31. data/spec/commands/command_track_spec.rb +82 -0
  32. data/spec/commands_spec.rb +49 -0
  33. data/spec/extensions_spec.rb +36 -0
  34. data/spec/github_spec.rb +85 -0
  35. data/spec/helper_spec.rb +368 -0
  36. data/spec/spec_helper.rb +160 -4
  37. data/spec/windoze_spec.rb +38 -0
  38. metadata +114 -47
  39. data/README +0 -49
  40. data/commands/commands.rb +0 -54
  41. data/commands/helpers.rb +0 -79
  42. data/spec/helpers/owner_spec.rb +0 -12
  43. data/spec/helpers/project_spec.rb +0 -12
  44. data/spec/helpers/public_url_for_spec.rb +0 -12
  45. data/spec/helpers/repo_for_spec.rb +0 -12
  46. data/spec/helpers/user_and_repo_from_spec.rb +0 -15
  47. data/spec/helpers/user_for_spec.rb +0 -12
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,165 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
+ require 'activerecord'
3
4
 
4
5
  require File.dirname(__FILE__) + '/../lib/github'
5
6
 
6
- module GitHub
7
- load 'helpers.rb'
8
- load 'commands.rb'
9
- end
7
+ class Module
8
+ def metaclass
9
+ class << self;self;end
10
+ end
11
+ end
12
+
13
+ class Spec::NextInstanceProxy
14
+ def initialize
15
+ @deferred = []
16
+ end
17
+
18
+ def method_missing(sym, *args)
19
+ proxy = Spec::NextInstanceProxy.new
20
+ @deferred << [sym, args, proxy]
21
+ proxy
22
+ end
23
+
24
+ def should_receive(*args)
25
+ method_missing(:should_receive, *args)
26
+ end
27
+ alias stub! should_receive
28
+
29
+ def invoke(obj)
30
+ @deferred.each do |(sym, args, proxy)|
31
+ result = obj.send(sym, *args)
32
+ proxy.invoke(result)
33
+ end
34
+ end
35
+ end
36
+
37
+ class Class
38
+ def next_instance
39
+ meth = metaclass.instance_method(:new)
40
+ proxy = Spec::NextInstanceProxy.new
41
+ metaclass.send :define_method, :new do |*args|
42
+ instance = meth.bind(self).call(*args)
43
+ proxy.invoke(instance)
44
+ metaclass.send :define_method, :new, meth
45
+ instance
46
+ end
47
+ proxy
48
+ end
49
+ end
50
+
51
+ module Spec::Example::ExampleGroupSubclassMethods
52
+ def add_guard(klass, name, is_class = false)
53
+ guarded = nil # define variable now for scoping
54
+ target = (is_class ? klass.metaclass : klass)
55
+ sep = (is_class ? "." : "#")
56
+ target.class_eval do
57
+ guarded = instance_method(name)
58
+ define_method name do |*args|
59
+ raise "Testing guards violated: Cannot call #{klass}#{sep}#{name} with args #{args.inspect}"
60
+ end
61
+ end
62
+ @guards ||= []
63
+ @guards << [klass, name, is_class, guarded]
64
+ end
65
+
66
+ def add_class_guard(klass, name)
67
+ add_guard(klass, name, true)
68
+ end
69
+
70
+ def unguard(klass, name, is_class = false)
71
+ row = @guards.find { |(k,n,i)| k == klass and n == name and i == is_class }
72
+ raise "#{klass}#{is_class ? "." : "#"}#{name} is not guarded" if row.nil?
73
+ (is_class ? klass.metaclass : klass).class_eval do
74
+ define_method name, row.last
75
+ end
76
+ @guards.delete row
77
+ end
78
+
79
+ def class_unguard(klass, name)
80
+ unguard(klass, name, true)
81
+ end
82
+
83
+ def unguard_all
84
+ @guards ||= []
85
+ @guards.each do |klass, name, is_class, guarded|
86
+ (is_class ? klass.metaclass : klass).class_eval do
87
+ define_method name, guarded
88
+ end
89
+ end
90
+ @guards.clear
91
+ end
92
+ end
93
+
94
+ # prevent the use of `` in tests
95
+ Spec::Runner.configure do |configuration|
96
+ # load this here so it's covered by the `` guard
97
+ configuration.prepend_before(:all) do
98
+ module GitHub
99
+ load 'helpers.rb'
100
+ load 'commands.rb'
101
+ load 'network.rb'
102
+ load 'issues.rb'
103
+ end
104
+ end
105
+
106
+ configuration.prepend_after(:each) do
107
+ GitHub.instance_variable_set :'@options', nil
108
+ GitHub.instance_variable_set :'@debug', nil
109
+ end
110
+
111
+ configuration.prepend_before(:all) do
112
+ self.class.send :include, Spec::Example::ExampleGroupSubclassMethods
113
+ end
114
+
115
+ configuration.prepend_before(:each) do
116
+ add_guard Kernel, :`
117
+ add_guard Kernel, :system
118
+ add_guard Kernel, :fork
119
+ add_guard Kernel, :exec
120
+ add_class_guard Process, :fork
121
+ end
122
+
123
+ configuration.append_after(:each) do
124
+ unguard_all
125
+ end
126
+ end
127
+
128
+ # include this in any example group that defines @helper
129
+ module SetupMethods
130
+ def setup_url_for(remote = "origin", user = nil, project = "project")
131
+ if user.nil?
132
+ user = remote
133
+ user = "user" if remote == "origin"
134
+ end
135
+ @helper.should_receive(:url_for).any_number_of_times.with(remote).and_return("git://github.com/#{user}/#{project}.git")
136
+ @helper.should_receive(:origin).any_number_of_times.and_return(remote.to_s)
137
+ end
138
+
139
+ def setup_user_and_branch(user = :user, branch = :master)
140
+ @helper.should_receive(:user_and_branch).any_number_of_times.and_return([user, branch])
141
+ end
142
+
143
+ def setup_github_token(user = 'drnic', token = 'MY_GITHUB_TOKEN')
144
+ @command.should_receive(:github_user).any_number_of_times.and_return(user)
145
+ @command.should_receive(:github_token).any_number_of_times.and_return(token)
146
+ end
147
+ end
148
+
149
+ # When running specs in TextMate, provide an rputs method to cleanly print objects into HTML display
150
+ # From http://talklikeaduck.denhaven2.com/2009/09/23/rspec-textmate-pro-tip
151
+ module Kernel
152
+ if ENV.keys.find {|env_var| env_var.index("TM_")}
153
+ def rputs(*args)
154
+ require 'cgi'
155
+ puts( *["<pre>", args.collect {|a| CGI.escapeHTML(a.to_s)}, "</pre>"])
156
+ end
157
+ def rp(*args)
158
+ require 'cgi'
159
+ puts( *["<pre>", args.collect {|a| CGI.escapeHTML(a.inspect)}, "</pre>"])
160
+ end
161
+ else
162
+ alias_method :rputs, :puts
163
+ alias_method :rp, :p
164
+ end
165
+ end
@@ -0,0 +1,38 @@
1
+ # this is an extremely hacky spec
2
+ # intended purely to test the Windoze-specific code
3
+
4
+ require 'rubygems'
5
+ require 'spec'
6
+
7
+ describe "github/command.rb" do
8
+ before(:all) do
9
+ @orig_platform = RUBY_PLATFORM
10
+ Object.send :remove_const, :RUBY_PLATFORM
11
+ Object.const_set :RUBY_PLATFORM, "mswin"
12
+ end
13
+
14
+ after(:all) do
15
+ Object.send :remove_const, :RUBY_PLATFORM
16
+ Object.const_set :RUBY_PLATFORM, @orig_platform
17
+ end
18
+
19
+ before(:each) do
20
+ @filename = File.dirname(__FILE__) + "/../lib/github/command.rb"
21
+ @data = File.read(@filename)
22
+ end
23
+
24
+ it "should require win32/open3 under Windows" do
25
+ mod = Module.new
26
+ mod.should_receive(:require).with("fileutils")
27
+ mod.should_receive(:require).with("win32/open3")
28
+ mod.class_eval @data, @filename
29
+ end
30
+
31
+ it "should blow up if win32/open3 isn't present under Windows" do
32
+ mod = Module.new
33
+ mod.should_receive(:require).with("fileutils")
34
+ mod.should_receive(:require).with("win32/open3").and_return { raise LoadError }
35
+ mod.should_receive(:warn).with("You must 'gem install win32-open3' to use the github command on Windows")
36
+ lambda { mod.class_eval @data, @filename }.should raise_error(SystemExit)
37
+ end
38
+ end
metadata CHANGED
@@ -1,63 +1,130 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: github
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2008-03-26 00:00:00 -04:00
8
- summary: The official `github` command line helper for simplifying your GitHub experience.
9
- require_paths:
10
- - lib
11
- email: chris@ozmm.org
12
- homepage: http://github.com/
13
- rubyforge_project: github
14
- description: The official `github` command line helper for simplifying your GitHub experience.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.4.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
- - Chris Wanstrath
31
- files:
7
+ - Chris Wanstrath, Kevin Ballard, Scott Chacon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-06 00:00:00 +10:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: text-format
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: highline
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.1
34
+ version:
35
+ description: The official `github` command line helper for simplifying your GitHub experience.
36
+ email: chris@ozmm.org
37
+ executables:
38
+ - gh
39
+ - github
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ - README.md
45
+ - bin/gh
32
46
  - bin/github
33
- - commands/commands.rb
34
- - commands/helpers.rb
47
+ - lib/commands/commands.rb
48
+ - lib/commands/helpers.rb
49
+ - lib/commands/issues.rb
50
+ - lib/commands/network.rb
51
+ - lib/github.rb
35
52
  - lib/github/command.rb
53
+ - lib/github/extensions.rb
36
54
  - lib/github/helper.rb
37
- - lib/github.rb
55
+ - lib/github/ui.rb
56
+ files:
57
+ - History.txt
38
58
  - LICENSE
39
- - README
59
+ - Manifest
60
+ - README.md
61
+ - Rakefile
62
+ - bin/gh
63
+ - bin/github
64
+ - lib/commands/commands.rb
65
+ - lib/commands/helpers.rb
66
+ - lib/commands/issues.rb
67
+ - lib/commands/network.rb
68
+ - lib/github.rb
69
+ - lib/github/command.rb
70
+ - lib/github/extensions.rb
71
+ - lib/github/helper.rb
72
+ - lib/github/ui.rb
73
+ - setup.rb
40
74
  - spec/command_spec.rb
41
- - spec/helpers/owner_spec.rb
42
- - spec/helpers/project_spec.rb
43
- - spec/helpers/public_url_for_spec.rb
44
- - spec/helpers/repo_for_spec.rb
45
- - spec/helpers/user_and_repo_from_spec.rb
46
- - spec/helpers/user_for_spec.rb
75
+ - spec/commands/command_browse_spec.rb
76
+ - spec/commands/command_clone_spec.rb
77
+ - spec/commands/command_create-from-local_spec.rb
78
+ - spec/commands/command_fetch_spec.rb
79
+ - spec/commands/command_fork_spec.rb
80
+ - spec/commands/command_helper.rb
81
+ - spec/commands/command_home_spec.rb
82
+ - spec/commands/command_info_spec.rb
83
+ - spec/commands/command_issues_spec.rb
84
+ - spec/commands/command_network_spec.rb
85
+ - spec/commands/command_pull-request_spec.rb
86
+ - spec/commands/command_pull_spec.rb
87
+ - spec/commands/command_search_spec.rb
88
+ - spec/commands/command_track_spec.rb
89
+ - spec/commands_spec.rb
90
+ - spec/extensions_spec.rb
91
+ - spec/github_spec.rb
92
+ - spec/helper_spec.rb
47
93
  - spec/spec_helper.rb
48
- - Manifest
94
+ - spec/windoze_spec.rb
49
95
  - github.gemspec
50
- test_files: []
51
-
52
- rdoc_options: []
53
-
54
- extra_rdoc_files: []
55
-
56
- executables:
57
- - github
58
- extensions: []
96
+ has_rdoc: true
97
+ homepage: http://github.com/
98
+ licenses: []
59
99
 
100
+ post_install_message:
101
+ rdoc_options:
102
+ - --line-numbers
103
+ - --inline-source
104
+ - --title
105
+ - Github
106
+ - --main
107
+ - README.md
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: "0"
115
+ version:
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: "1.2"
121
+ version:
60
122
  requirements: []
61
123
 
62
- dependencies: []
124
+ rubyforge_project: github
125
+ rubygems_version: 1.3.5
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: The official `github` command line helper for simplifying your GitHub experience.
129
+ test_files: []
63
130
 
data/README DELETED
@@ -1,49 +0,0 @@
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 github
13
-
14
- Run it:
15
-
16
- $ github <command> <args>
17
-
18
-
19
- =============
20
- Pulling Changes
21
- =============
22
-
23
- Let's say you just forked `github-gem` on GitHub from defunkt.
24
-
25
- $ git clone git://github.com/YOU/github-gem.git
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
- $ git checkout master
40
- $ git merge defunkt/master
41
-
42
-
43
- ==========
44
- Contributors
45
- ==========
46
-
47
- - defunkt
48
- - maddox
49
- - halorgium
data/commands/commands.rb DELETED
@@ -1,54 +0,0 @@
1
- GitHub.register :helper do |name, comma_args|
2
- comma_args ||= ''
3
- puts helper.send(name, comma_args.split(/,/))
4
- end
5
-
6
- GitHub.describe :home => "Open this repo's master branch in a web browser."
7
- GitHub.register :home do
8
- if helper.project
9
- exec "open #{helper.homepage_for(helper.owner, 'master')}"
10
- end
11
- end
12
-
13
- GitHub.describe :browse => "Open this repo in a web browser."
14
- GitHub.register :browse do
15
- if helper.project
16
- exec "open #{helper.homepage_for(helper.branch_user, helper.branch_name)}"
17
- end
18
- end
19
-
20
- GitHub.describe :info => "Info about this project."
21
- GitHub.register :info do
22
- puts "== Info for #{helper.project}"
23
- puts "You are #{helper.owner}"
24
- puts "Currently tracking: "
25
- helper.tracking.each do |(name,user_or_url)|
26
- puts " - #{user_or_url} (as #{name})"
27
- end
28
- end
29
-
30
- GitHub.describe :track => "Track another user's repository."
31
- GitHub.register :track do |user|
32
- die "Specify a user to track" if user.nil?
33
- die "Already tracking #{user}" if helper.tracking?(user)
34
-
35
- git "remote add #{user} #{helper.public_url_for(user)}"
36
- end
37
-
38
- GitHub.describe :pull => "Pull from a remote. Pass --merge to automatically merge remote's changes into your master."
39
- GitHub.register :pull do |user, branch|
40
- die "Specify a user to pull from" if user.nil?
41
- GitHub.invoke(:track, user) unless helper.tracking?(user)
42
- branch ||= 'master'
43
-
44
- puts "Switching to #{user}/#{branch}"
45
- git "checkout #{user}/#{branch}" if git("checkout -b #{user}/#{branch}").error?
46
-
47
- if options[:merge]
48
- git "pull #{user} #{branch}"
49
- git "checkout master"
50
- git_exec "merge #{user}/#{branch}"
51
- else
52
- git_exec "pull #{user} #{branch}"
53
- end
54
- end