Skip to content
Snippets Groups Projects
Commit d9ff616f authored by Douwe Maan's avatar Douwe Maan
Browse files

Code style, directory structure.

parent afe5d7d2
No related branches found
No related tags found
1 merge request!8686add "Uplaod" and "Replace" functionality
Showing
with 59 additions and 57 deletions
Loading
Loading
@@ -65,16 +65,16 @@ automatically inspected. Leave blank to include all branches.'
]
end
 
def execute(push)
object_kind = push[:object_kind]
def execute(data)
object_kind = data[:object_kind]
return unless object_kind == "push"
 
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
 
Loading
Loading
@@ -86,7 +86,7 @@ automatically inspected. Leave blank to include all branches.'
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
Loading
Loading
Loading
Loading
@@ -41,14 +41,14 @@ class CampfireService < Service
]
end
 
def execute(push_data)
object_kind = push_data[:object_kind]
def execute(data)
object_kind = data[:object_kind]
return unless object_kind == "push"
 
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
Loading
Loading
Loading
Loading
@@ -33,11 +33,11 @@ class EmailsOnPushService < Service
'emails_on_push'
end
 
def execute(push_data)
object_kind = push_data[:object_kind]
def execute(data)
object_kind = data[:object_kind]
return unless object_kind == "push"
 
EmailsOnPushWorker.perform_async(project_id, recipients, push_data)
EmailsOnPushWorker.perform_async(project_id, recipients, data)
end
 
def fields
Loading
Loading
Loading
Loading
@@ -41,14 +41,14 @@ class FlowdockService < Service
]
end
 
def execute(push_data)
object_kind = push_data[:object_kind]
def execute(data)
object_kind = data[:object_kind]
return unless object_kind == "push"
 
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}",
Loading
Loading
Loading
Loading
@@ -42,14 +42,14 @@ class GemnasiumService < Service
]
end
 
def execute(push_data)
object_kind = push_data[:object_kind]
def execute(data)
object_kind = data[:object_kind]
return unless object_kind == "push"
 
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
Loading
Loading
Loading
Loading
@@ -44,11 +44,11 @@ class HipchatService < Service
]
end
 
def execute(push_data)
object_kind = push_data.fetch(:object_kind)
def execute(data)
object_kind = data[:object_kind]
return unless object_kind == "push"
 
gate[room].send('GitLab', create_message(push_data))
gate[room].send('GitLab', create_message(data))
end
 
private
Loading
Loading
Loading
Loading
@@ -41,12 +41,12 @@ class PivotaltrackerService < Service
]
end
 
def execute(push)
object_kind = push[:object_kind]
def execute(data)
object_kind = data[:object_kind]
return unless object_kind == "push"
 
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],
Loading
Loading
Loading
Loading
@@ -80,24 +80,24 @@ class PushoverService < Service
]
end
 
def execute(push_data)
object_kind = push_data[:object_kind]
def execute(data)
object_kind = data[:object_kind]
return unless object_kind == "push"
 
ref = push_data[:ref].gsub('refs/heads/', '')
before = push_data[:before]
after = push_data[:after]
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 = {
Loading
Loading
@@ -107,7 +107,7 @@ class PushoverService < Service
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}"
}
 
Loading
Loading
Loading
Loading
@@ -16,9 +16,6 @@
# merge_requests_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
prop_accessor :webhook, :username, :channel
Loading
Loading
@@ -59,14 +56,15 @@ class SlackService < Service
# 'close' action. Ignore update events for now to prevent duplicate
# messages from arriving.
 
message = case object_kind
when "push"
message = SlackMessages::SlackPushMessage.new(data)
when "issue"
message = SlackMessages::SlackIssueMessage.new(data) unless is_update?(data)
when "merge_request"
message = SlackMessages::SlackMergeMessage.new(data) unless is_update?(data)
end
message = \
case object_kind
when "push"
PushMessage.new(data)
when "issue"
IssueMessage.new(data) unless is_update?(data)
when "merge_request"
MergeMessage.new(data) unless is_update?(data)
end
 
opt = {}
opt[:channel] = channel if channel
Loading
Loading
@@ -92,3 +90,7 @@ class SlackService < Service
data[:object_attributes][:action] == 'update'
end
end
require "slack_service/issue_message"
require "slack_service/push_message"
require "slack_service/merge_message"
\ No newline at end of file
require 'slack-notifier'
 
module SlackMessages
class SlackBaseMessage
class SlackService
class BaseMessage
def initialize(params)
raise NotImplementedError
end
Loading
Loading
module SlackMessages
class SlackIssueMessage < SlackBaseMessage
module SlackService
class IssueMessage < BaseMessage
attr_reader :username
attr_reader :title
attr_reader :project_name
Loading
Loading
module SlackMessages
class SlackMergeMessage < SlackBaseMessage
module SlackService
class MergeMessage < BaseMessage
attr_reader :username
attr_reader :project_name
attr_reader :project_url
Loading
Loading
require 'slack-notifier'
 
module SlackMessages
class SlackPushMessage < SlackBaseMessage
module SlackService
class PushMessage < BaseMessage
attr_reader :after
attr_reader :before
attr_reader :commits
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment