Add wiki page diff url to Slack notification message

In this commit, we add the wiki page diff url to the
notification message sent to Slack.

Changelog: added
parent 0c81941b
......@@ -7,6 +7,7 @@ module Integrations
attr_reader :wiki_page_url
attr_reader :action
attr_reader :description
attr_reader :diff_url
def initialize(params)
super
......@@ -16,6 +17,7 @@ module Integrations
@title = obj_attr[:title]
@wiki_page_url = obj_attr[:url]
@description = obj_attr[:message]
@diff_url = obj_attr[:diff_url]
@action =
case obj_attr[:action]
......@@ -44,19 +46,23 @@ module Integrations
private
def message
"#{user_combined_name} #{action} #{wiki_page_link} in #{project_link}: *#{title}*"
"#{user_combined_name} #{action} #{wiki_page_link} (#{diff_link}) in #{project_link}: *#{title}*"
end
def description_message
[{ text: format(@description), color: attachment_color }]
end
def diff_link
link('Compare changes', diff_url)
end
def project_link
"[#{project_name}](#{project_url})"
link(project_name, project_url)
end
def wiki_page_link
"[wiki page](#{wiki_page_url})"
link('wiki page', wiki_page_url)
end
end
end
......
......@@ -18,7 +18,8 @@ module Gitlab
wiki: wiki.hook_attrs,
object_attributes: wiki_page.hook_attrs.merge(
url: Gitlab::UrlBuilder.build(wiki_page),
action: action
action: action,
diff_url: Gitlab::UrlBuilder.build(wiki_page, action: :diff, version_id: wiki_page.version.id)
)
}
end
......
......@@ -4,8 +4,8 @@ require 'spec_helper'
RSpec.describe Gitlab::DataBuilder::WikiPage do
let_it_be(:project) { create(:project, :repository, :wiki_repo) }
let(:wiki_page) { create(:wiki_page, wiki: project.wiki) }
let(:user) { create(:user) }
let_it_be(:wiki_page) { create(:wiki_page, wiki: project.wiki) }
let_it_be(:user) { create(:user) }
describe '.build' do
let(:data) { described_class.build(wiki_page, user, 'create') }
......@@ -19,5 +19,6 @@ RSpec.describe Gitlab::DataBuilder::WikiPage do
it { expect(data[:object_attributes]).to include(wiki_page.hook_attrs) }
it { expect(data[:object_attributes]).to include(url: Gitlab::UrlBuilder.build(wiki_page)) }
it { expect(data[:object_attributes]).to include(action: 'create') }
it { expect(data[:object_attributes]).to include(diff_url: Gitlab::UrlBuilder.build(wiki_page, action: :diff, version_id: wiki_page.version.id)) }
end
end
......@@ -5,20 +5,30 @@ require 'spec_helper'
RSpec.describe Integrations::ChatMessage::WikiPageMessage do
subject { described_class.new(args) }
let(:name) { 'Test User' }
let(:username) { 'test.user' }
let(:avatar_url) { 'http://someavatar.com' }
let(:project_name) { 'project_name' }
let(:project_url) {'http://somewhere.com' }
let(:url) { 'http://url.com' }
let(:diff_url) { 'http://url.com/diff?version_id=1234' }
let(:wiki_page_title) { 'Wiki page title' }
let(:commit_message) { 'Wiki page commit message' }
let(:args) do
{
user: {
name: 'Test User',
username: 'test.user',
avatar_url: 'http://someavatar.com'
name: name,
username: username,
avatar_url: avatar_url
},
project_name: 'project_name',
project_url: 'http://somewhere.com',
project_name: project_name,
project_url: project_url,
object_attributes: {
title: 'Wiki page title',
url: 'http://url.com',
title: wiki_page_title,
url: url,
content: 'Wiki page content',
message: 'Wiki page commit message'
message: commit_message,
diff_url: diff_url
}
}
end
......@@ -32,8 +42,8 @@ RSpec.describe Integrations::ChatMessage::WikiPageMessage do
it 'returns a message that a new wiki page was created' do
expect(subject.pretext).to eq(
'Test User (test.user) created <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
'*Wiki page title*')
"#{name} (#{username}) created <#{url}|wiki page> (<#{diff_url}|Compare changes>) in <#{project_url}|#{project_name}>: "\
"*#{wiki_page_title}*")
end
end
......@@ -44,8 +54,8 @@ RSpec.describe Integrations::ChatMessage::WikiPageMessage do
it 'returns a message that a wiki page was updated' do
expect(subject.pretext).to eq(
'Test User (test.user) edited <http://url.com|wiki page> in <http://somewhere.com|project_name>: '\
'*Wiki page title*')
"#{name} (#{username}) edited <#{url}|wiki page> (<#{diff_url}|Compare changes>) in <#{project_url}|#{project_name}>: "\
"*#{wiki_page_title}*")
end
end
end
......@@ -61,7 +71,7 @@ RSpec.describe Integrations::ChatMessage::WikiPageMessage do
it 'returns the commit message for a new wiki page' do
expect(subject.attachments).to eq([
{
text: "Wiki page commit message",
text: commit_message,
color: color
}
])
......@@ -76,7 +86,7 @@ RSpec.describe Integrations::ChatMessage::WikiPageMessage do
it 'returns the commit message for an updated wiki page' do
expect(subject.attachments).to eq([
{
text: "Wiki page commit message",
text: commit_message,
color: color
}
])
......@@ -98,7 +108,7 @@ RSpec.describe Integrations::ChatMessage::WikiPageMessage do
it 'returns a message that a new wiki page was created' do
expect(subject.pretext).to eq(
'Test User (test.user) created [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*')
"#{name} (#{username}) created [wiki page](#{url}) ([Compare changes](#{diff_url})) in [#{project_name}](#{project_url}): *#{wiki_page_title}*")
end
end
......@@ -109,7 +119,7 @@ RSpec.describe Integrations::ChatMessage::WikiPageMessage do
it 'returns a message that a wiki page was updated' do
expect(subject.pretext).to eq(
'Test User (test.user) edited [wiki page](http://url.com) in [project_name](http://somewhere.com): *Wiki page title*')
"#{name} (#{username}) edited [wiki page](#{url}) ([Compare changes](#{diff_url})) in [#{project_name}](#{project_url}): *#{wiki_page_title}*")
end
end
end
......@@ -121,7 +131,7 @@ RSpec.describe Integrations::ChatMessage::WikiPageMessage do
end
it 'returns the commit message for a new wiki page' do
expect(subject.attachments).to eq('Wiki page commit message')
expect(subject.attachments).to eq(commit_message)
end
end
......@@ -131,7 +141,7 @@ RSpec.describe Integrations::ChatMessage::WikiPageMessage do
end
it 'returns the commit message for an updated wiki page' do
expect(subject.attachments).to eq('Wiki page commit message')
expect(subject.attachments).to eq(commit_message)
end
end
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