-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjira.rb
121 lines (102 loc) · 2.81 KB
/
jira.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
require "rubygems"
require "sinatra"
require "haml"
require "jira4r"
set :haml, {:format => :html5 }
class MyJiraService
attr_reader :address
def initialize(params)
@address = params[:url]
@filter_id = params[:filter_id]
@jira = Jira4R::JiraTool.new(2, @address)
@jira.login(params[:user], params[:password])
@project = @jira.getProjectByKey(params[:project_key])
@issue_types = @jira.getIssueTypes()
@subtask_issue_types = @jira.getSubTaskIssueTypes()
@statuses = @jira.getStatuses()
end
def find_issue_type_by_id(id)
@issue_types.find {|i| i.id == id}
end
def find_subtask_issue_type_by_id(id)
@subtask_issue_types.find {|i| i.id == id}
end
def find_status_by_id(id)
@statuses.find {|i| i.id == id}
end
def issues
@jira.getIssuesFromFilter(@filter_id)
end
end
class Board
#open, reopened
TODO_STATUSES = %w[1 4]
#in progress
IN_PROGRESS_STATUSES = %w[3]
# resolved
VERIFY_STATUSES = %w[5]
# closed
DONE_STATUSES = %w[6]
attr_reader :todo, :in_progress, :verifying, :done, :people
def initialize(jira)
@todo = []
@in_progress = []
@verifying = []
@done = []
@people =[]
@jira = jira
issues = jira.issues
populate(issues)
end
def get_person_class(person)
if @people.any? {|p| p == person}
@people.index(person)
else
@people << person
@people.size - 1
end
end
def render_issues(issues)
content = ""
issues.each do |i|
content << %[
<div class="issue type_#{i.type} person_#{get_person_class(i.assignee)}">
<span class="key"><a href="#{@jira.address}browse/#{i.key}">#{i.key}</a></span>
<span class="summary">#{i.summary}</span><br />
<span class="type type_#{i.type}">#{issue_type_description(i)}</span><br />
<span class="assignee person_#{get_person_class(i.assignee)}">#{i.assignee}</span>
</div>
]
end
content
end
def issue_type_description(issue)
type = @jira.find_issue_type_by_id(issue.type) || @jira.find_subtask_issue_type_by_id(issue.type)
if type then type.name else issue.type end
end
private
def populate(issues)
issues.each do |issue|
if TODO_STATUSES.any? {|i| i == issue.status}
@todo << issue
elsif IN_PROGRESS_STATUSES.any? {|i| i == issue.status}
@in_progress << issue
elsif VERIFY_STATUSES.any? {|i| i == issue.status}
@verifying << issue
elsif DONE_STATUSES.any? {|i| i == issue.status}
@done << issue
end
unless @people.any? {|p| p == issue.assignee}
@people << issue.assignee
end
end
end
end
get "/" do
haml :index
end
post "/board" do
jira = MyJiraService.new(params[:jira])
board = Board.new(jira)
haml :board, :locals => {:board => board}
end