summaryrefslogtreecommitdiff
path: root/app/models/project_services/slack_service
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-03-06 08:31:49 -0800
committerStan Hu <stanhu@gmail.com>2015-03-06 08:31:49 -0800
commitad14ed5e49a956511ae8f4d3bf377457fdb1075d (patch)
treed7884a56ecea18ea867b63bbbca478a4be96c650 /app/models/project_services/slack_service
parent76802012e62a70bd040ec5cb8efa7e357dda0eee (diff)
downloadgitlab-ce-ad14ed5e49a956511ae8f4d3bf377457fdb1075d.tar.gz
Add tag_push event notification to HipChat and Slack services.
Normalize output to use: - User name instead of username - Include first line of title in message description - Link to "Issue #X" instead of "#X"
Diffstat (limited to 'app/models/project_services/slack_service')
-rw-r--r--app/models/project_services/slack_service/issue_message.rb8
-rw-r--r--app/models/project_services/slack_service/merge_message.rb14
-rw-r--r--app/models/project_services/slack_service/note_message.rb12
-rw-r--r--app/models/project_services/slack_service/push_message.rb19
4 files changed, 33 insertions, 20 deletions
diff --git a/app/models/project_services/slack_service/issue_message.rb b/app/models/project_services/slack_service/issue_message.rb
index e2fed0bb1b9..5af24a80609 100644
--- a/app/models/project_services/slack_service/issue_message.rb
+++ b/app/models/project_services/slack_service/issue_message.rb
@@ -1,6 +1,6 @@
class SlackService
class IssueMessage < BaseMessage
- attr_reader :username
+ attr_reader :user_name
attr_reader :title
attr_reader :project_name
attr_reader :project_url
@@ -11,7 +11,7 @@ class SlackService
attr_reader :description
def initialize(params)
- @username = params[:user][:username]
+ @user_name = params[:user][:name]
@project_name = params[:project_name]
@project_url = params[:project_url]
@@ -34,7 +34,7 @@ class SlackService
private
def message
- "#{username} #{state} issue #{issue_link} in #{project_link}: #{title}"
+ "#{user_name} #{state} #{issue_link} in #{project_link}: *#{title}*"
end
def opened_issue?
@@ -50,7 +50,7 @@ class SlackService
end
def issue_link
- "[##{issue_iid}](#{issue_url})"
+ "[issue ##{issue_iid}](#{issue_url})"
end
end
end
diff --git a/app/models/project_services/slack_service/merge_message.rb b/app/models/project_services/slack_service/merge_message.rb
index 4dcce1d15a0..e792c258f73 100644
--- a/app/models/project_services/slack_service/merge_message.rb
+++ b/app/models/project_services/slack_service/merge_message.rb
@@ -1,15 +1,16 @@
class SlackService
class MergeMessage < BaseMessage
- attr_reader :username
+ attr_reader :user_name
attr_reader :project_name
attr_reader :project_url
attr_reader :merge_request_id
attr_reader :source_branch
attr_reader :target_branch
attr_reader :state
+ attr_reader :title
def initialize(params)
- @username = params[:user][:username]
+ @user_name = params[:user][:name]
@project_name = params[:project_name]
@project_url = params[:project_url]
@@ -19,6 +20,7 @@ class SlackService
@source_branch = obj_attr[:source_branch]
@target_branch = obj_attr[:target_branch]
@state = obj_attr[:state]
+ @title = format_title(obj_attr[:title])
end
def pretext
@@ -31,6 +33,10 @@ class SlackService
private
+ def format_title(title)
+ '*' + title.lines.first.chomp + '*'
+ end
+
def message
merge_request_message
end
@@ -40,11 +46,11 @@ class SlackService
end
def merge_request_message
- "#{username} #{state} merge request #{merge_request_link} in #{project_link}"
+ "#{user_name} #{state} #{merge_request_link} in #{project_link}: #{title}"
end
def merge_request_link
- "[##{merge_request_id}](#{merge_request_url})"
+ "[merge request ##{merge_request_id}](#{merge_request_url})"
end
def merge_request_url
diff --git a/app/models/project_services/slack_service/note_message.rb b/app/models/project_services/slack_service/note_message.rb
index f93dc358f61..074478b292d 100644
--- a/app/models/project_services/slack_service/note_message.rb
+++ b/app/models/project_services/slack_service/note_message.rb
@@ -1,7 +1,7 @@
class SlackService
class NoteMessage < BaseMessage
attr_reader :message
- attr_reader :username
+ attr_reader :user_name
attr_reader :project_name
attr_reader :project_link
attr_reader :note
@@ -10,7 +10,7 @@ class SlackService
def initialize(params)
params = HashWithIndifferentAccess.new(params)
- @username = params[:user][:username]
+ @user_name = params[:user][:name]
@project_name = params[:project_name]
@project_url = params[:project_url]
@@ -47,28 +47,28 @@ class SlackService
commit_sha = Commit.truncate_sha(commit_sha)
commit_link = "[commit #{commit_sha}](#{@note_url})"
title = format_title(commit[:message])
- @message = "#{@username} commented on #{commit_link} in #{project_link}: *#{title}*"
+ @message = "#{@user_name} commented on #{commit_link} in #{project_link}: *#{title}*"
end
def create_issue_note(issue)
issue_iid = issue[:iid]
note_link = "[issue ##{issue_iid}](#{@note_url})"
title = format_title(issue[:title])
- @message = "#{@username} commented on #{note_link} in #{project_link}: *#{title}*"
+ @message = "#{@user_name} commented on #{note_link} in #{project_link}: *#{title}*"
end
def create_merge_note(merge_request)
merge_request_id = merge_request[:iid]
merge_request_link = "[merge request ##{merge_request_id}](#{@note_url})"
title = format_title(merge_request[:title])
- @message = "#{@username} commented on #{merge_request_link} in #{project_link}: *#{title}*"
+ @message = "#{@user_name} commented on #{merge_request_link} in #{project_link}: *#{title}*"
end
def create_snippet_note(snippet)
snippet_id = snippet[:id]
snippet_link = "[snippet ##{snippet_id}](#{@note_url})"
title = format_title(snippet[:title])
- @message = "#{@username} commented on #{snippet_link} in #{project_link}: *#{title}*"
+ @message = "#{@user_name} commented on #{snippet_link} in #{project_link}: *#{title}*"
end
def description_message
diff --git a/app/models/project_services/slack_service/push_message.rb b/app/models/project_services/slack_service/push_message.rb
index 2e566bc317b..3dc2df04764 100644
--- a/app/models/project_services/slack_service/push_message.rb
+++ b/app/models/project_services/slack_service/push_message.rb
@@ -6,7 +6,8 @@ class SlackService
attr_reader :project_name
attr_reader :project_url
attr_reader :ref
- attr_reader :username
+ attr_reader :ref_type
+ attr_reader :user_name
def initialize(params)
@after = params[:after]
@@ -14,8 +15,14 @@ class SlackService
@commits = params.fetch(:commits, [])
@project_name = params[:project_name]
@project_url = params[:project_url]
- @ref = params[:ref].gsub('refs/heads/', '')
- @username = params[:user_name]
+ if params[:ref].starts_with?('refs/tags/')
+ @ref_type = 'tag'
+ @ref = params[:ref].gsub('refs/tags/', '')
+ else
+ @ref_type = 'branch'
+ @ref = params[:ref].gsub('refs/heads/', '')
+ end
+ @user_name = params[:user_name]
end
def pretext
@@ -45,15 +52,15 @@ class SlackService
end
def new_branch_message
- "#{username} pushed new branch #{branch_link} to #{project_link}"
+ "#{user_name} pushed new #{ref_type} #{branch_link} to #{project_link}"
end
def removed_branch_message
- "#{username} removed branch #{ref} from #{project_link}"
+ "#{user_name} removed #{ref_type} #{ref} from #{project_link}"
end
def push_message
- "#{username} pushed to branch #{branch_link} of #{project_link} (#{compare_link})"
+ "#{user_name} pushed to #{ref_type} #{branch_link} of #{project_link} (#{compare_link})"
end
def commit_messages