Class: Lita::GitlabCi::BuildMessage
- Inherits:
-
Object
- Object
- Lita::GitlabCi::BuildMessage
- Defined in:
- lib/lita/gitlab_ci/build_message.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#hipchat ⇒ Object
readonly
Returns the value of attribute hipchat.
Instance Method Summary collapse
- #build_commits ⇒ Object
- #build_header ⇒ Object
- #color ⇒ Object
- #commits ⇒ Object
-
#initialize(hipchat, data) ⇒ BuildMessage
constructor
A new instance of BuildMessage.
- #project_branch ⇒ Object
- #project_infos ⇒ Object
- #project_status ⇒ Object
- #send_to_hipchat! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hipchat, data) ⇒ BuildMessage
Returns a new instance of BuildMessage.
6 7 8 9 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 6 def initialize(hipchat, data) @hipchat = hipchat @data = OpenStruct.new(data) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 4 def data @data end |
#hipchat ⇒ Object (readonly)
Returns the value of attribute hipchat.
4 5 6 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 4 def hipchat @hipchat end |
Instance Method Details
#build_commits ⇒ Object
27 28 29 30 31 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 27 def build_commits commits.map do |commit| Commit.new(commit) end end |
#build_header ⇒ Object
23 24 25 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 23 def build_header "<p>Build for #{ project_infos } #{ project_branch }: #{ project_status }</p>" end |
#color ⇒ Object
11 12 13 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 11 def color data.build_status == 'success' ? 'green' : 'red' end |
#commits ⇒ Object
33 34 35 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 33 def commits data.push_data['commits'].reverse end |
#project_branch ⇒ Object
41 42 43 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 41 def project_branch "(#{ data.ref })" end |
#project_infos ⇒ Object
37 38 39 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 37 def project_infos "<a href=\"#{ data.gitlab_url }\">#{ data.project_name }</a>" end |
#project_status ⇒ Object
45 46 47 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 45 def project_status "<strong>#{ data.build_status }</strong>!" end |
#send_to_hipchat! ⇒ Object
19 20 21 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 19 def send_to_hipchat! hipchat.send('lita', to_s, color: color) end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/lita/gitlab_ci/build_message.rb', line 15 def to_s [build_header, build_commits].join end |