git-pulls 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/git-pulls.rb +76 -3
- metadata +18 -4
data/lib/git-pulls.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'json'
|
3
3
|
require 'httparty'
|
4
|
+
require 'launchy'
|
4
5
|
require 'pp'
|
5
6
|
|
6
7
|
class GitPulls
|
@@ -19,7 +20,14 @@ class GitPulls
|
|
19
20
|
|
20
21
|
def run
|
21
22
|
if @command && self.respond_to?(@command)
|
23
|
+
# If the cache file doesn't exist, make sure we run update
|
24
|
+
# before any other command. git-pulls will otherwise crash
|
25
|
+
# with an exception.
|
26
|
+
update unless File.exists?(PULLS_CACHE_FILE) || @command == 'update'
|
27
|
+
|
22
28
|
self.send @command
|
29
|
+
elsif %w(-h --help).include?(@command)
|
30
|
+
usage
|
23
31
|
else
|
24
32
|
help
|
25
33
|
end
|
@@ -30,6 +38,17 @@ class GitPulls
|
|
30
38
|
def help
|
31
39
|
puts "No command: #{@command}"
|
32
40
|
puts "Try: update, list, show, merge, browse"
|
41
|
+
puts "or call with '--help' for usage information"
|
42
|
+
end
|
43
|
+
|
44
|
+
def usage
|
45
|
+
puts <<-USAGE
|
46
|
+
Usage: git pulls update
|
47
|
+
or: git pulls list [--reverse]
|
48
|
+
or: git pulls show <number> [--full]
|
49
|
+
or: git pulls browse <number>
|
50
|
+
or: git pulls merge <number>
|
51
|
+
USAGE
|
33
52
|
end
|
34
53
|
|
35
54
|
def merge
|
@@ -86,7 +105,7 @@ class GitPulls
|
|
86
105
|
def browse
|
87
106
|
num = @args.shift
|
88
107
|
if p = pull_num(num)
|
89
|
-
|
108
|
+
Launchy.open(p['html_url'])
|
90
109
|
else
|
91
110
|
puts "No such number"
|
92
111
|
end
|
@@ -97,6 +116,7 @@ class GitPulls
|
|
97
116
|
puts "Open Pull Requests for #{@user}/#{@repo}"
|
98
117
|
pulls = get_pull_info
|
99
118
|
pulls.reverse! if option == '--reverse'
|
119
|
+
count = 0
|
100
120
|
pulls.each do |pull|
|
101
121
|
line = []
|
102
122
|
line << l(pull['number'], 4)
|
@@ -107,8 +127,12 @@ class GitPulls
|
|
107
127
|
sha = pull['head']['sha']
|
108
128
|
if not_merged?(sha)
|
109
129
|
puts line.join ' '
|
130
|
+
count += 1
|
110
131
|
end
|
111
132
|
end
|
133
|
+
if count == 0
|
134
|
+
puts ' -- no open pull requests --'
|
135
|
+
end
|
112
136
|
end
|
113
137
|
|
114
138
|
def update
|
@@ -117,10 +141,15 @@ class GitPulls
|
|
117
141
|
fetch_stale_forks
|
118
142
|
list
|
119
143
|
end
|
144
|
+
|
145
|
+
def protocol(is_private)
|
146
|
+
is_private ? "ssh://git@" : "git://"
|
147
|
+
end
|
120
148
|
|
121
149
|
def fetch_stale_forks
|
122
150
|
puts "Checking for forks in need of fetching"
|
123
151
|
pulls = get_pull_info
|
152
|
+
is_private = get_repo_visibility
|
124
153
|
repos = {}
|
125
154
|
pulls.each do |pull|
|
126
155
|
o = pull['head']['repository']['owner']
|
@@ -133,7 +162,16 @@ class GitPulls
|
|
133
162
|
end
|
134
163
|
repos.each do |repo, bool|
|
135
164
|
puts " fetching #{repo}"
|
136
|
-
git("fetch
|
165
|
+
git("fetch #{protocol(is_private)}#{github_url}/#{repo}.git +refs/heads/*:refs/pr/#{repo}/*")
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def github_url
|
170
|
+
host = git("config --get-all github.host")
|
171
|
+
if host.size > 0
|
172
|
+
host
|
173
|
+
else
|
174
|
+
'github.com'
|
137
175
|
end
|
138
176
|
end
|
139
177
|
|
@@ -162,15 +200,50 @@ class GitPulls
|
|
162
200
|
info.to_s.gsub("\n", ' ')
|
163
201
|
end
|
164
202
|
|
203
|
+
|
204
|
+
# PRIVATE REPOSITORIES ACCESS
|
205
|
+
|
206
|
+
def github_username
|
207
|
+
git("config --get-all github.user")
|
208
|
+
end
|
209
|
+
|
210
|
+
def github_token
|
211
|
+
git("config --get-all github.token")
|
212
|
+
end
|
213
|
+
|
165
214
|
# API/DATA HELPER FUNCTIONS #
|
215
|
+
|
216
|
+
def github_credentials_provided?
|
217
|
+
if github_token.empty? && github_username.empty?
|
218
|
+
return false
|
219
|
+
end
|
220
|
+
true
|
221
|
+
end
|
222
|
+
|
223
|
+
def authentication_options
|
224
|
+
if github_credentials_provided?
|
225
|
+
options = {:basic_auth => {:username => "#{github_username}/token:#{github_token}"}}
|
226
|
+
end
|
227
|
+
options || {}
|
228
|
+
end
|
166
229
|
|
167
230
|
def get_pull_info
|
168
231
|
get_data(PULLS_CACHE_FILE)['pulls']
|
169
232
|
end
|
170
233
|
|
234
|
+
def get_repo_visibility
|
235
|
+
# This would fail if the repository was private and user did not provide github token
|
236
|
+
if github_credentials_provided?
|
237
|
+
repo_path = "/repos/show/#{repo_info[0]}/#{repo_info[1]}"
|
238
|
+
repo_response = HTTParty.get("https://#{github_url}/api/v2/json" << repo_path, authentication_options)
|
239
|
+
repo_response['repository']['private'] if repo_response['repository']
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
171
243
|
def cache_pull_info
|
172
244
|
path = "/pulls/#{@user}/#{@repo}/open"
|
173
|
-
|
245
|
+
puts "https://#{github_url}/api/v2/json"
|
246
|
+
response = HTTParty.get("https://#{github_url}/api/v2/json" << path, authentication_options)
|
174
247
|
save_data(response, PULLS_CACHE_FILE)
|
175
248
|
end
|
176
249
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-pulls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 2
|
8
9
|
- 1
|
9
|
-
|
10
|
-
version: 0.1.0
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Scott Chacon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-03 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -46,6 +46,20 @@ dependencies:
|
|
46
46
|
version: "0"
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: launchy
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
49
63
|
description: " git-pulls facilitates github pull requests.\n"
|
50
64
|
email: schacon@gmail.com
|
51
65
|
executables:
|