Created
April 29, 2012 14:38
-
-
Save jan-matejka/2550857 to your computer and use it in GitHub Desktop.
rake task for exporting redmine 1.2 issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| desc 'export issues from given project(s) and having given tracker' | |
| require 'config/environment' | |
| require 'csv' | |
| task :export_stories, :project, :tracker, :outfile, :recursive do |t, args| | |
| #puts "args: #{args}" | |
| args = args.to_hash | |
| if args.empty? then | |
| puts "Usage: <project-identifier>,<tracker-name>,<outfile>,<recursive> | |
| recursive = 1|0" | |
| exit | |
| end | |
| args_req = [:project, :tracker, :outfile] | |
| for arg in args_req | |
| if not args.has_key? arg then | |
| puts "requires arg: #{arg}" | |
| exit | |
| end | |
| end | |
| if args.key? :recursive and args[:recursive] == '1' then | |
| args[:recursive] = true | |
| else | |
| args[:recursive] = false | |
| end | |
| ########################################################### | |
| require 'app/models/issue' | |
| require 'app/models/project' | |
| require 'app/models/tracker' | |
| print "\n\n" | |
| tracker = Tracker.find(:first, :conditions => { :name => args[:tracker]}) | |
| puts "Found tracker: #{tracker.name}" | |
| project = Project.find(:first, :conditions => { :identifier => args[:project]}) | |
| puts "Found project: #{project}" | |
| projects = [project.id] | |
| if args[:recursive] then | |
| puts "Recursing into projects #{project.children.map { |i| i.name }.join(" ")}" | |
| projects += project.children.map { |i| i.id } | |
| end | |
| issues = Issue.find(:all, :conditions => { :tracker_id => tracker.id, :project_id => projects }, :order => "project_id" ) | |
| CSV.open(args[:outfile], 'w') { |writer| | |
| writer << ['Project', 'Status', 'Subject', 'Description', 'Target Version', 'Planned'] | |
| issues.each { |i| | |
| writer << [i.project, i.status, i.subject, i.description, i.fixed_version, i.estimated_hours.nil? ? 'Ne' : 'Ano'] | |
| } | |
| writer.close() | |
| } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment