Commit 63178a95 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge branch 'add-more-slack-notifications' into 'master'

Add more Slack notifications for issue and merge request events

From https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/237 by Stan Hu.

See merge request !1556
......@@ -32,6 +32,7 @@ v 7.8.2
- 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 import check for case sensetive namespaces
- Added issue and merge request events to Slack service (Stan Hu)
v 7.8.1
- Fix run of custom post receive hooks
......
......@@ -51,7 +51,8 @@ def service_params
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
:build_key, :server, :teamcity_url, :build_type,
:description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
:colorize_messages, :channels
:colorize_messages, :channels,
:push_events, :issues_events, :merge_requests_events, :tag_push_events
)
end
end
......@@ -479,8 +479,9 @@ def execute_hooks(data, hooks_scope = :push_hooks)
end
end
def execute_services(data)
services.select(&:active).each do |service|
def execute_services(data, hooks_scope = :push_hooks)
# Call only service hooks that are active for this scope
services.send(hooks_scope).each do |service|
service.async_execute(data)
end
end
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
require 'asana'
......@@ -61,13 +65,19 @@ def fields
]
end
def execute(push)
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
Asana.configure do |client|
client.api_key = api_key
end
user = push[:user_name]
branch = push[:ref].gsub('refs/heads/', '')
user = data[:user_name]
branch = data[:ref].gsub('refs/heads/', '')
branch_restriction = restrict_to_branch.to_s
......@@ -79,7 +89,7 @@ def execute(push)
project_name = project.name_with_namespace
push_msg = user + ' pushed to branch ' + branch + ' of ' + project_name
push[:commits].each do |commit|
data[:commits].each do |commit|
check_commit(' ( ' + commit[:url] + ' ): ' + commit[:message], push_msg)
end
end
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class AssemblaService < Service
......@@ -38,8 +42,14 @@ def fields
]
end
def execute(push)
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
url = "https://atlas.assembla.com/spaces/#{subdomain}/github_tool?secret_key=#{token}"
AssemblaService.post(url, body: { payload: push }.to_json, headers: { 'Content-Type' => 'application/json' })
AssemblaService.post(url, body: { payload: data }.to_json, headers: { 'Content-Type' => 'application/json' })
end
end
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class BambooService < CiService
......@@ -69,6 +73,10 @@ def fields
]
end
def supported_events
%w(push)
end
def build_info(sha)
url = URI.parse("#{bamboo_url}/rest/api/latest/result?label=#{sha}")
......@@ -118,7 +126,9 @@ def commit_status(sha)
end
end
def execute(_data)
def execute(data)
return unless supported_events.include?(data[:object_kind])
# Bamboo requires a GET and does not take any data.
self.class.get("#{bamboo_url}/updateAndBuild.action?buildKey=#{build_key}",
verify: false)
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
require "addressable/uri"
......@@ -32,7 +36,13 @@ def compose_service_hook
hook.save
end
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
service_hook.execute(data)
end
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class CampfireService < Service
......@@ -37,11 +41,17 @@ def fields
]
end
def execute(push_data)
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
room = gate.find_room_by_name(self.room)
return true unless room
message = build_message(push_data)
message = build_message(data)
room.speak(message)
end
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean
# issues_events :boolean
# merge_requests_events :boolean
# tag_push_events :boolean
#
# Base class for CI services
......@@ -21,6 +25,10 @@ def category
:ci
end
def supported_events
%w(push)
end
# Return complete url to build page
#
# Ex.
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean
# issues_events :boolean
# merge_requests_events :boolean
# tag_push_events :boolean
#
class EmailsOnPushService < Service
......@@ -29,8 +33,14 @@ def to_param
'emails_on_push'
end
def execute(push_data)
EmailsOnPushWorker.perform_async(project_id, recipients, push_data)
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
EmailsOnPushWorker.perform_async(project_id, recipients, data)
end
def fields
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean
# issues_events :boolean
# merge_requests_events :boolean
# tag_push_events :boolean
#
require "flowdock-git-hook"
......@@ -37,11 +41,17 @@ def fields
]
end
def execute(push_data)
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
Flowdock::Git.post(
push_data[:ref],
push_data[:before],
push_data[:after],
data[:ref],
data[:before],
data[:after],
token: token,
repo: project.repository.path_to_repo,
repo_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}",
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean
# issues_events :boolean
# merge_requests_events :boolean
# tag_push_events :boolean
#
require "gemnasium/gitlab_service"
......@@ -38,11 +42,17 @@ def fields
]
end
def execute(push_data)
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
Gemnasium::GitlabService.execute(
ref: push_data[:ref],
before: push_data[:before],
after: push_data[:after],
ref: data[:ref],
before: data[:before],
after: data[:after],
token: token,
api_key: api_key,
repo: project.repository.path_to_repo
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean
# issues_events :boolean
# merge_requests_events :boolean
# tag_push_events :boolean
#
class GitlabCiService < CiService
......@@ -18,8 +22,6 @@ class GitlabCiService < CiService
validates :project_url, presence: true, if: :activated?
validates :token, presence: true, if: :activated?
delegate :execute, to: :service_hook, prefix: nil
after_save :compose_service_hook, if: :activated?
def compose_service_hook
......@@ -28,6 +30,16 @@ def compose_service_hook
hook.save
end
def supported_events
%w(push tag_push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
service_hook.execute(data)
end
def commit_status_path(sha)
project_url + "/commits/#{sha}/status.json?token=#{token}"
end
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class GitlabIssueTrackerService < IssueTrackerService
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean
# issues_events :boolean
# merge_requests_events :boolean
# tag_push_events :boolean
#
class HipchatService < Service
......@@ -40,8 +44,14 @@ def fields
]
end
def execute(push_data)
gate[room].send('GitLab', create_message(push_data))
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
gate[room].send('GitLab', create_message(data))
end
private
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class IssueTrackerService < Service
......@@ -65,7 +69,13 @@ def initialize_properties
end
end
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
message = "#{self.type} was unable to reach #{self.project_url}. Check the url and try again."
result = false
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class JiraService < IssueTrackerService
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class PivotaltrackerService < Service
......@@ -37,9 +41,15 @@ def fields
]
end
def execute(push)
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
url = 'https://www.pivotaltracker.com/services/v5/source_commits'
push[:commits].each do |commit|
data[:commits].each do |commit|
message = {
'source_commit' => {
'commit_id' => commit[:id],
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class PushoverService < Service
......@@ -76,21 +80,27 @@ def fields
]
end
def execute(push_data)
ref = push_data[:ref].gsub('refs/heads/', '')
before = push_data[:before]
after = push_data[:after]
def supported_events
%w(push)
end
def execute(data)
return unless supported_events.include?(data[:object_kind])
ref = data[:ref].gsub('refs/heads/', '')
before = data[:before]
after = data[:after]
if before.include?('000000')
message = "#{push_data[:user_name]} pushed new branch \"#{ref}\"."
message = "#{data[:user_name]} pushed new branch \"#{ref}\"."
elsif after.include?('000000')
message = "#{push_data[:user_name]} deleted branch \"#{ref}\"."
message = "#{data[:user_name]} deleted branch \"#{ref}\"."
else
message = "#{push_data[:user_name]} push to branch \"#{ref}\"."
message = "#{data[:user_name]} push to branch \"#{ref}\"."
end
if push_data[:total_commits_count] > 0
message << "\nTotal commits count: #{push_data[:total_commits_count]}"
if data[:total_commits_count] > 0
message << "\nTotal commits count: #{data[:total_commits_count]}"
end
pushover_data = {
......@@ -100,7 +110,7 @@ def execute(push_data)
priority: priority,
title: "#{project.name_with_namespace}",
message: message,
url: push_data[:repository][:homepage],
url: data[:repository][:homepage],
url_title: "See project #{project.name_with_namespace}"
}
......
......@@ -11,6 +11,10 @@
# active :boolean default(FALSE), not null
# properties :text
# template :boolean default(FALSE)
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
class RedmineService < IssueTrackerService
......
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