git_pr 0.0.14.beta0 → 0.0.14.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/git-pr +119 -38
- data/lib/git_pr/merge.rb +0 -7
- data/lib/git_pr/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd50ce4e2cfb2bba6e49dea8ec04f6d3467b93bd
|
4
|
+
data.tar.gz: 753a8cfd5bebc83704c0daee2503791a237f953c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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]
|
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
|
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
|
65
|
-
diff:
|
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:
|
68
|
-
|
69
|
-
|
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 <
|
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
|
-
|
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
|
129
|
-
case
|
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
|
-
|
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 =
|
180
|
+
command = alias_to_command(ARGV.shift)
|
155
181
|
|
156
|
-
# Check for the special command help. Support "git pr help" and "git pr help <
|
182
|
+
# Check for the special command help. Support "git pr help" and "git pr help <command>"
|
157
183
|
if command == "help"
|
158
|
-
command =
|
159
|
-
if
|
160
|
-
puts
|
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 !
|
194
|
+
if !commands[command]
|
169
195
|
puts global_options
|
170
196
|
exit
|
171
197
|
end
|
172
198
|
|
173
|
-
# Parse
|
199
|
+
# Parse command options. Print help if any unrecognized
|
174
200
|
begin
|
175
|
-
options[command].additional_arguments =
|
201
|
+
options[command].additional_arguments = commands[command].permute!
|
176
202
|
rescue OptionParser::InvalidOption => e
|
177
203
|
puts e
|
178
|
-
puts
|
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
|
202
|
-
|
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
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
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
|
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
|
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
|
data/lib/git_pr/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|