Class: Integrations::ChatMessage::PipelineMessage

Inherits:
BaseMessage
  • Object
show all
Defined in:
app/models/integrations/chat_message/pipeline_message.rb

Constant Summary collapse

MAX_VISIBLE_JOBS =
10

Constants inherited from BaseMessage

BaseMessage::RELATIVE_LINK_REGEX

Instance Attribute Summary collapse

Attributes inherited from BaseMessage

#markdown, #project_name, #user_avatar, #user_full_name, #user_name

Instance Method Summary collapse

Methods inherited from BaseMessage

#fallback, #summary, #user_combined_name

Constructor Details

#initialize(data) ⇒ PipelineMessage

Returns a new instance of PipelineMessage.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 24

def initialize(data)
  super

  @user = data[:user]
  @user_name = data.dig(:user, :username) || 'API'

  pipeline_attributes = data[:object_attributes]
  @ref_type = pipeline_attributes[:tag] ? 'tag' : 'branch'
  @ref = pipeline_attributes[:ref]
  @status = pipeline_attributes[:status]
  @detailed_status = pipeline_attributes[:detailed_status]
  @duration = pipeline_attributes[:duration].to_i
  @finished_at = pipeline_attributes[:finished_at] ? Time.parse(pipeline_attributes[:finished_at]).to_i : nil
  @pipeline_id = pipeline_attributes[:id]

  # Get list of jobs that have actually failed (after exhausting all retries)
  @failed_jobs = actually_failed_jobs(Array(data[:builds]))
  @failed_stages = @failed_jobs.map { |j| j[:stage] }.uniq

  @project = Project.find(data[:project][:id])
  @commit = project.commit_by(oid: data[:commit][:id])
  @committer = commit.committer
  @pipeline = Ci::Pipeline.find(pipeline_id)
end

Instance Attribute Details

#commitObject (readonly)

Returns the value of attribute commit.



20
21
22
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 20

def commit
  @commit
end

#committerObject (readonly)

Returns the value of attribute committer.



21
22
23
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 21

def committer
  @committer
end

#detailed_statusObject (readonly)

Returns the value of attribute detailed_status.



12
13
14
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 12

def detailed_status
  @detailed_status
end

#durationObject (readonly)

Returns the value of attribute duration.



13
14
15
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 13

def duration
  @duration
end

#failed_jobsObject (readonly)

Returns the value of attribute failed_jobs.



17
18
19
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 17

def failed_jobs
  @failed_jobs
end

#failed_stagesObject (readonly)

Returns the value of attribute failed_stages.



16
17
18
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 16

def failed_stages
  @failed_stages
end

#finished_atObject (readonly)

Returns the value of attribute finished_at.



14
15
16
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 14

def finished_at
  @finished_at
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



22
23
24
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 22

def pipeline
  @pipeline
end

#pipeline_idObject (readonly)

Returns the value of attribute pipeline_id.



15
16
17
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 15

def pipeline_id
  @pipeline_id
end

#projectObject (readonly)

Returns the value of attribute project.



19
20
21
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 19

def project
  @project
end

#refObject (readonly)

Returns the value of attribute ref.



10
11
12
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 10

def ref
  @ref
end

#ref_typeObject (readonly)

Returns the value of attribute ref_type.



9
10
11
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 9

def ref_type
  @ref_type
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 11

def status
  @status
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 8

def user
  @user
end

Instance Method Details

#activityObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 76

def activity
  {
    title: s_("ChatMessage|Pipeline %{pipeline_link} of %{ref_type} %{ref_link} by %{user_combined_name} %{humanized_status}") %
      {
        pipeline_link: pipeline_link,
        ref_type: ref_type,
        ref_link: ref_link,
        user_combined_name: strip_markup(user_combined_name),
        humanized_status: humanized_status
      },
    subtitle: s_("ChatMessage|in %{project_link}") % { project_link: project_link },
    text: s_("ChatMessage|in %{duration}") % { duration: pretty_duration(duration) },
    image: user_avatar || ''
  }
end

#attachmentsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 53

def attachments
  return message if markdown

  [{
    fallback: format(message),
    color: attachment_color,
    author_name: strip_markup(user_combined_name),
    author_icon: user_avatar,
    author_link: author_url,
    title: s_("ChatMessage|Pipeline #%{pipeline_id} %{humanized_status} in %{duration}") %
      {
        pipeline_id: pipeline_id,
        humanized_status: humanized_status,
        duration: pretty_duration(duration)
      },
    title_link: pipeline_url,
    fields: attachments_fields,
    footer: project.name,
    footer_icon: project.avatar_url(only_path: false),
    ts: finished_at
  }]
end

#pretextObject



49
50
51
# File 'app/models/integrations/chat_message/pipeline_message.rb', line 49

def pretext
  ''
end