git-issue 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- $KCODE="UTF8" if RUBY_VERSION < '1.9.0'
4
+ if RUBY_VERSION < '1.9.0'
5
+ $KCODE = "UTF8"
6
+ else
7
+ Encoding.default_external = Encoding.find('UTF-8')
8
+ end
5
9
 
6
10
  require 'pp'
7
11
  require 'rubygems'
@@ -18,6 +22,8 @@ require 'active_support/all'
18
22
  require 'shellwords'
19
23
  require 'term/ansicolor'
20
24
 
25
+ Term::ANSIColor::coloring = STDOUT.isatty && RUBY_PLATFORM.downcase !~ /mswin(?!ce)|mingw|bccwin|cygwin/
26
+
21
27
  module GitIssue
22
28
  class Command
23
29
  attr_reader :name, :short_name, :description
@@ -77,6 +77,33 @@ class GitIssue::Base
77
77
  system "git checkout #{cb}"
78
78
  end
79
79
 
80
+ def cherry(option = {})
81
+ upstream = options[:upstream]
82
+ head = options[:head]
83
+
84
+ commits = %x(git cherry -v #{upstream} #{head}).split(/\n/).map{|s|
85
+ s.scan(/^([+-])\s(\w+)\s(.*)/).first
86
+ }.select{|_, _, msg| msg =~ /#[0-9]+/ }.map{|diff, sha1, msg|
87
+ msg.scan(/#([0-9]+)/).flatten.map{|ticket| [diff, sha1, msg, ticket]}
88
+ }.flatten(1)
89
+
90
+ commits.group_by{|d, _, _, n| [d, n]}.each do |k, records|
91
+ diff, ticket = k
92
+ c = case diff
93
+ when "-" then :red
94
+ when "+" then :green
95
+ end
96
+
97
+ issue = fetch_issue(ticket, options)
98
+
99
+ puts "#{apply_colors(diff, c)} #{oneline_issue(issue, options)}"
100
+ if options[:verbose]
101
+ records.each {|_, sha1, msg| puts " #{sha1} #{msg}" }
102
+ puts ""
103
+ end
104
+ end
105
+ end
106
+
80
107
  def commands
81
108
  [
82
109
  GitIssue::Command.new(:show, :s, 'show given issue summary. if given no id, geuss id from current branch name.'),
@@ -86,6 +113,7 @@ class GitIssue::Base
86
113
  GitIssue::Command.new(:add, :a, 'create issue.'),
87
114
  GitIssue::Command.new(:update, :u, 'update issue properties. if given no id, geuss id from current branch name.'),
88
115
  GitIssue::Command.new(:branch, :b, "checout to branch using specified issue id. if branch dose'nt exisits, create it. (ex ticket/id/<issue_id>)"),
116
+ GitIssue::Command.new(:cherry, :chr, 'find issue not merged upstream.'),
89
117
 
90
118
  GitIssue::Command.new(:publish,:pub, "push branch to remote repository and set upstream "),
91
119
  GitIssue::Command.new(:rebase, :rb, "rebase branch onto specific newbase"),
@@ -252,6 +280,9 @@ class GitIssue::Base
252
280
  opts.on("--remote=VALUE", 'on publish, remote repository to push branch ') {|v| @options[:remote] = v}
253
281
  opts.on("--onto=VALUE", 'on rebase, start new branch with HEAD equal to "newbase" ') {|v| @options[:onto] = v}
254
282
 
283
+ opts.on("--upstream=VALUE", 'on cherry, upstream branch to compare against. default is tracked remote branch') {|v| @options[:upstream] = v}
284
+ opts.on("--head=VALUE", 'on cherry, working branch. defaults to HEAD') {|v| @options[:head] = v}
285
+
255
286
  opts.on("--no-color", "turn off colored output"){@no_color = true }
256
287
  opts.on("--debug", "debug print"){@debug= true }
257
288
  }
@@ -269,5 +300,16 @@ class GitIssue::Base
269
300
  def apply_colors(str, *colors)
270
301
  @no_color.present? ? str : (colors.map(&method(:send)) + [str, reset]).join
271
302
  end
303
+
304
+ def connection(host, port)
305
+ env = ENV['http_proxy'] || ENV['HTTP_PROXY']
306
+ if env
307
+ uri = URI(env)
308
+ proxy_host, proxy_port = uri.host, uri.port
309
+ Net::HTTP::Proxy(proxy_host, proxy_port).new(host, port)
310
+ else
311
+ Net::HTTP.new(host, port)
312
+ end
313
+ end
272
314
  end
273
315
 
@@ -267,7 +267,7 @@ class GitIssue::Github < GitIssue::Base
267
267
  puts '-' * 80
268
268
  end
269
269
 
270
- https = Net::HTTP.new(uri.host, uri.port)
270
+ https = connection(uri.host, uri.port)
271
271
  https.use_ssl = true
272
272
  https.verify_mode = @ssl_options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_NONE
273
273
 
@@ -39,13 +39,29 @@ class Redmine < GitIssue::Base
39
39
 
40
40
  def list(options = {})
41
41
  url = to_url('issues')
42
- params = {"limit" => options[:max_count] || 100 }
42
+ params = {"limit" => options[:max_count] || "100" }
43
43
  params.merge!("assigned_to_id" => "me") if options[:mine]
44
44
  params.merge!(Hash[*(options[:query].split("&").map{|s| s.split("=") }.flatten)]) if options[:query]
45
45
 
46
- json = fetch_json(url, params)
46
+ param_list = Hash[*params.map{|k,v| [k,v.split(/,/)] }.flatten(1)]
47
+ keys = param_list.keys
48
+ pl,*pls = param_list.values
49
+
50
+ jsons = pl.product(*pls).map{|vs| Hash[*keys.zip(vs).flatten]}.map{|p|
51
+ fetch_json(url, p)['issues']
52
+ }.flatten
53
+
54
+ known_ids = []
55
+ issues = jsons.reject{|i|
56
+ known = known_ids.include?(i["id"])
57
+ known_ids << i['id'] unless known
58
+ known
59
+ }
60
+
61
+ # json = fetch_json(url, params)
47
62
 
48
- output_issues(json['issues'])
63
+ # output_issues(json['issues'])
64
+ output_issues(issues)
49
65
  end
50
66
 
51
67
  def mine(options = {})
@@ -135,12 +151,15 @@ class Redmine < GitIssue::Base
135
151
  end
136
152
 
137
153
  def local(option = {})
138
-
139
- brances = %x(git branch).split(/\n/).map{|b| b.scan(/.*ticket\D*(\d+).*/).first }.reject{|r| r.nil?}.map{|r| r.first }
140
-
141
- issues = brances.map{|ticket_id| fetch_issue(ticket_id) }
142
-
143
- output_issues(issues)
154
+ branches = %x(git branch).split(/\n/).select{|b| b.scan(/(\d+)_/).present?}.map{|b| b.gsub(/^(\s+|\*\s+)/, "")}
155
+ branches.each do |b|
156
+ puts b
157
+ issues = b.scan(/(\d+)_/).map{|ticket_id| fetch_issue(ticket_id) rescue nil}.compact
158
+ issues.each do |i|
159
+ puts " #{oneline_issue(i, options)}"
160
+ end
161
+ puts ""
162
+ end
144
163
  end
145
164
 
146
165
  def project(options = {})
@@ -203,7 +222,7 @@ class Redmine < GitIssue::Base
203
222
  puts '-' * 80
204
223
  end
205
224
 
206
- http = Net::HTTP.new(uri.host, uri.port)
225
+ http = connection(uri.host, uri.port)
207
226
  if uri.scheme == 'https'
208
227
  http.use_ssl = true
209
228
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -262,7 +281,7 @@ class Redmine < GitIssue::Base
262
281
  end
263
282
 
264
283
  def oneline_issue(issue, options = {})
265
- "##{issue['id']} #{issue['subject']}"
284
+ "#{apply_fmt_colors(:id, "##{issue['id']}")} #{issue['subject']}"
266
285
  end
267
286
 
268
287
  def format_issue(issue, options)
@@ -471,7 +490,12 @@ class Redmine < GitIssue::Base
471
490
  end
472
491
 
473
492
  def output_issues(issues)
474
- if options[:raw_id]
493
+
494
+ if options[:oneline]
495
+ issues.each do |i|
496
+ puts oneline_issue(i, options)
497
+ end
498
+ elsif options[:raw_id]
475
499
  issues.each do |i|
476
500
  puts i['id']
477
501
  end
@@ -568,6 +592,7 @@ MSG
568
592
  opts.on("--supperss_changesets", "-c", "do not show issue changesets"){|v| @options[:supperss_changesets] = true}
569
593
  opts.on("--query=VALUE",'-q=VALUE', "filter query of listing tickets") {|v| @options[:query] = v}
570
594
 
595
+ opts.on("--mine", "lists issues assigned_to me"){|v| @options[:mine] = true}
571
596
  opts.on("--project_id=VALUE", "use the given value to create subject"){|v| @options[:project_id] = v}
572
597
  opts.on("--description=VALUE", "use the given value to create subject"){|v| @options[:description] = v}
573
598
  opts.on("--subject=VALUE", "use the given value to create/update subject"){|v| @options[:subject] = v}
@@ -1,3 +1,3 @@
1
1
  module GitIssue
2
- VERSION = "0.8.5"
2
+ VERSION = "0.8.6"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-issue
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 5
10
- version: 0.8.5
9
+ - 6
10
+ version: 0.8.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tomohito Ozaki
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-09 00:00:00 +09:00
18
+ date: 2012-10-25 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency