Commit cafb2dac authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '14544-slack-service-hook-discards-spaces' into 'master'

Do not remove spaces from project name in Slack

See merge request gitlab-org/gitlab!24851
parents c5de0a40 61180326
...@@ -16,7 +16,7 @@ module ChatMessage ...@@ -16,7 +16,7 @@ module ChatMessage
def initialize(params) def initialize(params)
@markdown = params[:markdown] || false @markdown = params[:markdown] || false
@project_name = params.dig(:project, :path_with_namespace) || params[:project_name] @project_name = params[:project_name] || params.dig(:project, :path_with_namespace)
@project_url = params.dig(:project, :web_url) || params[:project_url] @project_url = params.dig(:project, :web_url) || params[:project_url]
@user_full_name = params.dig(:user, :name) || params[:user_full_name] @user_full_name = params.dig(:user, :name) || params[:user_full_name]
@user_name = params.dig(:user, :username) || params[:user_name] @user_name = params.dig(:user, :username) || params[:user_name]
......
...@@ -157,7 +157,7 @@ class ChatNotificationService < Service ...@@ -157,7 +157,7 @@ class ChatNotificationService < Service
end end
def project_name def project_name
project.full_name.gsub(/\s/, '') project.full_name
end end
def project_url def project_url
......
---
title: Do not remove space from project name in Slack
merge_request: 24851
author:
type: fixed
...@@ -35,6 +35,7 @@ describe ChatNotificationService do ...@@ -35,6 +35,7 @@ describe ChatNotificationService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:webhook_url) { 'https://example.gitlab.com/' } let(:webhook_url) { 'https://example.gitlab.com/' }
let(:data) { Gitlab::DataBuilder::Push.build_sample(subject.project, user) }
before do before do
allow(chat_service).to receive_messages( allow(chat_service).to receive_messages(
...@@ -51,9 +52,6 @@ describe ChatNotificationService do ...@@ -51,9 +52,6 @@ describe ChatNotificationService do
context 'with a repository' do context 'with a repository' do
it 'returns true' do it 'returns true' do
subject.project = project
data = Gitlab::DataBuilder::Push.build_sample(project, user)
expect(chat_service).to receive(:notify).and_return(true) expect(chat_service).to receive(:notify).and_return(true)
expect(chat_service.execute(data)).to be true expect(chat_service.execute(data)).to be true
end end
...@@ -62,11 +60,19 @@ describe ChatNotificationService do ...@@ -62,11 +60,19 @@ describe ChatNotificationService do
context 'with an empty repository' do context 'with an empty repository' do
it 'returns true' do it 'returns true' do
subject.project = create(:project, :empty_repo) subject.project = create(:project, :empty_repo)
data = Gitlab::DataBuilder::Push.build_sample(subject.project, user)
expect(chat_service).to receive(:notify).and_return(true) expect(chat_service).to receive(:notify).and_return(true)
expect(chat_service.execute(data)).to be true expect(chat_service.execute(data)).to be true
end end
end end
context 'with a project with name containing spaces' do
it 'does not remove spaces' do
allow(project).to receive(:full_name).and_return('Project Name')
expect(chat_service).to receive(:get_message).with(any_args, hash_including(project_name: 'Project Name'))
chat_service.execute(data)
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