Add support for project name. Better rendering style.

This commit is contained in:
Glenn Y. Rolland 2016-06-29 10:36:20 +02:00
parent 469449a033
commit 52afe426c2
4 changed files with 84 additions and 51 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
Gemfile.lock Gemfile.lock
*.ods
*.ods#

View file

@ -5,3 +5,4 @@ gem 'thor'
gem 'minedig', git: "https://github.com/siman-man/minedig" gem 'minedig', git: "https://github.com/siman-man/minedig"
gem 'rspreadsheet' gem 'rspreadsheet'
gem 'pry' gem 'pry'
gem 'semantic'

View file

@ -5,64 +5,94 @@ require 'minedig'
require 'yaml' require 'yaml'
require 'rspreadsheet' require 'rspreadsheet'
require 'pry' require 'pry'
require 'thor'
require 'semantic'
credential_file = ENV['HOME'] + '/.aoidos/redmine.yml' class Aoidos < Thor
unless File.exist? credential_file
sample_content = "home: 'http://redmine.example.com'\nkey: REDMINE_API_KEY"
raise Errno::ENOENT, "Please create %s file with:\n%s" % [
credential_file, sample_content
]
end
credential = YAML.load_file(credential_file)
redmine = Minedig::Redmine.new do |config|
config.home = credential['home'] # ex: 'http://project.gnuside.com'
config.api_key = credential['key'] # ex: ...
end
book = Rspreadsheet::Workbook.new
tickets = redmine.project('catone-smb-device').tickets(count: :all)
tickets.each do |ticket|
type = case ticket.tracker_id
when 2 then :feature # feature
when 4 then :user_story # user story
else :bug
end
next if type != :user_story
prefix = nil desc "export PROJECT", "Export project user stories"
title = nil def export(project)
sheet = nil target_version = make_version '2.0.0'
if ticket.subject.strip =~ /^(\s*As\s+.*?)\s*,\s+i\s+want\s+to\s+(.*)$/i then credential_file = ENV['HOME'] + '/.aoidos/redmine.yml'
prefix = $1.strip
title = $2.strip
else
raise "Invalid ticket #{ticket.id} - #{ticket.subject}"
end
sheet = book.sheet(prefix) || book.create_worksheet(prefix)
if sheet.rows.size == 0 then unless File.exist? credential_file
[prefix, 'Description', 'Version', 'ID'].each_with_index do |txt,idx| sample_content = "home: 'http://redmine.example.com'\nkey: REDMINE_API_KEY"
cell = sheet.cell(1,idx+1) raise Errno::ENOENT, "Please create %s file with:\n%s" % [
cell.value = txt credential_file, sample_content
cell.format.bold = true ]
cell.format.color = '#FFFFFF'
cell.format.background_color = '#662D91'
end end
credential = YAML.load_file(credential_file)
redmine = Minedig::Redmine.new do |config|
config.home = credential['home'] # ex: 'http://project.gnuside.com'
config.api_key = credential['key'] # ex: ...
end
book = Rspreadsheet::Workbook.new
tickets = redmine.project(project).tickets(count: :all)
tickets.each do |ticket|
type = case ticket.tracker_id
when 2 then :feature # feature
when 4 then :user_story # user story
else :bug
end
next if type != :user_story
prefix = nil
title = nil
sheet = nil
if ticket.subject.strip =~ /^(\s*As\s+.*?)\s*,\s+i\s+want\s+to\s+(.*)$/i then
prefix = $1.strip
title = $2.strip
else
raise "Invalid ticket #{ticket.id} - #{ticket.subject}"
end
sheet = book.sheet(prefix) || book.create_worksheet(prefix)
if sheet.rows.size == 0 then
[prefix, 'Description', 'Version', 'ID'].each_with_index do |txt,idx|
cell = sheet.cell(1,idx+1)
cell.value = txt
cell.format.bold = true
cell.format.color = '#FFFFFF'
cell.format.background_color = '#662D91'
end
end
nextline = sheet.rows.size + 1
ticket_title = "%s%s" % [title[0].upcase, title[1..-1]]
ticket_version =
(ticket.ticket['fixed_version'] || {'name' => ''})['name']
.split(/\s+-\s+/)[0]
ticket_version_obj = make_version ticket_version.gsub(/^v/,'')
puts "[ %- 8d | %- 30.30s | %- 50.50s ]" % [ticket.id, prefix, ticket_title]
[ticket_title, '', ticket_version, ticket.id].each_with_index do |txt,idx|
cell = sheet.cell(nextline,idx+1)
cell.value = txt
if ticket_version_obj <= target_version then
cell.format.bold = true
cell.format.color = '#000000'
else
cell.format.color = '#888888'
end
end
end
book.save(project + '.ods')
end end
nextline = sheet.rows.size + 1 private
ticket_title = "%s%s" % [title[0].upcase, title[1..-1]]
ticket_version = (ticket.ticket['fixed_version'] || {'name' => ''})['name']
puts "[ %- 8d | %- 30.30s | %- 50.50s ]" % [ticket.id, prefix, ticket_title]
[title, '', ticket_version, ticket.id].each_with_index do |txt,idx| def make_version str
cell = sheet.cell(nextline,idx+1) return Semantic::Version.new str
cell.value = txt rescue ArgumentError
make_version str + '.0'
end end
end end
book.save('report.ods')
Aoidos.start(ARGV)

Binary file not shown.