Code style, directory structure.

This commit is contained in:
Douwe Maan 2015-02-20 14:49:26 +01:00
parent afe5d7d209
commit d9ff616fd8
13 changed files with 59 additions and 57 deletions

View File

@ -65,16 +65,16 @@ automatically inspected. Leave blank to include all branches.'
] ]
end end
def execute(push) def execute(data)
object_kind = push[:object_kind] object_kind = data[:object_kind]
return unless object_kind == "push" return unless object_kind == "push"
Asana.configure do |client| Asana.configure do |client|
client.api_key = api_key client.api_key = api_key
end end
user = push[:user_name] user = data[:user_name]
branch = push[:ref].gsub('refs/heads/', '') branch = data[:ref].gsub('refs/heads/', '')
branch_restriction = restrict_to_branch.to_s branch_restriction = restrict_to_branch.to_s
@ -86,7 +86,7 @@ automatically inspected. Leave blank to include all branches.'
project_name = project.name_with_namespace project_name = project.name_with_namespace
push_msg = user + ' pushed to branch ' + branch + ' of ' + project_name 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) check_commit(' ( ' + commit[:url] + ' ): ' + commit[:message], push_msg)
end end
end end

View File

@ -41,14 +41,14 @@ class CampfireService < Service
] ]
end end
def execute(push_data) def execute(data)
object_kind = push_data[:object_kind] object_kind = data[:object_kind]
return unless object_kind == "push" return unless object_kind == "push"
room = gate.find_room_by_name(self.room) room = gate.find_room_by_name(self.room)
return true unless room return true unless room
message = build_message(push_data) message = build_message(data)
room.speak(message) room.speak(message)
end end

View File

@ -33,11 +33,11 @@ class EmailsOnPushService < Service
'emails_on_push' 'emails_on_push'
end end
def execute(push_data) def execute(data)
object_kind = push_data[:object_kind] object_kind = data[:object_kind]
return unless object_kind == "push" return unless object_kind == "push"
EmailsOnPushWorker.perform_async(project_id, recipients, push_data) EmailsOnPushWorker.perform_async(project_id, recipients, data)
end end
def fields def fields

View File

@ -41,14 +41,14 @@ class FlowdockService < Service
] ]
end end
def execute(push_data) def execute(data)
object_kind = push_data[:object_kind] object_kind = data[:object_kind]
return unless object_kind == "push" return unless object_kind == "push"
Flowdock::Git.post( Flowdock::Git.post(
push_data[:ref], data[:ref],
push_data[:before], data[:before],
push_data[:after], data[:after],
token: token, token: token,
repo: project.repository.path_to_repo, repo: project.repository.path_to_repo,
repo_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}", repo_url: "#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}",

View File

@ -42,14 +42,14 @@ class GemnasiumService < Service
] ]
end end
def execute(push_data) def execute(data)
object_kind = push_data[:object_kind] object_kind = data[:object_kind]
return unless object_kind == "push" return unless object_kind == "push"
Gemnasium::GitlabService.execute( Gemnasium::GitlabService.execute(
ref: push_data[:ref], ref: data[:ref],
before: push_data[:before], before: data[:before],
after: push_data[:after], after: data[:after],
token: token, token: token,
api_key: api_key, api_key: api_key,
repo: project.repository.path_to_repo repo: project.repository.path_to_repo

View File

@ -44,11 +44,11 @@ class HipchatService < Service
] ]
end end
def execute(push_data) def execute(data)
object_kind = push_data.fetch(:object_kind) object_kind = data[:object_kind]
return unless object_kind == "push" return unless object_kind == "push"
gate[room].send('GitLab', create_message(push_data)) gate[room].send('GitLab', create_message(data))
end end
private private

View File

@ -41,12 +41,12 @@ class PivotaltrackerService < Service
] ]
end end
def execute(push) def execute(data)
object_kind = push[:object_kind] object_kind = data[:object_kind]
return unless object_kind == "push" return unless object_kind == "push"
url = 'https://www.pivotaltracker.com/services/v5/source_commits' url = 'https://www.pivotaltracker.com/services/v5/source_commits'
push[:commits].each do |commit| data[:commits].each do |commit|
message = { message = {
'source_commit' => { 'source_commit' => {
'commit_id' => commit[:id], 'commit_id' => commit[:id],

View File

@ -80,24 +80,24 @@ class PushoverService < Service
] ]
end end
def execute(push_data) def execute(data)
object_kind = push_data[:object_kind] object_kind = data[:object_kind]
return unless object_kind == "push" return unless object_kind == "push"
ref = push_data[:ref].gsub('refs/heads/', '') ref = data[:ref].gsub('refs/heads/', '')
before = push_data[:before] before = data[:before]
after = push_data[:after] after = data[:after]
if before.include?('000000') 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') elsif after.include?('000000')
message = "#{push_data[:user_name]} deleted branch \"#{ref}\"." message = "#{data[:user_name]} deleted branch \"#{ref}\"."
else else
message = "#{push_data[:user_name]} push to branch \"#{ref}\"." message = "#{data[:user_name]} push to branch \"#{ref}\"."
end end
if push_data[:total_commits_count] > 0 if data[:total_commits_count] > 0
message << "\nTotal commits count: #{push_data[:total_commits_count]}" message << "\nTotal commits count: #{data[:total_commits_count]}"
end end
pushover_data = { pushover_data = {
@ -107,7 +107,7 @@ class PushoverService < Service
priority: priority, priority: priority,
title: "#{project.name_with_namespace}", title: "#{project.name_with_namespace}",
message: message, message: message,
url: push_data[:repository][:homepage], url: data[:repository][:homepage],
url_title: "See project #{project.name_with_namespace}" url_title: "See project #{project.name_with_namespace}"
} }

View File

@ -16,9 +16,6 @@
# merge_requests_events :boolean default(TRUE) # merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE) # tag_push_events :boolean default(TRUE)
# #
require "slack_messages/slack_issue_message"
require "slack_messages/slack_push_message"
require "slack_messages/slack_merge_message"
class SlackService < Service class SlackService < Service
prop_accessor :webhook, :username, :channel prop_accessor :webhook, :username, :channel
@ -59,14 +56,15 @@ class SlackService < Service
# 'close' action. Ignore update events for now to prevent duplicate # 'close' action. Ignore update events for now to prevent duplicate
# messages from arriving. # messages from arriving.
message = case object_kind message = \
when "push" case object_kind
message = SlackMessages::SlackPushMessage.new(data) when "push"
when "issue" PushMessage.new(data)
message = SlackMessages::SlackIssueMessage.new(data) unless is_update?(data) when "issue"
when "merge_request" IssueMessage.new(data) unless is_update?(data)
message = SlackMessages::SlackMergeMessage.new(data) unless is_update?(data) when "merge_request"
end MergeMessage.new(data) unless is_update?(data)
end
opt = {} opt = {}
opt[:channel] = channel if channel opt[:channel] = channel if channel
@ -92,3 +90,7 @@ class SlackService < Service
data[:object_attributes][:action] == 'update' data[:object_attributes][:action] == 'update'
end end
end end
require "slack_service/issue_message"
require "slack_service/push_message"
require "slack_service/merge_message"

View File

@ -1,7 +1,7 @@
require 'slack-notifier' require 'slack-notifier'
module SlackMessages class SlackService
class SlackBaseMessage class BaseMessage
def initialize(params) def initialize(params)
raise NotImplementedError raise NotImplementedError
end end

View File

@ -1,5 +1,5 @@
module SlackMessages module SlackService
class SlackIssueMessage < SlackBaseMessage class IssueMessage < BaseMessage
attr_reader :username attr_reader :username
attr_reader :title attr_reader :title
attr_reader :project_name attr_reader :project_name

View File

@ -1,5 +1,5 @@
module SlackMessages module SlackService
class SlackMergeMessage < SlackBaseMessage class MergeMessage < BaseMessage
attr_reader :username attr_reader :username
attr_reader :project_name attr_reader :project_name
attr_reader :project_url attr_reader :project_url

View File

@ -1,7 +1,7 @@
require 'slack-notifier' require 'slack-notifier'
module SlackMessages module SlackService
class SlackPushMessage < SlackBaseMessage class PushMessage < BaseMessage
attr_reader :after attr_reader :after
attr_reader :before attr_reader :before
attr_reader :commits attr_reader :commits