forked from zendesk/samson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploys_helper.rb
119 lines (89 loc) · 3.05 KB
/
deploys_helper.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
require 'coderay'
module DeploysHelper
def deploy_active?
@deploy.active? && (JobExecution.find_by_id(@deploy.job_id) || JobExecution.enabled)
end
def deploy_page_title
"#{@deploy.stage.name} deploy (#{@deploy.status}) - #{@project.name}"
end
def deploy_notification
"Samson deploy finished:\n#{@project.name} / #{@deploy.stage.name} #{@deploy.status}"
end
def file_status_label(status)
mapping = {
"added" => "success",
"modified" => "info",
"removed" => "danger"
}
type = mapping[status]
content_tag :span, status[0].upcase, class: "label label-#{type}"
end
def file_changes_label(count, type)
content_tag :span, count.to_s, class: "label label-#{type}" unless count.zero?
end
def github_users(users)
users.map {|user| github_user_avatar(user) }.join(" ").html_safe
end
def github_user_avatar(user)
return if user.nil?
link_to user.url, title: user.login do
image_tag user.avatar_url, width: 20, height: 20
end
end
def deploy_status_panel(deploy)
deploy_status_panel_common(deploy, BuddyCheck.enabled?)
end
def buddy_check_button(project, deploy)
return nil unless deploy.waiting_for_buddy?
button_class = ['btn']
if @deploy.started_by?(current_user)
button_text = 'Bypass'
button_class << 'btn-danger'
else
button_text = 'Approve'
button_class << 'btn-primary'
end
link_to button_text, buddy_check_project_deploy_path(@project, @deploy), method: :post, class: button_class.join(' ')
end
def duration_text(deploy)
seconds = (deploy.updated_at - deploy.start_time).to_i
duration = ""
if seconds > 60
minutes = seconds / 60
seconds = seconds - minutes * 60
duration << "#{minutes} minute".pluralize(minutes)
end
duration << (seconds > 0 || duration.size == 0 ? " #{seconds} second".pluralize(seconds) : "")
end
def syntax_highlight(code, language = :ruby)
CodeRay.scan(code, language).html.html_safe
end
def stages_select_options
@project.stages.unlocked_for(current_user).map do |stage|
[stage.name, stage.id, 'data-confirmation' => stage.confirm?]
end
end
def stop_button(options = {})
link_to "Stop", [@project, @deploy], options.merge({ method: :delete, class: options.fetch(:class, 'btn btn-danger btn-xl') })
end
private
def deploy_status_panel_common(deploy, enabled, hash = { "cancelled" => "danger" } )
mapping = {
"succeeded" => "success",
"failed" => "danger",
"errored" => "warning",
}
mapping = mapping.merge(hash) if enabled
content, status = content_no_buddy_check(deploy)
content ||= h deploy.summary
status ||= mapping.fetch(deploy.status, "info")
content_tag :div, content.html_safe, class: "alert alert-#{status}"
end
def content_no_buddy_check(deploy)
if deploy.finished?
content = h "#{deploy.summary} "
content << relative_time(deploy.start_time)
content << ", it took #{duration_text(deploy)}."
end
end
end