Created
January 14, 2011 11:44
-
-
Save kzk/779506 to your computer and use it in GitHub Desktop.
This file contains 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
require 'rubygems' | |
require 'sqlite3' | |
require 'rexml/document' | |
include SQLite3 | |
target_projects = { | |
"Sedue" => "SQ" | |
} | |
#------------------ | |
def create_mapping(d, fields, table, h) | |
d.execute("SELECT #{fields} FROM #{table}").each { |r| | |
h[r[0]] = r[1] | |
} | |
end | |
def tracker_mapping(t) | |
return "Bug" if t == "バグ" | |
return "New Feature" if t == "機能" | |
return "Bug" | |
end | |
def user_mapping(u) | |
users = ["eiichiro", "hillbig", "kzk", "nobu", "nvaca", "oxy", "repeatedly", "tkng"] | |
return u if users.include? u | |
return "kzk" | |
end | |
def create_mapping_with_pid(d, pid, fields, table, h) | |
d.execute("SELECT #{fields} FROM #{table} WHERE project_id=#{pid}").each { |r| | |
h[r[0]] = r[1] | |
} | |
end | |
def process_tag(t) | |
t = t.strip | |
return t if t.nil? or t.empty? | |
return t.gsub(/<pre>/, "{code}").gsub(/<\/pre>/, "{code}") | |
end | |
def lookup(id, h) | |
return "" if id.nil? | |
h[id] | |
end | |
def jl_tag(tag_name, h) | |
e = REXML::Element.new(tag_name) | |
e.add_attributes(h) | |
puts e.to_s | |
end | |
#------------------ | |
def process_projects(d, pid, proj) | |
cnt = 0 | |
users = {} | |
create_mapping(d, "id,login", "users", users) | |
categories = {} | |
create_mapping_with_pid(d, pid, "id,name", "issue_categories", categories) | |
trackers = {} | |
create_mapping(d, "id,name", "trackers", trackers) | |
statuses = {} | |
create_mapping(d, "id,name", "issue_statuses", statuses) | |
versions = {} | |
create_mapping_with_pid(d, pid, "id,name", "versions", versions) | |
if true | |
categories.each { |id, name| | |
jl_tag("jira:AddComponent", { | |
"project-key" => proj, | |
"name" => name | |
}) | |
} | |
version_dates = {} | |
create_mapping_with_pid(d, pid, "id,effective_date", "versions", version_dates) | |
versions.each { |id, name| | |
jl_tag("jira:AddVersion", { | |
"project-key" => proj, | |
"schedule" => version_dates[id], | |
"name" => name | |
}) | |
} | |
end | |
d.execute("SELECT subject,description,category_id,author_id,assigned_to_id,status_id,fixed_version_id,created_on,updated_on,tracker_id,parent_id,id FROM issues WHERE project_id=#{pid}").each { |issue| | |
subject = issue[0] | |
description = issue[1] | |
category = lookup(issue[2], categories) | |
author = user_mapping(lookup(issue[3], users)) | |
assigned = user_mapping(lookup(issue[4], users)) | |
status = lookup(issue[5], statuses) | |
version = lookup(issue[6], versions) | |
created = issue[7] | |
updated = issue[8] | |
tracker = lookup(issue[9], trackers) | |
parent = issue[10] | |
id = issue[11] | |
if true | |
h = { | |
"project-key" => proj, | |
"issueType" => tracker_mapping(tracker), | |
"summary" => subject, | |
"description" => process_tag(description), | |
"issueKeyVar" => "key", | |
"reporter" => author, | |
"assignee" => assigned, | |
"created" => created, | |
"updated" => updated | |
} | |
h["fixVersions"] = version unless (version.nil? or version.empty?) | |
h["components"] = category unless (category.nil? or category.empty?) | |
jl_tag("jira:CreateIssue", h) | |
d.execute("SELECT journalized_id,user_id,notes,created_on FROM journals WHERE journalized_id=#{id}").each { |issue| | |
journalized_id = issue[0] | |
user = user_mapping(lookup(issue[1], users)) | |
notes = issue[2] | |
notes = "empty comment (by migration script)" if notes.nil? or notes.strip.empty? | |
created_on = issue[3] | |
jl_tag("jira:AddComment", { | |
"issue-key" => "${key}", | |
"commenter" => user, | |
"comment" => process_tag(notes), | |
"created" => created_on, | |
}) | |
} | |
if status == "終了" | |
jl_tag("jira:TransitionWorkflow", { | |
"key" => "${key}", | |
"user" => assigned, | |
"workflowAction" => "Close issue", | |
"resolution" => "fixed", | |
"assignee" => "-automatic-", | |
"groupLevel" => "jira-developers" | |
}) | |
end | |
end | |
cnt = cnt + 1 | |
# TODO | |
# parent link | |
# sibling link | |
} | |
end | |
puts <<END | |
<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib"> | |
<!-- | |
Add your own Jelly XML here | |
For documentation on the JIRA tag library see: | |
http://www.atlassian.com/software/jira/docs/latest/jelly.html | |
--> | |
END | |
d = Database.new("redmine.db") | |
begin | |
projects = {} | |
d.execute("SELECT id,name FROM projects").each { |r| projects[r[0]] = r[1] } | |
projects.each { |id, name| | |
next unless target_projects.has_key? name | |
process_projects(d, id, target_projects[name]) | |
} | |
ensure | |
d.close | |
end | |
puts "</JiraJelly>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment