git-pulls 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/git-pulls.rb +48 -19
  2. metadata +2 -2
@@ -51,8 +51,8 @@ class GitPulls
51
51
  def usage
52
52
  puts <<-USAGE
53
53
  Usage: git pulls update
54
- or: git pulls list [--reverse]
55
- or: git pulls show <number> [--full]
54
+ or: git pulls list [state] [--reverse]
55
+ or: git pulls show <number> [--comments] [--full]
56
56
  or: git pulls browse <number>
57
57
  or: git pulls merge <number>
58
58
  or: git pulls checkout [--force]
@@ -96,22 +96,38 @@ Usage: git pulls update
96
96
 
97
97
  def show
98
98
  num = @args.shift
99
- option = @args.shift
99
+ optiona = @args.shift
100
+ optionb = @args.shift
100
101
  if p = pull_num(num)
102
+ comments = []
103
+ if optiona == '--comments' || optionb == '--comments'
104
+ i_comments = Octokit.issue_comments("#{@user}/#{@repo}", num)
105
+ p_comments = Octokit.pull_request_comments("#{@user}/#{@repo}", num)
106
+ c_comments = Octokit.commit_comments(p['head']['repo']['full_name'], p['head']['sha'])
107
+ comments = (i_comments | p_comments | c_comments).sort_by {|i| i['created_at']}
108
+ end
101
109
  puts "Number : #{p['number']}"
102
110
  puts "Label : #{p['head']['label']}"
111
+ puts "Creator : #{p['user']['login']}"
103
112
  puts "Created : #{p['created_at']}"
104
- puts "Votes : #{p['votes']}"
105
- puts "Comments : #{p['comments']}"
106
113
  puts
107
114
  puts "Title : #{p['title']}"
108
- puts "Body :"
109
115
  puts
110
116
  puts p['body']
111
117
  puts
112
118
  puts '------------'
113
119
  puts
114
- if option == '--full'
120
+ comments.each do |c|
121
+ puts "Comment : #{c['user']['login']}"
122
+ puts "Created : #{c['created_at']}"
123
+ puts "File : #{c['path']}:L#{c['line'] || c['position'] || c['original_position']}" unless c['path'].nil?
124
+ puts
125
+ puts c['body']
126
+ puts
127
+ puts '------------'
128
+ puts
129
+ end
130
+ if optiona == '--full' || optionb == '--full'
115
131
  exec "git diff --color=always HEAD...#{p['head']['sha']}"
116
132
  else
117
133
  puts "cmd: git diff HEAD...#{p['head']['sha']}"
@@ -132,10 +148,17 @@ Usage: git pulls update
132
148
  end
133
149
 
134
150
  def list
135
- option = @args.shift
151
+ state = @args.shift
152
+
153
+ if not ['open', 'closed'].include?(state)
154
+ state = 'open'
155
+ option = state
156
+ else
157
+ option = @args.shift
158
+ end
136
159
 
137
- puts "Open Pull Requests for #{@user}/#{@repo}"
138
- pulls = get_pull_info
160
+ puts state.capitalize + " Pull Requests for #{@user}/#{@repo}"
161
+ pulls = state == 'open' ? get_open_pull_info : get_closed_pull_info
139
162
  pulls.reverse! if option == '--reverse'
140
163
 
141
164
  count = 0
@@ -153,13 +176,13 @@ Usage: git pulls update
153
176
  end
154
177
  end
155
178
  if count == 0
156
- puts ' -- no open pull requests --'
179
+ puts ' -- no ' + state + ' pull requests --'
157
180
  end
158
181
  end
159
182
 
160
183
  def checkout
161
184
  puts "Checking out all open pull requests for #{@user}/#{@repo}"
162
- pulls = get_pull_info
185
+ pulls = get_open_pull_info
163
186
  pulls.each do |pull|
164
187
  branch_ref = pull['head']['ref']
165
188
  puts "> #{branch_ref} into pull-#{branch_ref}"
@@ -176,7 +199,7 @@ Usage: git pulls update
176
199
 
177
200
  def fetch_stale_forks
178
201
  puts "Checking for forks in need of fetching"
179
- pulls = get_pull_info
202
+ pulls = get_open_pull_info | get_closed_pull_info
180
203
  repos = {}
181
204
  pulls.each do |pull|
182
205
  next if pull['head']['repository'].nil? # Fork has been deleted
@@ -264,8 +287,12 @@ Usage: git pulls update
264
287
  true
265
288
  end
266
289
 
267
- def get_pull_info
268
- get_data(PULLS_CACHE_FILE)['pulls']
290
+ def get_closed_pull_info
291
+ get_data(PULLS_CACHE_FILE)['closed']
292
+ end
293
+
294
+ def get_open_pull_info
295
+ get_data(PULLS_CACHE_FILE)['open']
269
296
  end
270
297
 
271
298
  def get_data(file)
@@ -273,8 +300,9 @@ Usage: git pulls update
273
300
  end
274
301
 
275
302
  def cache_pull_info
276
- response = Octokit.pull_requests("#{@user}/#{@repo}")
277
- save_data({'pulls' => response}, PULLS_CACHE_FILE)
303
+ response_o = Octokit.pull_requests("#{@user}/#{@repo}")
304
+ response_c = Octokit.pull_requests("#{@user}/#{@repo}", 'closed')
305
+ save_data({'open' => response_o, 'closed' => response_c}, PULLS_CACHE_FILE)
278
306
  end
279
307
 
280
308
  def save_data(data, file)
@@ -284,8 +312,9 @@ Usage: git pulls update
284
312
  end
285
313
 
286
314
  def pull_num(num)
287
- data = get_pull_info
288
- data.select { |p| p['number'].to_s == num.to_s }.first
315
+ pull = get_open_pull_info.select { |p| p['number'].to_s == num.to_s }.first
316
+ pull ||= get_closed_pull_info.select { |p| p['number'].to_s == num.to_s }.first
317
+ pull
289
318
  end
290
319
 
291
320
  def github_insteadof_matching(c, u)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-pulls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-21 00:00:00.000000000 Z
13
+ date: 2013-02-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json