Commit 80777108 authored by Nick Thomas's avatar Nick Thomas

Merge branch '20811-fj-include-diff-url-in-wiki-slack-notification' into 'master'

Add wiki page diff url to Slack notification message

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