Skip to content

Commit

Permalink
Added capability to import watchers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Hourvitz committed Apr 4, 2011
1 parent 82e7a11 commit cae5207
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.~lock*
18 changes: 17 additions & 1 deletion app/controllers/importer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ImporterController < ApplicationController
ISSUE_ATTRS = [:id, :subject, :assigned_to, :fixed_version,
:author, :description, :category, :priority, :tracker, :status,
:start_date, :due_date, :done_ratio, :estimated_hours,
:parent_issue]
:parent_issue, :watchers ]

def index
end
Expand Down Expand Up @@ -161,6 +161,7 @@ def result
category = IssueCategory.find_by_name(row[attrs_map["category"]])
assigned_to = row[attrs_map["assigned_to"]] != nil ? User.find_by_login(row[attrs_map["assigned_to"]]) : nil
fixed_version = Version.find_by_name(row[attrs_map["fixed_version"]])
watchers = row[attrs_map["watchers"]]
# new issue or find exists one
issue = Issue.new
journal = nil
Expand Down Expand Up @@ -260,6 +261,20 @@ def result
end
h
end

# watchers
if watchers
addable_watcher_users = issue.addable_watcher_users
watchers.split(',').each do |watcher|
watcher_user = User.find_by_login(watcher)
if (!watcher_user) || (issue.watcher_users.include?(watcher_user))
next
end
if addable_watcher_users.include?(watcher_user)
issue.add_watcher(watcher_user)
end
end
end

if (!issue.save)
# 记录错误
Expand All @@ -269,6 +284,7 @@ def result
if unique_field
@issue_by_unique_attr[row[unique_field]] = issue
end

# Issue relations
begin
IssueRelation::TYPES.each_pair do |rtype, rinfo|
Expand Down
4 changes: 2 additions & 2 deletions test/samples/AllStandardFields.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"Subject","Description","Assignee","Target version","Author","Category","Priority","Tracker","Status","Start date","Due date","% done","Estimated time"
"A full task","A lengthily described set of activities.","admin","The Target Version","admin","Default","High","Bug","In Progress",2011-05-01,2011-08-28,25,200
"Subject","Description","Assignee","Target version","Author","Category","Priority","Tracker","Status","Start date","Due date","% done","Estimated time","Watchers"
"A full task","A lengthily described set of activities.","admin","The Target Version","admin","Default","High","Bug","In Progress",05/01/11,08/28/11,25,200,"test1,test2"

0 comments on commit cae5207

Please sign in to comment.