Commit 1b864680 authored by Jason Goodman's avatar Jason Goodman Committed by Douglas Barbosa Alexandre

Update deployment chat message notification

Include link to user and commit title.
Rearrange text
parent f1526ccd
......@@ -2,27 +2,31 @@
module ChatMessage
class DeploymentMessage < BaseMessage
attr_reader :commit_title
attr_reader :commit_url
attr_reader :deployable_id
attr_reader :deployable_url
attr_reader :environment
attr_reader :short_sha
attr_reader :status
attr_reader :user_url
def initialize(data)
super
@commit_title = data[:commit_title]
@commit_url = data[:commit_url]
@deployable_id = data[:deployable_id]
@deployable_url = data[:deployable_url]
@environment = data[:environment]
@short_sha = data[:short_sha]
@status = data[:status]
@user_url = data[:user_url]
end
def attachments
[{
text: "#{project_link}\n#{deployment_link}, SHA #{commit_link}, by #{user_combined_name}",
text: "#{project_link} with job #{deployment_link} by #{user_link}\n#{commit_link}: #{commit_title}",
color: color
}]
end
......@@ -55,7 +59,11 @@ module ChatMessage
end
def deployment_link
link("Job ##{deployable_id}", deployable_url)
link("##{deployable_id}", deployable_url)
end
def user_link
link(user_combined_name, user_url)
end
def commit_link
......
---
title: Update deployment event chat notification message
merge_request: 27972
author:
type: changed
......@@ -15,7 +15,9 @@ module Gitlab
project: deployment.project.hook_attrs,
short_sha: deployment.short_sha,
user: deployment.user.hook_attrs,
commit_url: Gitlab::UrlBuilder.build(deployment.commit)
user_url: Gitlab::UrlBuilder.build(deployment.user),
commit_url: Gitlab::UrlBuilder.build(deployment.commit),
commit_title: deployment.commit.title
}
end
end
......
......@@ -32,6 +32,8 @@ module Gitlab
milestone_url(object)
when ::Ci::Build
project_job_url(object.project, object)
when User
user_url(object)
else
raise NotImplementedError.new("No URL builder defined for #{object.class}")
end
......
......@@ -19,6 +19,7 @@ describe Gitlab::DataBuilder::Deployment do
deployment = create(:deployment, status: :failed, environment: environment, sha: commit.sha, project: project)
deployable = deployment.deployable
expected_deployable_url = Gitlab::Routing.url_helpers.project_job_url(deployable.project, deployable)
expected_user_url = Gitlab::Routing.url_helpers.user_url(deployment.user)
expected_commit_url = Gitlab::UrlBuilder.build(commit)
data = described_class.build(deployment)
......@@ -30,7 +31,9 @@ describe Gitlab::DataBuilder::Deployment do
expect(data[:project]).to eq(project.hook_attrs)
expect(data[:short_sha]).to eq(deployment.short_sha)
expect(data[:user]).to eq(deployment.user.hook_attrs)
expect(data[:user_url]).to eq(expected_user_url)
expect(data[:commit_url]).to eq(expected_commit_url)
expect(data[:commit_title]).to eq(commit.title)
end
end
end
......@@ -89,8 +89,10 @@ describe ChatMessage::DeploymentMessage do
name: "Jane Person",
username: "jane"
},
user_url: "user_url",
short_sha: "12345678",
commit_url: "commit_url"
commit_url: "commit_url",
commit_title: "commit title text"
}.merge(params)
end
......@@ -104,12 +106,13 @@ describe ChatMessage::DeploymentMessage do
deployment = create(:deployment, :success, deployable: ci_build, environment: environment, project: project, user: user, sha: commit.sha)
job_url = Gitlab::Routing.url_helpers.project_job_url(project, ci_build)
commit_url = Gitlab::UrlBuilder.build(deployment.commit)
user_url = Gitlab::Routing.url_helpers.user_url(user)
data = Gitlab::DataBuilder::Deployment.build(deployment)
message = described_class.new(data)
expect(message.attachments).to eq([{
text: "[myspace/myproject](#{project.web_url})\n[Job ##{ci_build.id}](#{job_url}), SHA [#{deployment.short_sha}](#{commit_url}), by John Smith (smith)",
text: "[myspace/myproject](#{project.web_url}) with job [##{ci_build.id}](#{job_url}) by [John Smith (smith)](#{user_url})\n[#{deployment.short_sha}](#{commit_url}): #{commit.title}",
color: "good"
}])
end
......@@ -120,7 +123,7 @@ describe ChatMessage::DeploymentMessage do
message = described_class.new(data)
expect(message.attachments).to eq([{
text: "[project_path_with_namespace](project_web_url)\n[Job #3](deployable_url), SHA [12345678](commit_url), by Jane Person (jane)",
text: "[project_path_with_namespace](project_web_url) with job [#3](deployable_url) by [Jane Person (jane)](user_url)\n[12345678](commit_url): commit title text",
color: "danger"
}])
end
......@@ -131,7 +134,7 @@ describe ChatMessage::DeploymentMessage do
message = described_class.new(data)
expect(message.attachments).to eq([{
text: "[project_path_with_namespace](project_web_url)\n[Job #3](deployable_url), SHA [12345678](commit_url), by Jane Person (jane)",
text: "[project_path_with_namespace](project_web_url) with job [#3](deployable_url) by [Jane Person (jane)](user_url)\n[12345678](commit_url): commit title text",
color: "warning"
}])
end
......@@ -142,7 +145,7 @@ describe ChatMessage::DeploymentMessage do
message = described_class.new(data)
expect(message.attachments).to eq([{
text: "[project_path_with_namespace](project_web_url)\n[Job #3](deployable_url), SHA [12345678](commit_url), by Jane Person (jane)",
text: "[project_path_with_namespace](project_web_url) with job [#3](deployable_url) by [Jane Person (jane)](user_url)\n[12345678](commit_url): commit title text",
color: "#334455"
}])
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment