summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-05-18 17:30:26 +0000
committerRémy Coutable <remy@rymai.me>2016-05-18 17:30:26 +0000
commit43493ecac1740a9a0339052585c88cd34130bd6a (patch)
tree2dbe4e5474741f98e045cf8179825a566c98712f
parent5da1c23b7ff8c13941962016456b30d8c4afe83a (diff)
parent78e2d0ac3c6d4e4477625840063e0d4a54f36594 (diff)
downloadgitlab-ce-43493ecac1740a9a0339052585c88cd34130bd6a.tar.gz
Merge branch 'slack-issue-format' into 'master'
Improve issue formatting in Slack service This will improve the looks of the message that gets send to Slack. **Before** ![image](https://gitlab.com/jeroenvanbaarsen/gitlab-ce/uploads/670442d4d5cef5aa36753671b8894a75/image.png) **After** ![image](https://gitlab.com/jeroenvanbaarsen/gitlab-ce/uploads/ab6e40a0c22ebe89ebd5b3652821c6dd/image.png) There is one thing I'm not certain about, thats sending the logo with the payload. Because this means we need to host the GitLab logo somewhere public, and every time a payload from any GitLab instance is send, we use that logo url. This might overload the server, or drive the bandwidth bill through the roof. This is something @sytses or @dzaporozhets have to decide about. @stanhu, you told me you were the author of the original code, maybe you can review? See merge request !1308
-rw-r--r--CHANGELOG3
-rw-r--r--app/models/project_services/slack_service/issue_message.rb19
-rw-r--r--spec/models/project_services/slack_service/issue_message_spec.rb11
3 files changed, 24 insertions, 9 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 2dd80779541..9baab4734c6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -59,6 +59,7 @@ v 8.8.0 (unreleased)
- Add counter metrics for rails cache
- Import pull requests from GitHub where the source or target branches were removed
- All Grape API helpers are now instrumented
+ - Improve Issue formatting for the Slack Service (Jeroen van Baarsen)
v 8.7.6
- Fix links on wiki pages for relative url setups. !4131 (Artem Sidorenko)
@@ -893,7 +894,7 @@ v 8.1.3
- Use issue editor as cross reference comment author when issue is edited with a new mention
- Add Facebook authentication
-v 8.1.2
+v 8.1.1
- Fix cloning Wiki repositories via HTTP (Stan Hu)
- Add migration to remove satellites directory
- Fix specific runners visibility
diff --git a/app/models/project_services/slack_service/issue_message.rb b/app/models/project_services/slack_service/issue_message.rb
index 438ff33fdff..88e053ec192 100644
--- a/app/models/project_services/slack_service/issue_message.rb
+++ b/app/models/project_services/slack_service/issue_message.rb
@@ -34,7 +34,12 @@ class SlackService
private
def message
- "#{user_name} #{state} #{issue_link} in #{project_link}: *#{title}*"
+ case state
+ when "opened"
+ "[#{project_link}] Issue #{state} by #{user_name}"
+ else
+ "[#{project_link}] Issue #{issue_link} #{state} by #{user_name}"
+ end
end
def opened_issue?
@@ -42,7 +47,11 @@ class SlackService
end
def description_message
- [{ text: format(description), color: attachment_color }]
+ [{
+ title: issue_title,
+ title_link: issue_url,
+ text: format(description),
+ color: "#C95823" }]
end
def project_link
@@ -50,7 +59,11 @@ class SlackService
end
def issue_link
- "[issue ##{issue_iid}](#{issue_url})"
+ "[#{issue_title}](#{issue_url})"
+ end
+
+ def issue_title
+ "##{issue_iid} #{title}"
end
end
end
diff --git a/spec/models/project_services/slack_service/issue_message_spec.rb b/spec/models/project_services/slack_service/issue_message_spec.rb
index f648cbe2dee..0f8889bdf3c 100644
--- a/spec/models/project_services/slack_service/issue_message_spec.rb
+++ b/spec/models/project_services/slack_service/issue_message_spec.rb
@@ -25,7 +25,7 @@ describe SlackService::IssueMessage, models: true do
}
end
- let(:color) { '#345' }
+ let(:color) { '#C95823' }
context '#initialize' do
before do
@@ -40,10 +40,11 @@ describe SlackService::IssueMessage, models: true do
context 'open' do
it 'returns a message regarding opening of issues' do
expect(subject.pretext).to eq(
- 'Test User opened <url|issue #100> in <somewhere.com|project_name>: '\
- '*Issue title*')
+ '<somewhere.com|[project_name>] Issue opened by Test User')
expect(subject.attachments).to eq([
{
+ title: "#100 Issue title",
+ title_link: "url",
text: "issue description",
color: color,
}
@@ -56,10 +57,10 @@ describe SlackService::IssueMessage, models: true do
args[:object_attributes][:action] = 'close'
args[:object_attributes][:state] = 'closed'
end
+
it 'returns a message regarding closing of issues' do
expect(subject.pretext). to eq(
- 'Test User closed <url|issue #100> in <somewhere.com|project_name>: '\
- '*Issue title*')
+ '<somewhere.com|[project_name>] Issue <url|#100 Issue title> closed by Test User')
expect(subject.attachments).to be_empty
end
end