git-issue 0.8.0 → 0.8.1

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.
data/lib/git_issue.rb CHANGED
@@ -38,9 +38,9 @@ module GitIssue
38
38
  end
39
39
 
40
40
 
41
- def configured_value(name)
41
+ def configured_value(name, trim = true)
42
42
  res = `git config issue.#{name}`
43
- res.strip
43
+ trim ? res.strip : res
44
44
  end
45
45
 
46
46
  def global_configured_value(name)
@@ -278,7 +278,7 @@ class Redmine < GitIssue::Base
278
278
  add_prop_name = Proc.new{|name|
279
279
  title = property_title(name)
280
280
  value = ''
281
- value = issue[name]['name'] if issue[name] && issue[name]['name']
281
+ value = "#{issue[name]['name']}(#{issue[name]['id']})" if issue[name] && issue[name]['name']
282
282
  props << [title, value]
283
283
  }
284
284
 
@@ -396,22 +396,53 @@ class Redmine < GitIssue::Base
396
396
  end
397
397
 
398
398
  def format_issue_tables(issues_json)
399
- issues = issues_json.map{ |issue|
400
- project = issue['project']['name'] rescue ""
401
- tracker = issue['tracker']['name'] rescue ""
402
- status = issue['status']['name'] rescue ""
403
- assigned_to = issue['assigned_to']['name'] rescue ""
404
- [issue['id'], project, tracker, status, issue['subject'], assigned_to, issue['updated_on']]
399
+ name_of = lambda{|issue, name| issue[name]['name'] rescue ""}
400
+
401
+ issues = issues_json.map{ |issue|{
402
+ :id => sprintf("#%-4d", issue['id']), :subject => issue['subject'],
403
+ :project => name_of.call(issue, 'project'),
404
+ :tracker => name_of.call(issue, 'tracker'),
405
+ :status => name_of.call(issue, 'status'),
406
+ :assigned_to => name_of.call(issue, 'assigned_to'),
407
+ :version => name_of.call(issue, 'fixed_version'),
408
+ :priority => name_of.call(issue, 'priority'),
409
+ :category => name_of.call(issue, 'category'),
410
+ :updated_on => issue['updated_on'].to_date
411
+ }}
412
+
413
+ max_of = lambda{|name, limit|
414
+ max = issues.map{|i| mlength(i[name])}.max
415
+ [max, limit].min
416
+ }
417
+ max_length = {
418
+ :project => max_of.call(:project, 20),
419
+ :tracker => max_of.call(:tracker, 20),
420
+ :status => max_of.call(:status, 20),
421
+ :assigned_to => max_of.call(:assigned_to, 20),
422
+ :version => max_of.call(:version, 20),
423
+ :priority => max_of.call(:priority, 20),
424
+ :category => max_of.call(:category, 20),
425
+ :subject => 80
405
426
  }
406
427
 
407
- p_max = issues.map{|i| mlength(i[1])}.max
408
- t_max = issues.map{|i| mlength(i[2])}.max
409
- s_max = issues.map{|i| mlength(i[3])}.max
410
- a_max = issues.map{|i| mlength(i[5])}.max
411
-
412
- issues.map {|i|
413
- sprintf("#%-4d %s %s %s %s %s %s", i[0].to_i, mljust(i[1], p_max), mljust(i[2], t_max), mljust(i[3], s_max), mljust(i[4], 80), mljust(i[5], a_max), to_date(i[6]))
428
+ fmt = configured_value('defaultformat', false)
429
+ fmt_chars = { :I => :id, :S => :subject,
430
+ :A => :assigned_to, :s => :status, :T => :tracker,
431
+ :P => :priority, :p => :project, :V => :version,
432
+ :C => :category, :U => :updated_on }
433
+
434
+ format_to = lambda{|i|
435
+ res = fmt.dup
436
+ fmt_chars.each do |k, v|
437
+ res.gsub!(/\%(\d*)#{k}/) do |s|
438
+ max = $1.blank? ? max_length[v] : $1.to_i
439
+ max ? mljust(i[v], max) : i[v]
440
+ end
441
+ end
442
+ res
414
443
  }
444
+
445
+ issues.map{|i| format_to.call(i) }
415
446
  end
416
447
 
417
448
  def output_issues(issues)
@@ -445,7 +476,10 @@ class Redmine < GitIssue::Base
445
476
  end
446
477
 
447
478
  def read_issue_from_editor(issue, options = {})
448
- id_of = lambda{|name| issue[name] ? issue[name]["id"] : ""}
479
+ id_of = lambda{|name| issue[name] ? sprintf('%2s : %s', issue[name]["id"] , issue[name]['name'] ): ""}
480
+
481
+ memofile = configured_value('memofile')
482
+ memo = File.open(memofile).read.lines.map{|l| "# #{l}"}.join("") unless memofile.blank?
449
483
 
450
484
  message = <<-MSG
451
485
  #{issue["subject"].present? ? issue["subject"].chomp : "### subject here ###"}
@@ -458,14 +492,16 @@ Category : #{id_of.call("category")}
458
492
  Assigned : #{id_of.call("assigned_to")}
459
493
  Version : #{id_of.call("fixed_version")}
460
494
 
461
- ### notes here ###
495
+ # Please enter the notes for your changes. Lines starting
496
+ # with '#' will be ignored, and an empty message aborts.
497
+ #{memo}
462
498
  MSG
463
499
  body = get_body_from_editor(message)
464
500
 
465
501
  subject, dummy, project_id, tracker_id, status_id, priority_id, category_id, assigned_to_id, fixed_version_id, dummy, *notes = body.lines.to_a
466
502
 
467
503
  notes = if notes.present?
468
- notes.reject{|line| line.chomp == "### notes here ###"}.join("")
504
+ notes.reject{|l| l =~ /^#/}.join("")
469
505
  else
470
506
  nil
471
507
  end
@@ -485,7 +521,7 @@ MSG
485
521
  end
486
522
 
487
523
  take_id = lambda{|s|
488
- x, i = s.chomp.split(":")
524
+ x, i, name = s.chomp.split(":")
489
525
  i.present? ? i.strip.to_i : nil
490
526
  }
491
527
 
@@ -1,3 +1,3 @@
1
1
  module GitIssue
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
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: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
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-03-02 00:00:00 +09:00
18
+ date: 2012-04-11 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency