git_pr 0.0.14.beta0 → 0.0.14.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1a52c54177aa30fbf3c66ae58700877bc84c539
4
- data.tar.gz: 11e1faab37fcddee44be6e33093832daa48a98d7
3
+ metadata.gz: fd50ce4e2cfb2bba6e49dea8ec04f6d3467b93bd
4
+ data.tar.gz: 753a8cfd5bebc83704c0daee2503791a237f953c
5
5
  SHA512:
6
- metadata.gz: 55b6ea86c912b8d15051f2cd32b01cdeb09c3068a40cdf0d0c8d579615581e35886f408f418e22f6e8f171a0968884fe4ed35048e0fe1c22a5078437b2b37916
7
- data.tar.gz: 4028887f5b4262f19657edc05d4f483922505aad091b3a5b917808449f45472b69008c9b814c47cab9553c4721c17cdaed3e224a2f6f3000200d522eac6e1540
6
+ metadata.gz: b21abd38f9c7131263e51e917b23a85933bc2cc5065778ccf7e15196d5f3a80243fd14a49af0a21c734e4dd7368ce08af2fe8afa1b01de49c9ff3006d22fc95c
7
+ data.tar.gz: 965c8d39ddbf565248fa80b3af80161cd1335e97d76b31ecba2a38dda02d89341dafa70740ffd36e9671560b4b72f6a840e6628d81a1d975582e63c4c315cc49
data/bin/git-pr CHANGED
@@ -20,6 +20,8 @@ require 'pp'
20
20
  $verbose = false
21
21
  $default_remotes = ["origin", "upstream"]
22
22
 
23
+ LIST_STATUS_KEY = "pr.liststatus"
24
+
23
25
  options = OpenStruct.new(:help => false,
24
26
  :verbose => false,
25
27
  :project => nil,
@@ -28,13 +30,14 @@ options = OpenStruct.new(:help => false,
28
30
  :difftool => OpenStruct.new(),
29
31
  :list => OpenStruct.new(),
30
32
  :merge => OpenStruct.new(),
31
- :open => OpenStruct.new())
33
+ :open => OpenStruct.new(),
34
+ :status => OpenStruct.new())
32
35
 
33
36
  global_options = OptionParser.new do |opts|
34
37
  opts.banner = <<eos
35
38
  git_pr version #{GitPr::VERSION}
36
39
 
37
- Usage: git pr [options] subcommand [options]
40
+ Usage: git pr [options] command [options]
38
41
  eos
39
42
 
40
43
  opts.separator "\nGlobal options"
@@ -44,7 +47,7 @@ eos
44
47
  "The GitHub project to access. Can be a named remote, or a GitHub project in",
45
48
  "<user>/<project> form. Defaults to the GitHub project that the \"origin\"",
46
49
  "or \"upstream\" remote points to. You can override the default remote",
47
- "with git config. Run: 'git config --add pr.defaultremote <remote_name>'"
50
+ "with git config. Run: 'git config --add #{GitPr::GitHub::DEFAULT_REMOTE_KEY} <remote_name>'"
48
51
  ) do |project|
49
52
  options.project = project
50
53
  end
@@ -61,14 +64,15 @@ eos
61
64
 
62
65
  opts.separator <<eos
63
66
 
64
- Valid subcommands:
65
- diff: Use "git diff" to display a diff for a pull request
67
+ Valid commands:
68
+ diff: Use "git diff" to display a diff for a pull request
66
69
  difftool: Like "diff", but uses "git difftool" instead
67
- list: List open pull requests
68
- merge: Merge and close a pull request
69
- open: Open a PR page on the web
70
+ list: List open pull requests
71
+ status: Show the detailed status for a pull request
72
+ merge: Merge and close a pull request
73
+ open: Open a PR page on the web
70
74
 
71
- Run "git pr <subcommand> -h" for help with subcommands.
75
+ Run "git pr help <command>" for more detailed help.
72
76
 
73
77
  eos
74
78
  end
@@ -86,7 +90,7 @@ eos
86
90
  end
87
91
  end
88
92
 
89
- subcommands = {
93
+ commands = {
90
94
  'diff' => make_diff_argument_parser("diff"),
91
95
  'difftool' => make_diff_argument_parser("difftool"),
92
96
  'list' => OptionParser.new do |opts|
@@ -98,6 +102,16 @@ subcommands = {
98
102
  options.list.user = user
99
103
  end
100
104
 
105
+ opts.on("-s", "--[no-]status",
106
+ "Include PR status in the output. Including status is slower,",
107
+ "as each PR's status must be queried individually. You can set",
108
+ "the default behavior with git config:",
109
+ "\n",
110
+ "git config --bool --add #{LIST_STATUS_KEY} true"
111
+ ) do |s|
112
+ options.list.status = s
113
+ end
114
+
101
115
  opts.separator ""
102
116
  end,
103
117
  'merge' => OptionParser.new do |opts|
@@ -122,11 +136,21 @@ argument is passed, open a PR page for the current branch.
122
136
 
123
137
  eos
124
138
 
139
+ end,
140
+ 'status' => OptionParser.new do |opts|
141
+ opts.banner = "Usage: git pr status [pr_number|branch]"
142
+
143
+ opts.separator <<eos
144
+
145
+ Report detailed pull request status for the passed in PR number or
146
+ branch.
147
+
148
+ eos
125
149
  end
126
150
  }
127
151
 
128
- def alias_to_subcommand(subcommand)
129
- case subcommand
152
+ def alias_to_command(command)
153
+ case command
130
154
  when "dt", /^difft/
131
155
  "difftool"
132
156
  when "d", /^d/
@@ -137,8 +161,10 @@ def alias_to_subcommand(subcommand)
137
161
  "list"
138
162
  when "ci", /^m/
139
163
  "merge"
164
+ when /^s/
165
+ "status"
140
166
  else
141
- subcommand
167
+ command
142
168
  end
143
169
  end
144
170
 
@@ -151,13 +177,13 @@ rescue OptionParser::InvalidOption => e
151
177
  exit
152
178
  end
153
179
 
154
- command = alias_to_subcommand(ARGV.shift)
180
+ command = alias_to_command(ARGV.shift)
155
181
 
156
- # Check for the special command help. Support "git pr help" and "git pr help <subcommand>"
182
+ # Check for the special command help. Support "git pr help" and "git pr help <command>"
157
183
  if command == "help"
158
- command = alias_to_subcommand(ARGV.shift)
159
- if subcommands[command]
160
- puts subcommands[command]
184
+ command = alias_to_command(ARGV.shift)
185
+ if commands[command]
186
+ puts commands[command]
161
187
  else
162
188
  puts global_options
163
189
  end
@@ -165,17 +191,17 @@ if command == "help"
165
191
  end
166
192
 
167
193
  # Unrecognized command? Print help and exit
168
- if !subcommands[command]
194
+ if !commands[command]
169
195
  puts global_options
170
196
  exit
171
197
  end
172
198
 
173
- # Parse subcommand options. Print help if any unrecognized
199
+ # Parse command options. Print help if any unrecognized
174
200
  begin
175
- options[command].additional_arguments = subcommands[command].permute!
201
+ options[command].additional_arguments = commands[command].permute!
176
202
  rescue OptionParser::InvalidOption => e
177
203
  puts e
178
- puts subcommands[command]
204
+ puts commands[command]
179
205
  exit
180
206
  end
181
207
 
@@ -198,8 +224,37 @@ elsif File.exists? File.join(git_dir, '.git')
198
224
  git = Git.open git_dir, :repository => submodule_git_dir, :index => File.join(submodule_git_dir, 'index')
199
225
  end
200
226
 
201
- def pull_summary(pull)
202
- return "##{pull[:number]} from #{pull[:user][:login]}: #{pull[:title]}"
227
+ def pull_request_status(pull)
228
+ Octokit.combined_status(pull.base.repo.full_name, pull.head.sha)
229
+ end
230
+
231
+ def status_summary(state)
232
+ case state
233
+ when "failure"
234
+ STDOUT.tty? ? "\u2717".red : "-"
235
+ when "success"
236
+ STDOUT.tty? ? "\u2713".green : "+"
237
+ else
238
+ STDOUT.tty? ? "\u25CF".yellow : "O"
239
+ end
240
+ end
241
+
242
+ def pull_summary(pull, include_status)
243
+ if include_status
244
+ combined_status = pull_request_status(pull)
245
+ status_string = "#{status_summary(combined_status.state)} "
246
+ else
247
+ status_string = ""
248
+ end
249
+ "#{status_string}##{pull[:number]} from #{pull[:user][:login]}: #{pull[:title]}"
250
+ end
251
+
252
+ def find_pull_request_from_command_line_argument(git, github_project, argument)
253
+ # Look for an existing pull request that fits. A branch name or PR number can
254
+ # be passed on the command line, or we default to the current branch.
255
+ pulls = Octokit.pulls github_project
256
+ source = argument || git.current_branch
257
+ pulls.any? ? pulls.find { |p| p.head.ref == source || p.number.to_s == source } : nil
203
258
  end
204
259
 
205
260
  # Figure out what GitHub project we're dealing with.
@@ -221,25 +276,25 @@ when "list"
221
276
  if options.list.user
222
277
  pulls = pulls.select { |p| p[:user][:login] == options.list.user }
223
278
  end
279
+ include_status = false
280
+ if options.list.to_h.has_key?(:status)
281
+ include_status = options.list.status
282
+ elsif git.config.has_key? LIST_STATUS_KEY
283
+ include_status = git.config(LIST_STATUS_KEY) == 'true'
284
+ end
224
285
 
225
286
  if pulls.any?
226
- pulls.each { |p| puts pull_summary(p) }
287
+ pulls.each { |p| puts pull_summary(p, include_status) }
227
288
  else
228
289
  puts "No open pull requests found.".yellow
229
290
  end
230
291
 
231
292
  when "open"
232
-
233
- # Look for an existing pull request that fits. A branch name or PR number can
234
- # be passed on the command line, or we default to the current branch.
235
- pulls = Octokit.pulls github_project
236
- source = options[command].additional_arguments.shift || git.current_branch
237
- if pulls.any?
238
- pull = pulls.find { |p| p.head.ref == source || p.number.to_s == source }
239
- if pull
240
- `open #{pull.html_url}`
241
- exit
242
- end
293
+ argument = options[command].additional_arguments.shift
294
+ pull = find_pull_request_from_command_line_argument git, github_project, argument
295
+ if pull
296
+ `open #{pull.html_url}`
297
+ exit
243
298
  end
244
299
 
245
300
  # We didn't find a matching pull request, so let's try to open the "create
@@ -281,7 +336,7 @@ when "diff", "difftool"
281
336
 
282
337
  unless pull_request
283
338
  puts "Must specify a pull request to diff.\n".red
284
- puts subcommands[command]
339
+ puts commands[command]
285
340
  exit -1
286
341
  end
287
342
 
@@ -290,7 +345,7 @@ when "diff", "difftool"
290
345
  pull = Octokit.pull github_project, pull_request
291
346
  rescue Octokit::NotFound
292
347
  puts "Pull request #{pull_request} not found in #{github_project}.\n".red
293
- puts subcommands[command]
348
+ puts commands[command]
294
349
  exit -1
295
350
  end
296
351
 
@@ -323,4 +378,30 @@ when "diff", "difftool"
323
378
  # Wait for the child
324
379
  Process.wait child
325
380
 
381
+ when "status"
382
+ argument = options[command].additional_arguments.shift
383
+ pull = find_pull_request_from_command_line_argument git, github_project, argument
384
+ unless pull
385
+ puts "No matching pull request found"
386
+ exit 1
387
+ end
388
+
389
+ puts "Pull request #{pull.number}: #{pull.title}"
390
+ statuses = Octokit.statuses(pull.base.repo.full_name, pull.head.sha)
391
+ if statuses.empty?
392
+ puts "No status found."
393
+ exit
394
+ end
395
+
396
+ statuses_by_context = {}
397
+ statuses.sort_by { |s| s.updated_at }.each { |s| statuses_by_context[s.context] = s }
398
+
399
+ max_context = statuses_by_context.map { |c, s| s.context.length }.max
400
+ max_description = statuses_by_context.map { |c, s| s.description.length }.max
401
+
402
+ puts ""
403
+ statuses_by_context.each do |context, status|
404
+ puts "#{status_summary(status.state)} #{status.context.ljust(max_context)} #{status.description.ljust(max_description)} #{status.target_url}"
405
+ end
406
+
326
407
  end
data/lib/git_pr/merge.rb CHANGED
@@ -52,13 +52,6 @@ module GitPr
52
52
  # If the local target branch differs from the remote target branch, they
53
53
  # must be reconciled manually.
54
54
  remote_target_branch = "#{target_remote}/#{target_branch}"
55
- begin
56
- git.diff("remotes/#{remote_target_branch}", target_branch).any?
57
- rescue
58
- puts "Error cracking diff:"
59
- puts git.diff("remotes/#{remote_target_branch}", target_branch).to_s
60
- raise
61
- end
62
55
  if git.diff("remotes/#{remote_target_branch}", target_branch).any?
63
56
  puts "Local branch '#{target_branch}' differs from remote branch '#{remote_target_branch}'. Please reconcile before continuing.".red
64
57
  exit -1
@@ -1,3 +1,3 @@
1
1
  module GitPr
2
- VERSION = "0.0.14.beta0"
2
+ VERSION = "0.0.14.beta1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_pr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14.beta0
4
+ version: 0.0.14.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Sharon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-14 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize