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"
This commit is contained in:
parent
76802012e6
commit
ad14ed5e49
12 changed files with 134 additions and 64 deletions
|
@ -1,8 +1,9 @@
|
||||||
Please view this file on the master branch, on stable branches it's out of date.
|
Please view this file on the master branch, on stable branches it's out of date.
|
||||||
|
|
||||||
v 7.9.0 (unreleased)
|
v 7.9.0 (unreleased)
|
||||||
- Added comment notification events to HipChat and Slack services (Stan Hu)
|
- Add tag push notifications and normalize HipChat and Slack messages to be consistent (Stan Hu)
|
||||||
- Added issue and merge request events to HipChat and Slack services (Stan Hu)
|
- Add comment notification events to HipChat and Slack services (Stan Hu)
|
||||||
|
- Add issue and merge request events to HipChat and Slack services (Stan Hu)
|
||||||
- Fix merge request URL passed to Webhooks. (Stan Hu)
|
- Fix merge request URL passed to Webhooks. (Stan Hu)
|
||||||
- Fix bug that caused a server error when editing a comment to "+1" or "-1" (Stan Hu)
|
- Fix bug that caused a server error when editing a comment to "+1" or "-1" (Stan Hu)
|
||||||
- Move labels/milestones tabs to sidebar
|
- Move labels/milestones tabs to sidebar
|
||||||
|
@ -35,7 +36,6 @@ v 7.8.2
|
||||||
- Fix response of push to repository to return "Not found" if user doesn't have access
|
- Fix response of push to repository to return "Not found" if user doesn't have access
|
||||||
- Fix check if user is allowed to view the file attachment
|
- Fix check if user is allowed to view the file attachment
|
||||||
- Fix import check for case sensetive namespaces
|
- Fix import check for case sensetive namespaces
|
||||||
- Added issue and merge request events to Slack service (Stan Hu)
|
|
||||||
- Increase timeout for Git-over-HTTP requests to 1 hour since large pulls/pushes can take a long time.
|
- Increase timeout for Git-over-HTTP requests to 1 hour since large pulls/pushes can take a long time.
|
||||||
|
|
||||||
v 7.8.1
|
v 7.8.1
|
||||||
|
|
|
@ -45,7 +45,7 @@ class HipchatService < Service
|
||||||
end
|
end
|
||||||
|
|
||||||
def supported_events
|
def supported_events
|
||||||
%w(push issue merge_request note)
|
%w(push issue merge_request note tag_push)
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(data)
|
def execute(data)
|
||||||
|
@ -67,7 +67,7 @@ class HipchatService < Service
|
||||||
|
|
||||||
message = \
|
message = \
|
||||||
case object_kind
|
case object_kind
|
||||||
when "push"
|
when "push", "tag_push"
|
||||||
create_push_message(data)
|
create_push_message(data)
|
||||||
when "issue"
|
when "issue"
|
||||||
create_issue_message(data) unless is_update?(data)
|
create_issue_message(data) unless is_update?(data)
|
||||||
|
@ -79,21 +79,27 @@ class HipchatService < Service
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_push_message(push)
|
def create_push_message(push)
|
||||||
ref = push[:ref].gsub("refs/heads/", "")
|
if push[:ref].starts_with?('refs/tags/')
|
||||||
|
ref_type = 'tag'
|
||||||
|
ref = push[:ref].gsub('refs/tags/', '')
|
||||||
|
else
|
||||||
|
ref_type = 'branch'
|
||||||
|
ref = push[:ref].gsub('refs/heads/', '')
|
||||||
|
end
|
||||||
|
|
||||||
before = push[:before]
|
before = push[:before]
|
||||||
after = push[:after]
|
after = push[:after]
|
||||||
|
|
||||||
message = ""
|
message = ""
|
||||||
message << "#{push[:user_name]} "
|
message << "#{push[:user_name]} "
|
||||||
if before.include?('000000')
|
if before.include?('000000')
|
||||||
message << "pushed new branch <a href=\""\
|
message << "pushed new #{ref_type} <a href=\""\
|
||||||
"#{project_url}/commits/#{URI.escape(ref)}\">#{ref}</a>"\
|
"#{project_url}/commits/#{URI.escape(ref)}\">#{ref}</a>"\
|
||||||
" to <a href=\"#{project_url}\">"\
|
" to #{project_link}\n"
|
||||||
"#{project_url}</a>\n"
|
|
||||||
elsif after.include?('000000')
|
elsif after.include?('000000')
|
||||||
message << "removed branch #{ref} from <a href=\"#{project.web_url}\">#{project.name_with_namespace.gsub!(/\s/,'')}</a> \n"
|
message << "removed #{ref_type} <b>#{ref}</b> from <a href=\"#{project.web_url}\">#{project_name}</a> \n"
|
||||||
else
|
else
|
||||||
message << "pushed to branch <a href=\""\
|
message << "pushed to #{ref_type} <a href=\""\
|
||||||
"#{project.web_url}/commits/#{URI.escape(ref)}\">#{ref}</a> "
|
"#{project.web_url}/commits/#{URI.escape(ref)}\">#{ref}</a> "
|
||||||
message << "of <a href=\"#{project.web_url}\">#{project.name_with_namespace.gsub!(/\s/,'')}</a> "
|
message << "of <a href=\"#{project.web_url}\">#{project.name_with_namespace.gsub!(/\s/,'')}</a> "
|
||||||
message << "(<a href=\"#{project.web_url}/compare/#{before}...#{after}\">Compare changes</a>)"
|
message << "(<a href=\"#{project.web_url}/compare/#{before}...#{after}\">Compare changes</a>)"
|
||||||
|
@ -119,7 +125,7 @@ class HipchatService < Service
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_issue_message(data)
|
def create_issue_message(data)
|
||||||
username = data[:user][:username]
|
user_name = data[:user][:name]
|
||||||
|
|
||||||
obj_attr = data[:object_attributes]
|
obj_attr = data[:object_attributes]
|
||||||
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
||||||
|
@ -129,8 +135,8 @@ class HipchatService < Service
|
||||||
issue_url = obj_attr[:url]
|
issue_url = obj_attr[:url]
|
||||||
description = obj_attr[:description]
|
description = obj_attr[:description]
|
||||||
|
|
||||||
issue_link = "<a href=\"#{issue_url}\">##{issue_iid}</a>"
|
issue_link = "<a href=\"#{issue_url}\">issue ##{issue_iid}</a>"
|
||||||
message = "#{username} #{state} issue #{issue_link} in #{project_link}: <b>#{title}</b>"
|
message = "#{user_name} #{state} #{issue_link} in #{project_link}: <b>#{title}</b>"
|
||||||
|
|
||||||
if description
|
if description
|
||||||
description = format_body(description)
|
description = format_body(description)
|
||||||
|
@ -141,7 +147,7 @@ class HipchatService < Service
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_merge_request_message(data)
|
def create_merge_request_message(data)
|
||||||
username = data[:user][:username]
|
user_name = data[:user][:name]
|
||||||
|
|
||||||
obj_attr = data[:object_attributes]
|
obj_attr = data[:object_attributes]
|
||||||
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
||||||
|
@ -153,8 +159,8 @@ class HipchatService < Service
|
||||||
title = obj_attr[:title]
|
title = obj_attr[:title]
|
||||||
|
|
||||||
merge_request_url = "#{project_url}/merge_requests/#{merge_request_id}"
|
merge_request_url = "#{project_url}/merge_requests/#{merge_request_id}"
|
||||||
merge_request_link = "<a href=\"#{merge_request_url}\">##{merge_request_id}</a>"
|
merge_request_link = "<a href=\"#{merge_request_url}\">merge request ##{merge_request_id}</a>"
|
||||||
message = "#{username} #{state} merge request #{merge_request_link} in " \
|
message = "#{user_name} #{state} #{merge_request_link} in " \
|
||||||
"#{project_link}: <b>#{title}</b>"
|
"#{project_link}: <b>#{title}</b>"
|
||||||
|
|
||||||
if description
|
if description
|
||||||
|
@ -171,7 +177,7 @@ class HipchatService < Service
|
||||||
|
|
||||||
def create_note_message(data)
|
def create_note_message(data)
|
||||||
data = HashWithIndifferentAccess.new(data)
|
data = HashWithIndifferentAccess.new(data)
|
||||||
username = data[:user][:username]
|
user_name = data[:user][:name]
|
||||||
|
|
||||||
repo_attr = HashWithIndifferentAccess.new(data[:repository])
|
repo_attr = HashWithIndifferentAccess.new(data[:repository])
|
||||||
|
|
||||||
|
@ -208,7 +214,7 @@ class HipchatService < Service
|
||||||
end
|
end
|
||||||
|
|
||||||
subject_html = "<a href=\"#{note_url}\">#{subject_type} #{subject_desc}</a>"
|
subject_html = "<a href=\"#{note_url}\">#{subject_type} #{subject_desc}</a>"
|
||||||
message = "#{username} commented on #{subject_html} in #{project_link}: "
|
message = "#{user_name} commented on #{subject_html} in #{project_link}: "
|
||||||
message << title
|
message << title
|
||||||
|
|
||||||
if note
|
if note
|
||||||
|
|
|
@ -44,7 +44,7 @@ class SlackService < Service
|
||||||
end
|
end
|
||||||
|
|
||||||
def supported_events
|
def supported_events
|
||||||
%w(push issue merge_request note)
|
%w(push issue merge_request note tag_push)
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute(data)
|
def execute(data)
|
||||||
|
@ -64,7 +64,7 @@ class SlackService < Service
|
||||||
|
|
||||||
message = \
|
message = \
|
||||||
case object_kind
|
case object_kind
|
||||||
when "push"
|
when "push", "tag_push"
|
||||||
PushMessage.new(data)
|
PushMessage.new(data)
|
||||||
when "issue"
|
when "issue"
|
||||||
IssueMessage.new(data) unless is_update?(data)
|
IssueMessage.new(data) unless is_update?(data)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class SlackService
|
class SlackService
|
||||||
class IssueMessage < BaseMessage
|
class IssueMessage < BaseMessage
|
||||||
attr_reader :username
|
attr_reader :user_name
|
||||||
attr_reader :title
|
attr_reader :title
|
||||||
attr_reader :project_name
|
attr_reader :project_name
|
||||||
attr_reader :project_url
|
attr_reader :project_url
|
||||||
|
@ -11,7 +11,7 @@ class SlackService
|
||||||
attr_reader :description
|
attr_reader :description
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
@username = params[:user][:username]
|
@user_name = params[:user][:name]
|
||||||
@project_name = params[:project_name]
|
@project_name = params[:project_name]
|
||||||
@project_url = params[:project_url]
|
@project_url = params[:project_url]
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class SlackService
|
||||||
private
|
private
|
||||||
|
|
||||||
def message
|
def message
|
||||||
"#{username} #{state} issue #{issue_link} in #{project_link}: #{title}"
|
"#{user_name} #{state} #{issue_link} in #{project_link}: *#{title}*"
|
||||||
end
|
end
|
||||||
|
|
||||||
def opened_issue?
|
def opened_issue?
|
||||||
|
@ -50,7 +50,7 @@ class SlackService
|
||||||
end
|
end
|
||||||
|
|
||||||
def issue_link
|
def issue_link
|
||||||
"[##{issue_iid}](#{issue_url})"
|
"[issue ##{issue_iid}](#{issue_url})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
class SlackService
|
class SlackService
|
||||||
class MergeMessage < BaseMessage
|
class MergeMessage < BaseMessage
|
||||||
attr_reader :username
|
attr_reader :user_name
|
||||||
attr_reader :project_name
|
attr_reader :project_name
|
||||||
attr_reader :project_url
|
attr_reader :project_url
|
||||||
attr_reader :merge_request_id
|
attr_reader :merge_request_id
|
||||||
attr_reader :source_branch
|
attr_reader :source_branch
|
||||||
attr_reader :target_branch
|
attr_reader :target_branch
|
||||||
attr_reader :state
|
attr_reader :state
|
||||||
|
attr_reader :title
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
@username = params[:user][:username]
|
@user_name = params[:user][:name]
|
||||||
@project_name = params[:project_name]
|
@project_name = params[:project_name]
|
||||||
@project_url = params[:project_url]
|
@project_url = params[:project_url]
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ class SlackService
|
||||||
@source_branch = obj_attr[:source_branch]
|
@source_branch = obj_attr[:source_branch]
|
||||||
@target_branch = obj_attr[:target_branch]
|
@target_branch = obj_attr[:target_branch]
|
||||||
@state = obj_attr[:state]
|
@state = obj_attr[:state]
|
||||||
|
@title = format_title(obj_attr[:title])
|
||||||
end
|
end
|
||||||
|
|
||||||
def pretext
|
def pretext
|
||||||
|
@ -31,6 +33,10 @@ class SlackService
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def format_title(title)
|
||||||
|
'*' + title.lines.first.chomp + '*'
|
||||||
|
end
|
||||||
|
|
||||||
def message
|
def message
|
||||||
merge_request_message
|
merge_request_message
|
||||||
end
|
end
|
||||||
|
@ -40,11 +46,11 @@ class SlackService
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge_request_message
|
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
|
end
|
||||||
|
|
||||||
def merge_request_link
|
def merge_request_link
|
||||||
"[##{merge_request_id}](#{merge_request_url})"
|
"[merge request ##{merge_request_id}](#{merge_request_url})"
|
||||||
end
|
end
|
||||||
|
|
||||||
def merge_request_url
|
def merge_request_url
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class SlackService
|
class SlackService
|
||||||
class NoteMessage < BaseMessage
|
class NoteMessage < BaseMessage
|
||||||
attr_reader :message
|
attr_reader :message
|
||||||
attr_reader :username
|
attr_reader :user_name
|
||||||
attr_reader :project_name
|
attr_reader :project_name
|
||||||
attr_reader :project_link
|
attr_reader :project_link
|
||||||
attr_reader :note
|
attr_reader :note
|
||||||
|
@ -10,7 +10,7 @@ class SlackService
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
params = HashWithIndifferentAccess.new(params)
|
params = HashWithIndifferentAccess.new(params)
|
||||||
@username = params[:user][:username]
|
@user_name = params[:user][:name]
|
||||||
@project_name = params[:project_name]
|
@project_name = params[:project_name]
|
||||||
@project_url = params[:project_url]
|
@project_url = params[:project_url]
|
||||||
|
|
||||||
|
@ -47,28 +47,28 @@ class SlackService
|
||||||
commit_sha = Commit.truncate_sha(commit_sha)
|
commit_sha = Commit.truncate_sha(commit_sha)
|
||||||
commit_link = "[commit #{commit_sha}](#{@note_url})"
|
commit_link = "[commit #{commit_sha}](#{@note_url})"
|
||||||
title = format_title(commit[:message])
|
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
|
end
|
||||||
|
|
||||||
def create_issue_note(issue)
|
def create_issue_note(issue)
|
||||||
issue_iid = issue[:iid]
|
issue_iid = issue[:iid]
|
||||||
note_link = "[issue ##{issue_iid}](#{@note_url})"
|
note_link = "[issue ##{issue_iid}](#{@note_url})"
|
||||||
title = format_title(issue[:title])
|
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
|
end
|
||||||
|
|
||||||
def create_merge_note(merge_request)
|
def create_merge_note(merge_request)
|
||||||
merge_request_id = merge_request[:iid]
|
merge_request_id = merge_request[:iid]
|
||||||
merge_request_link = "[merge request ##{merge_request_id}](#{@note_url})"
|
merge_request_link = "[merge request ##{merge_request_id}](#{@note_url})"
|
||||||
title = format_title(merge_request[:title])
|
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
|
end
|
||||||
|
|
||||||
def create_snippet_note(snippet)
|
def create_snippet_note(snippet)
|
||||||
snippet_id = snippet[:id]
|
snippet_id = snippet[:id]
|
||||||
snippet_link = "[snippet ##{snippet_id}](#{@note_url})"
|
snippet_link = "[snippet ##{snippet_id}](#{@note_url})"
|
||||||
title = format_title(snippet[:title])
|
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
|
end
|
||||||
|
|
||||||
def description_message
|
def description_message
|
||||||
|
|
|
@ -6,7 +6,8 @@ class SlackService
|
||||||
attr_reader :project_name
|
attr_reader :project_name
|
||||||
attr_reader :project_url
|
attr_reader :project_url
|
||||||
attr_reader :ref
|
attr_reader :ref
|
||||||
attr_reader :username
|
attr_reader :ref_type
|
||||||
|
attr_reader :user_name
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
@after = params[:after]
|
@after = params[:after]
|
||||||
|
@ -14,8 +15,14 @@ class SlackService
|
||||||
@commits = params.fetch(:commits, [])
|
@commits = params.fetch(:commits, [])
|
||||||
@project_name = params[:project_name]
|
@project_name = params[:project_name]
|
||||||
@project_url = params[:project_url]
|
@project_url = params[:project_url]
|
||||||
@ref = params[:ref].gsub('refs/heads/', '')
|
if params[:ref].starts_with?('refs/tags/')
|
||||||
@username = params[:user_name]
|
@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
|
end
|
||||||
|
|
||||||
def pretext
|
def pretext
|
||||||
|
@ -45,15 +52,15 @@ class SlackService
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_branch_message
|
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
|
end
|
||||||
|
|
||||||
def removed_branch_message
|
def removed_branch_message
|
||||||
"#{username} removed branch #{ref} from #{project_link}"
|
"#{user_name} removed #{ref_type} #{ref} from #{project_link}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def push_message
|
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
|
end
|
||||||
|
|
||||||
def commit_messages
|
def commit_messages
|
||||||
|
|
|
@ -50,6 +50,35 @@ describe HipchatService do
|
||||||
|
|
||||||
expect(WebMock).to have_requested(:post, api_url).once
|
expect(WebMock).to have_requested(:post, api_url).once
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should create a push message" do
|
||||||
|
message = hipchat.send(:create_push_message, push_sample_data)
|
||||||
|
|
||||||
|
obj_attr = push_sample_data[:object_attributes]
|
||||||
|
branch = push_sample_data[:ref].gsub('refs/heads/', '')
|
||||||
|
expect(message).to include("#{user.name} pushed to branch " \
|
||||||
|
"<a href=\"#{project.web_url}/commits/#{branch}\">#{branch}</a> of " \
|
||||||
|
"<a href=\"#{project.web_url}\">#{project_name}</a>")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'tag_push events' do
|
||||||
|
let(:push_sample_data) { Gitlab::PushDataBuilder.build(project, user, '000000', '111111', 'refs/tags/test', []) }
|
||||||
|
|
||||||
|
it "should call Hipchat API for tag push events" do
|
||||||
|
hipchat.execute(push_sample_data)
|
||||||
|
|
||||||
|
expect(WebMock).to have_requested(:post, api_url).once
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create a tag push message" do
|
||||||
|
message = hipchat.send(:create_push_message, push_sample_data)
|
||||||
|
|
||||||
|
obj_attr = push_sample_data[:object_attributes]
|
||||||
|
expect(message).to eq("#{user.name} pushed new tag " \
|
||||||
|
"<a href=\"#{project.web_url}/commits/test\">test</a> to " \
|
||||||
|
"<a href=\"#{project.web_url}\">#{project_name}</a>\n")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'issue events' do
|
context 'issue events' do
|
||||||
|
@ -67,8 +96,8 @@ describe HipchatService do
|
||||||
message = hipchat.send(:create_issue_message, issues_sample_data)
|
message = hipchat.send(:create_issue_message, issues_sample_data)
|
||||||
|
|
||||||
obj_attr = issues_sample_data[:object_attributes]
|
obj_attr = issues_sample_data[:object_attributes]
|
||||||
expect(message).to eq("#{user.username} opened issue " \
|
expect(message).to eq("#{user.name} opened " \
|
||||||
"<a href=\"#{obj_attr[:url]}\">##{obj_attr["iid"]}</a> in " \
|
"<a href=\"#{obj_attr[:url]}\">issue ##{obj_attr["iid"]}</a> in " \
|
||||||
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
||||||
"<b>Awesome issue</b>" \
|
"<b>Awesome issue</b>" \
|
||||||
"<pre>please fix</pre>")
|
"<pre>please fix</pre>")
|
||||||
|
@ -91,8 +120,8 @@ describe HipchatService do
|
||||||
merge_sample_data)
|
merge_sample_data)
|
||||||
|
|
||||||
obj_attr = merge_sample_data[:object_attributes]
|
obj_attr = merge_sample_data[:object_attributes]
|
||||||
expect(message).to eq("#{user.username} opened merge request " \
|
expect(message).to eq("#{user.name} opened " \
|
||||||
"<a href=\"#{obj_attr[:url]}\">##{obj_attr["iid"]}</a> in " \
|
"<a href=\"#{obj_attr[:url]}\">merge request ##{obj_attr["iid"]}</a> in " \
|
||||||
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
||||||
"<b>Awesome merge request</b>" \
|
"<b>Awesome merge request</b>" \
|
||||||
"<pre>please fix</pre>")
|
"<pre>please fix</pre>")
|
||||||
|
@ -122,7 +151,7 @@ describe HipchatService do
|
||||||
commit_id = Commit.truncate_sha(data[:commit][:id])
|
commit_id = Commit.truncate_sha(data[:commit][:id])
|
||||||
title = hipchat.send(:format_title, data[:commit][:message])
|
title = hipchat.send(:format_title, data[:commit][:message])
|
||||||
|
|
||||||
expect(message).to eq("#{user.username} commented on " \
|
expect(message).to eq("#{user.name} commented on " \
|
||||||
"<a href=\"#{obj_attr[:url]}\">commit #{commit_id}</a> in " \
|
"<a href=\"#{obj_attr[:url]}\">commit #{commit_id}</a> in " \
|
||||||
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
||||||
"#{title}" \
|
"#{title}" \
|
||||||
|
@ -141,7 +170,7 @@ describe HipchatService do
|
||||||
merge_id = data[:merge_request]['iid']
|
merge_id = data[:merge_request]['iid']
|
||||||
title = data[:merge_request]['title']
|
title = data[:merge_request]['title']
|
||||||
|
|
||||||
expect(message).to eq("#{user.username} commented on " \
|
expect(message).to eq("#{user.name} commented on " \
|
||||||
"<a href=\"#{obj_attr[:url]}\">merge request ##{merge_id}</a> in " \
|
"<a href=\"#{obj_attr[:url]}\">merge request ##{merge_id}</a> in " \
|
||||||
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
||||||
"<b>#{title}</b>" \
|
"<b>#{title}</b>" \
|
||||||
|
@ -158,7 +187,7 @@ describe HipchatService do
|
||||||
issue_id = data[:issue]['iid']
|
issue_id = data[:issue]['iid']
|
||||||
title = data[:issue]['title']
|
title = data[:issue]['title']
|
||||||
|
|
||||||
expect(message).to eq("#{user.username} commented on " \
|
expect(message).to eq("#{user.name} commented on " \
|
||||||
"<a href=\"#{obj_attr[:url]}\">issue ##{issue_id}</a> in " \
|
"<a href=\"#{obj_attr[:url]}\">issue ##{issue_id}</a> in " \
|
||||||
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
||||||
"<b>#{title}</b>" \
|
"<b>#{title}</b>" \
|
||||||
|
@ -177,7 +206,7 @@ describe HipchatService do
|
||||||
snippet_id = data[:snippet]['id']
|
snippet_id = data[:snippet]['id']
|
||||||
title = data[:snippet]['title']
|
title = data[:snippet]['title']
|
||||||
|
|
||||||
expect(message).to eq("#{user.username} commented on " \
|
expect(message).to eq("#{user.name} commented on " \
|
||||||
"<a href=\"#{obj_attr[:url]}\">snippet ##{snippet_id}</a> in " \
|
"<a href=\"#{obj_attr[:url]}\">snippet ##{snippet_id}</a> in " \
|
||||||
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
"<a href=\"#{project.web_url}\">#{project_name}</a>: " \
|
||||||
"<b>#{title}</b>" \
|
"<b>#{title}</b>" \
|
||||||
|
|
|
@ -6,7 +6,8 @@ describe SlackService::IssueMessage do
|
||||||
let(:args) {
|
let(:args) {
|
||||||
{
|
{
|
||||||
user: {
|
user: {
|
||||||
username: 'username'
|
name: 'Test User',
|
||||||
|
username: 'Test User'
|
||||||
},
|
},
|
||||||
project_name: 'project_name',
|
project_name: 'project_name',
|
||||||
project_url: 'somewhere.com',
|
project_url: 'somewhere.com',
|
||||||
|
@ -29,8 +30,8 @@ describe SlackService::IssueMessage do
|
||||||
context 'open' do
|
context 'open' do
|
||||||
it 'returns a message regarding opening of issues' do
|
it 'returns a message regarding opening of issues' do
|
||||||
expect(subject.pretext).to eq(
|
expect(subject.pretext).to eq(
|
||||||
'username opened issue <url|#100> in <somewhere.com|project_name>: '\
|
'Test User opened <url|issue #100> in <somewhere.com|project_name>: '\
|
||||||
'Issue title')
|
'*Issue title*')
|
||||||
expect(subject.attachments).to eq([
|
expect(subject.attachments).to eq([
|
||||||
{
|
{
|
||||||
text: "issue description",
|
text: "issue description",
|
||||||
|
@ -47,8 +48,8 @@ describe SlackService::IssueMessage do
|
||||||
end
|
end
|
||||||
it 'returns a message regarding closing of issues' do
|
it 'returns a message regarding closing of issues' do
|
||||||
expect(subject.pretext). to eq(
|
expect(subject.pretext). to eq(
|
||||||
'username closed issue <url|#100> in <somewhere.com|project_name>: '\
|
'Test User closed <url|issue #100> in <somewhere.com|project_name>: '\
|
||||||
'Issue title')
|
'*Issue title*')
|
||||||
expect(subject.attachments).to be_empty
|
expect(subject.attachments).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,13 +6,14 @@ describe SlackService::MergeMessage do
|
||||||
let(:args) {
|
let(:args) {
|
||||||
{
|
{
|
||||||
user: {
|
user: {
|
||||||
username: 'username'
|
name: 'Test User',
|
||||||
|
username: 'Test User'
|
||||||
},
|
},
|
||||||
project_name: 'project_name',
|
project_name: 'project_name',
|
||||||
project_url: 'somewhere.com',
|
project_url: 'somewhere.com',
|
||||||
|
|
||||||
object_attributes: {
|
object_attributes: {
|
||||||
title: 'Issue title',
|
title: "Issue title\nSecond line",
|
||||||
id: 10,
|
id: 10,
|
||||||
iid: 100,
|
iid: 100,
|
||||||
assignee_id: 1,
|
assignee_id: 1,
|
||||||
|
@ -30,8 +31,8 @@ describe SlackService::MergeMessage do
|
||||||
context 'open' do
|
context 'open' do
|
||||||
it 'returns a message regarding opening of merge requests' do
|
it 'returns a message regarding opening of merge requests' do
|
||||||
expect(subject.pretext).to eq(
|
expect(subject.pretext).to eq(
|
||||||
'username opened merge request <somewhere.com/merge_requests/100|#100> '\
|
'Test User opened <somewhere.com/merge_requests/100|merge request #100> '\
|
||||||
'in <somewhere.com|project_name>')
|
'in <somewhere.com|project_name>: *Issue title*')
|
||||||
expect(subject.attachments).to be_empty
|
expect(subject.attachments).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,8 +43,8 @@ describe SlackService::MergeMessage do
|
||||||
end
|
end
|
||||||
it 'returns a message regarding closing of merge requests' do
|
it 'returns a message regarding closing of merge requests' do
|
||||||
expect(subject.pretext).to eq(
|
expect(subject.pretext).to eq(
|
||||||
'username closed merge request <somewhere.com/merge_requests/100|#100> '\
|
'Test User closed <somewhere.com/merge_requests/100|merge request #100> '\
|
||||||
'in <somewhere.com|project_name>')
|
'in <somewhere.com|project_name>: *Issue title*')
|
||||||
expect(subject.attachments).to be_empty
|
expect(subject.attachments).to be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,7 @@ describe SlackService::NoteMessage do
|
||||||
|
|
||||||
it 'returns a message regarding notes on commits' do
|
it 'returns a message regarding notes on commits' do
|
||||||
message = SlackService::NoteMessage.new(@args)
|
message = SlackService::NoteMessage.new(@args)
|
||||||
expect(message.pretext).to eq("username commented on " \
|
expect(message.pretext).to eq("Test User commented on " \
|
||||||
"<url|commit 5f163b2b> in <somewhere.com|project_name>: " \
|
"<url|commit 5f163b2b> in <somewhere.com|project_name>: " \
|
||||||
"*Added a commit message*")
|
"*Added a commit message*")
|
||||||
expected_attachments = [
|
expected_attachments = [
|
||||||
|
@ -62,7 +62,7 @@ describe SlackService::NoteMessage do
|
||||||
end
|
end
|
||||||
it 'returns a message regarding notes on a merge request' do
|
it 'returns a message regarding notes on a merge request' do
|
||||||
message = SlackService::NoteMessage.new(@args)
|
message = SlackService::NoteMessage.new(@args)
|
||||||
expect(message.pretext).to eq("username commented on " \
|
expect(message.pretext).to eq("Test User commented on " \
|
||||||
"<url|merge request #30> in <somewhere.com|project_name>: " \
|
"<url|merge request #30> in <somewhere.com|project_name>: " \
|
||||||
"*merge request title*")
|
"*merge request title*")
|
||||||
expected_attachments = [
|
expected_attachments = [
|
||||||
|
@ -89,7 +89,7 @@ describe SlackService::NoteMessage do
|
||||||
it 'returns a message regarding notes on an issue' do
|
it 'returns a message regarding notes on an issue' do
|
||||||
message = SlackService::NoteMessage.new(@args)
|
message = SlackService::NoteMessage.new(@args)
|
||||||
expect(message.pretext).to eq(
|
expect(message.pretext).to eq(
|
||||||
"username commented on " \
|
"Test User commented on " \
|
||||||
"<url|issue #20> in <somewhere.com|project_name>: " \
|
"<url|issue #20> in <somewhere.com|project_name>: " \
|
||||||
"*issue title*")
|
"*issue title*")
|
||||||
expected_attachments = [
|
expected_attachments = [
|
||||||
|
@ -114,7 +114,7 @@ describe SlackService::NoteMessage do
|
||||||
|
|
||||||
it 'returns a message regarding notes on a project snippet' do
|
it 'returns a message regarding notes on a project snippet' do
|
||||||
message = SlackService::NoteMessage.new(@args)
|
message = SlackService::NoteMessage.new(@args)
|
||||||
expect(message.pretext).to eq("username commented on " \
|
expect(message.pretext).to eq("Test User commented on " \
|
||||||
"<url|snippet #5> in <somewhere.com|project_name>: " \
|
"<url|snippet #5> in <somewhere.com|project_name>: " \
|
||||||
"*snippet title*")
|
"*snippet title*")
|
||||||
expected_attachments = [
|
expected_attachments = [
|
||||||
|
|
|
@ -39,6 +39,26 @@ describe SlackService::PushMessage do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'tag push' do
|
||||||
|
let(:args) {
|
||||||
|
{
|
||||||
|
after: 'after',
|
||||||
|
before: '000000',
|
||||||
|
project_name: 'project_name',
|
||||||
|
ref: 'refs/tags/new_tag',
|
||||||
|
user_name: 'user_name',
|
||||||
|
project_url: 'url'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it 'returns a message regarding pushes' do
|
||||||
|
expect(subject.pretext).to eq('user_name pushed new tag ' \
|
||||||
|
'<url/commits/new_tag|new_tag> to ' \
|
||||||
|
'<url|project_name>')
|
||||||
|
expect(subject.attachments).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'new branch' do
|
context 'new branch' do
|
||||||
before do
|
before do
|
||||||
args[:before] = '000000'
|
args[:before] = '000000'
|
||||||
|
|
Loading…
Reference in a new issue