defunkt-github 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gh +4 -1
- data/bin/github +4 -1
- data/github-gem.gemspec +3 -3
- data/{commands → lib/commands}/commands.rb +50 -6
- data/{commands → lib/commands}/helpers.rb +34 -13
- data/{commands → lib/commands}/network.rb +3 -3
- data/lib/github.rb +4 -3
- data/lib/github/command.rb +8 -0
- metadata +5 -5
data/bin/gh
CHANGED
data/bin/github
CHANGED
data/github-gem.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "github"
|
3
|
-
s.version = "0.3.
|
3
|
+
s.version = "0.3.4"
|
4
4
|
|
5
5
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
6
6
|
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.email = %q{chris@ozmm.org}
|
13
13
|
s.executables = ["github", "gh"]
|
14
14
|
s.extra_rdoc_files = ["bin/github", "bin/gh", "lib/github/extensions.rb", "lib/github/command.rb", "lib/github/helper.rb", "lib/github.rb", "LICENSE", "README"]
|
15
|
-
s.files = ["bin/github", "commands/network.rb", "commands/commands.rb", "commands/helpers.rb", "lib/github/extensions.rb", "lib/github/command.rb", "lib/github/helper.rb", "lib/github.rb", "LICENSE", "Manifest", "README", "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", "github-gem.gemspec"]
|
15
|
+
s.files = ["bin/github", "lib/commands/network.rb", "lib/commands/commands.rb", "lib/commands/helpers.rb", "lib/github/extensions.rb", "lib/github/command.rb", "lib/github/helper.rb", "lib/github.rb", "LICENSE", "Manifest", "README", "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", "github-gem.gemspec"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/}
|
18
18
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Github", "--main", "README"]
|
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.summary = %q{The official `github` command line helper for simplifying your GitHub experience.}
|
23
23
|
|
24
24
|
# s.add_dependency(%q<launchy>, [">= 0"])
|
25
|
-
s.add_dependency('
|
25
|
+
s.add_dependency('json_pure', [">= 0"])
|
26
26
|
end
|
@@ -37,7 +37,7 @@ command :info do
|
|
37
37
|
puts "== Info for #{helper.project}"
|
38
38
|
puts "You are #{helper.owner}"
|
39
39
|
puts "Currently tracking:"
|
40
|
-
helper.tracking.sort { |(a,),(b,)| a ==
|
40
|
+
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)|
|
41
41
|
puts " - #{user_or_url} (as #{name})"
|
42
42
|
end
|
43
43
|
end
|
@@ -108,9 +108,9 @@ command :pull do |user, branch|
|
|
108
108
|
if options[:merge]
|
109
109
|
git_exec "pull #{user} #{branch}"
|
110
110
|
else
|
111
|
-
puts "Switching to #{user}
|
112
|
-
git "
|
113
|
-
|
111
|
+
puts "Switching to #{user}-#{branch}"
|
112
|
+
git "fetch #{user}"
|
113
|
+
git_exec "checkout -b #{user}/#{branch} #{user}/#{branch}"
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
@@ -135,13 +135,57 @@ end
|
|
135
135
|
|
136
136
|
desc "Generate the text for a pull request."
|
137
137
|
usage "github pull-request [user] [branch]"
|
138
|
-
command
|
138
|
+
command 'pull-request' do |user, branch|
|
139
139
|
if helper.project
|
140
140
|
die "Specify a user for the pull request" if user.nil?
|
141
141
|
user, branch = user.split('/', 2) if branch.nil?
|
142
142
|
branch ||= 'master'
|
143
143
|
GitHub.invoke(:track, user) unless helper.tracking?(user)
|
144
144
|
|
145
|
-
git_exec "request-pull #{user}/#{branch} origin"
|
145
|
+
git_exec "request-pull #{user}/#{branch} #{helper.origin}"
|
146
146
|
end
|
147
147
|
end
|
148
|
+
|
149
|
+
desc "Create a new, empty GitHub repository"
|
150
|
+
usage "github create [repo]"
|
151
|
+
flags :markdown => 'Create README.markdown'
|
152
|
+
flags :mdown => 'Create README.mdown'
|
153
|
+
flags :textile => 'Create README.textile'
|
154
|
+
flags :rdoc => 'Create README.rdoc'
|
155
|
+
flags :rst => 'Create README.rst'
|
156
|
+
command :create do |repo|
|
157
|
+
sh "curl -F 'repository[name]=#{repo}' -F 'login=#{github_user}' -F 'token=#{github_token}' http://github.com/repositories"
|
158
|
+
mkdir repo
|
159
|
+
cd repo
|
160
|
+
git "init"
|
161
|
+
extension = options.keys.first
|
162
|
+
touch extension ? "README.#{extension}" : "README"
|
163
|
+
git "add *"
|
164
|
+
git "commit -m 'First commit!'"
|
165
|
+
git "remote add origin git@github.com:#{github_user}/#{repo}.git"
|
166
|
+
git_exec "push origin master"
|
167
|
+
end
|
168
|
+
|
169
|
+
desc "Forks a GitHub repository"
|
170
|
+
usage "github fork [user]/[repo]"
|
171
|
+
command :fork do |user, repo|
|
172
|
+
if repo.nil?
|
173
|
+
user, repo = user.split('/')
|
174
|
+
end
|
175
|
+
|
176
|
+
sh "curl -F 'login=#{github_user}' -F 'token=#{github_token}' http://github.com/#{user}/#{repo}/fork"
|
177
|
+
puts "Giving GitHub a moment to create the fork..."
|
178
|
+
sleep 3
|
179
|
+
git_exec "clone git@github.com:#{github_user}/#{repo}.git"
|
180
|
+
end
|
181
|
+
|
182
|
+
desc "Create a new GitHub repository from the current local repository"
|
183
|
+
command 'create-from-local' do
|
184
|
+
cwd = sh "pwd"
|
185
|
+
repo = File.basename(cwd)
|
186
|
+
is_repo = !git("status").match(/fatal/)
|
187
|
+
raise "Not a git repository. Use gh create instead" unless is_repo
|
188
|
+
sh "curl -F 'repository[name]=#{repo}' -F 'login=#{github_user}' -F 'token=#{github_token}' http://github.com/repositories"
|
189
|
+
git "remote add origin git@github.com:#{github_user}/#{repo}.git"
|
190
|
+
git_exec "push origin master"
|
191
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
DEV_NULL = File.exist?("/dev/null") ? "/dev/null" : "nul:"
|
2
|
+
|
1
3
|
helper :user_and_repo_from do |url|
|
2
4
|
case url
|
3
5
|
when %r|^git://github\.com/([^/]+/[^/]+)$|: $1.split('/')
|
@@ -17,10 +19,16 @@ helper :repo_for do |remote|
|
|
17
19
|
user_and_repo_for(remote).try.last
|
18
20
|
end
|
19
21
|
|
22
|
+
helper :origin do
|
23
|
+
orig = `git config --get github.origin`.chomp
|
24
|
+
orig = nil if orig.empty?
|
25
|
+
orig || 'origin'
|
26
|
+
end
|
27
|
+
|
20
28
|
helper :project do
|
21
|
-
repo = repo_for(
|
29
|
+
repo = repo_for(origin)
|
22
30
|
if repo.nil?
|
23
|
-
if url_for(
|
31
|
+
if url_for(origin) == ""
|
24
32
|
STDERR.puts "Error: missing remote 'origin'"
|
25
33
|
else
|
26
34
|
STDERR.puts "Error: remote 'origin' is not a github URL"
|
@@ -39,7 +47,7 @@ helper :local_heads do
|
|
39
47
|
end
|
40
48
|
|
41
49
|
helper :has_commit? do |sha|
|
42
|
-
`git show #{sha}
|
50
|
+
`git show #{sha} >#{DEV_NULL} 2>#{DEV_NULL}`
|
43
51
|
$?.exitstatus == 0
|
44
52
|
end
|
45
53
|
|
@@ -135,7 +143,7 @@ helper :print_commits do |our_commits, options|
|
|
135
143
|
end
|
136
144
|
|
137
145
|
helper :applies_cleanly do |sha|
|
138
|
-
`git diff ...#{sha} | git apply --check
|
146
|
+
`git diff ...#{sha} | git apply --check >#{DEV_NULL} 2>#{DEV_NULL}`
|
139
147
|
$?.exitstatus == 0
|
140
148
|
end
|
141
149
|
|
@@ -150,7 +158,7 @@ helper :remotes do
|
|
150
158
|
end
|
151
159
|
|
152
160
|
helper :remote_branches_for do |user|
|
153
|
-
`git ls-remote -h #{user} 2>
|
161
|
+
`git ls-remote -h #{user} 2> #{DEV_NULL}`.split(/\n/).inject({}) do |memo, line|
|
154
162
|
hash, head = line.split(/\t/, 2)
|
155
163
|
head = head[%r{refs/heads/(.+)$},1] unless head.nil?
|
156
164
|
memo[head] = hash unless head.nil?
|
@@ -167,7 +175,7 @@ helper :branch_dirty? do
|
|
167
175
|
# originally, we were going to use git-ls-files but that could only
|
168
176
|
# report modified track files...not files that have been staged
|
169
177
|
# for committal
|
170
|
-
!(system("git diff --quiet 2
|
178
|
+
!(system("git diff --quiet 2>#{DEV_NULL}") or !system("git diff --cached --quiet 2>#{DEV_NULL}"))
|
171
179
|
end
|
172
180
|
|
173
181
|
helper :tracking do
|
@@ -186,7 +194,7 @@ helper :tracking? do |user|
|
|
186
194
|
end
|
187
195
|
|
188
196
|
helper :owner do
|
189
|
-
user_for(
|
197
|
+
user_for(origin)
|
190
198
|
end
|
191
199
|
|
192
200
|
helper :current_branch do
|
@@ -239,6 +247,9 @@ helper :network_meta_for do |user|
|
|
239
247
|
"http://github.com/#{user}/#{project}/network_meta"
|
240
248
|
end
|
241
249
|
|
250
|
+
helper :network_members_for do |user|
|
251
|
+
"http://github.com/#{user}/#{project}/network/members.json"
|
252
|
+
end
|
242
253
|
|
243
254
|
helper :has_launchy? do |blk|
|
244
255
|
begin
|
@@ -290,8 +301,8 @@ These are all the commits that other people have pushed that you have not
|
|
290
301
|
applied or ignored yet (see 'github ignore'). Some things you might want to do:
|
291
302
|
|
292
303
|
* You can run 'github fetch user/branch' (sans '~N') to pull into a local branch for testing
|
293
|
-
* You can run '
|
294
|
-
* You can run '
|
304
|
+
* You can run 'github cherry-pick [SHA]' to apply a single patch
|
305
|
+
* You can run 'github merge user/branch' to merge a commit and all the '~N' variants.
|
295
306
|
* You can ignore all of a projects commits with 'github ignore ..user/branch'
|
296
307
|
=========================================================================================
|
297
308
|
|
@@ -303,9 +314,7 @@ helper :argv do
|
|
303
314
|
end
|
304
315
|
|
305
316
|
helper :network_members do
|
306
|
-
|
307
|
-
hash['name']
|
308
|
-
end
|
317
|
+
get_network_members(owner, {}).map {|member| member['owner']['login'] }
|
309
318
|
end
|
310
319
|
|
311
320
|
|
@@ -314,12 +323,24 @@ helper :get_network_data do |user, options|
|
|
314
323
|
return get_cache
|
315
324
|
end
|
316
325
|
if cache_network_data(options)
|
317
|
-
|
326
|
+
begin
|
327
|
+
return cache_data(user)
|
328
|
+
rescue SocketError
|
329
|
+
STDERR.puts "*** Warning: There was a problem accessing the network."
|
330
|
+
rv = get_cache
|
331
|
+
STDERR.puts "Using cached data."
|
332
|
+
rv
|
333
|
+
end
|
318
334
|
else
|
319
335
|
return get_cache
|
320
336
|
end
|
321
337
|
end
|
322
338
|
|
339
|
+
helper :get_network_members do |user, options|
|
340
|
+
json = Kernel.open(network_members_for(user)).read
|
341
|
+
JSON.parse(json)["users"]
|
342
|
+
end
|
343
|
+
|
323
344
|
helper :cache_commits do |commits|
|
324
345
|
File.open( commits_cache_path, 'w' ) do |out|
|
325
346
|
out.write(commits.to_yaml)
|
@@ -20,9 +20,9 @@ command :network do |command, user|
|
|
20
20
|
when 'web'
|
21
21
|
helper.open helper.network_page_for(user)
|
22
22
|
when 'list'
|
23
|
-
|
24
|
-
|
25
|
-
puts
|
23
|
+
members = helper.get_network_members(user, options)
|
24
|
+
members.each do |hsh|
|
25
|
+
puts hsh["owner"]["login"]
|
26
26
|
end
|
27
27
|
when 'fetch'
|
28
28
|
# fetch each remote we don't have
|
data/lib/github.rb
CHANGED
@@ -21,9 +21,10 @@ require 'yaml'
|
|
21
21
|
module GitHub
|
22
22
|
extend self
|
23
23
|
|
24
|
-
BasePath = File.expand_path(File.dirname(__FILE__)
|
24
|
+
BasePath = File.expand_path(File.dirname(__FILE__))
|
25
25
|
|
26
26
|
def command(command, options = {}, &block)
|
27
|
+
command = command.to_s
|
27
28
|
debug "Registered `#{command}`"
|
28
29
|
descriptions[command] = @next_description if @next_description
|
29
30
|
@next_description = nil
|
@@ -31,7 +32,7 @@ module GitHub
|
|
31
32
|
usage_descriptions[command] = @next_usage if @next_usage
|
32
33
|
@next_flags = nil
|
33
34
|
@next_usage = []
|
34
|
-
commands[command
|
35
|
+
commands[command] = Command.new(block)
|
35
36
|
Array(options[:alias] || options[:aliases]).each do |command_alias|
|
36
37
|
commands[command_alias.to_s] = commands[command.to_s]
|
37
38
|
end
|
@@ -143,7 +144,7 @@ module GitHub
|
|
143
144
|
end
|
144
145
|
|
145
146
|
def load(file)
|
146
|
-
file[0]
|
147
|
+
file[0] =~ /^\// ? path = file : path = BasePath + "/commands/#{File.basename(file)}"
|
147
148
|
data = File.read(path)
|
148
149
|
GitHub.module_eval data, path
|
149
150
|
end
|
data/lib/github/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
1
3
|
if RUBY_PLATFORM =~ /mswin|mingw/
|
2
4
|
begin
|
3
5
|
require 'win32/open3'
|
@@ -11,6 +13,8 @@ end
|
|
11
13
|
|
12
14
|
module GitHub
|
13
15
|
class Command
|
16
|
+
include FileUtils
|
17
|
+
|
14
18
|
def initialize(block)
|
15
19
|
(class << self;self end).send :define_method, :command, &block
|
16
20
|
end
|
@@ -66,6 +70,10 @@ module GitHub
|
|
66
70
|
git("config --get github.user")
|
67
71
|
end
|
68
72
|
|
73
|
+
def github_token
|
74
|
+
git("config --get github.token")
|
75
|
+
end
|
76
|
+
|
69
77
|
def shell_user
|
70
78
|
ENV['USER']
|
71
79
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defunkt-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath, Kevin Ballard, Scott Chacon
|
@@ -13,7 +13,7 @@ date: 2008-05-18 00:00:00 -07:00
|
|
13
13
|
default_executable: gh
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: json_pure
|
17
17
|
version_requirement:
|
18
18
|
version_requirements: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
@@ -39,9 +39,9 @@ extra_rdoc_files:
|
|
39
39
|
- README
|
40
40
|
files:
|
41
41
|
- bin/github
|
42
|
-
- commands/network.rb
|
43
|
-
- commands/commands.rb
|
44
|
-
- commands/helpers.rb
|
42
|
+
- lib/commands/network.rb
|
43
|
+
- lib/commands/commands.rb
|
44
|
+
- lib/commands/helpers.rb
|
45
45
|
- lib/github/extensions.rb
|
46
46
|
- lib/github/command.rb
|
47
47
|
- lib/github/helper.rb
|