-
Notifications
You must be signed in to change notification settings - Fork 8
/
redmine_to_kanboard.rb
99 lines (83 loc) · 2.38 KB
/
redmine_to_kanboard.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class RedmineToKanboard
def initialize(profile:, redmine_id: nil, kanboard_task: nil, tags: nil)
@profile = profile
@redmine_id = redmine_id
@kanboard_task = kanboard_task
@tags = tags || []
end
def run
load_redmine_issue
return false unless @redmine_issue
if @kanboard_task
update
else
create
end
end
def create
create_kanboard_task
sync_kanboard_task
@kanboard_task
end
def update
update_kanboard_task
sync_kanboard_task
puts "Kanboard task #{@kanboard_task.id} updated"
end
def sync_kanboard_task
@kanboard_task.sync_bugzilla_links
@kanboard_task.sync_github_links
end
private
def load_redmine_issue
if @redmine_id.nil? && @kanboard_task
@redmine_issue = @kanboard_task.redmine_issues.first
else
@redmine_issue = RedmineIssue.new(@redmine_id)
end
end
def create_kanboard_task
@kanboard_task = KanboardTask.create('title' => task_title,
'project_id' => project_id,
'color_id' => color_id,
'description' => task_description,
'swimlane_id' => swimlane_id,
'category_id' => category_id,
'tags' => task_tags)
@kanboard_task.create_redmine_links(@redmine_issue.url)
@kanboard_task
end
def update_kanboard_task
KanboardTask.update('id' => @kanboard_task.id, 'category_id' => category_id)
end
def swimlane_id
unless @swimlane
swimlane_name = @profile.backlog_swimlane_name
raise 'backlog_swimlane_name not configured' unless swimlane_name
@swimlane = KanboardSwimlane.find_by_name(project_id, swimlane_name)
raise "Swimlane #{swimlane_name} not found in project #{project_id}" unless @swimlane
end
return @swimlane.id
end
def project_id
@profile.project_id
end
def color_id
@profile.task_configuration['color']
end
def task_title
"RM \##{@redmine_issue.id}: #{@redmine_issue.subject}"
end
def task_description
@redmine_issue.description
end
def task_tags
@tags
end
def category_id
mapper.category.id if mapper.category
end
def mapper
@kanboard_mapper ||= KanboardMapper.new(profile: @profile, redmine_issue: @redmine_issue)
end
end