2014-09-02 18:07:02 +05:30
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: services
|
|
|
|
#
|
2015-04-26 12:48:37 +05:30
|
|
|
# id :integer not null, primary key
|
|
|
|
# type :string(255)
|
|
|
|
# title :string(255)
|
|
|
|
# project_id :integer
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# 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)
|
|
|
|
# note_events :boolean default(TRUE), not null
|
2016-01-14 18:37:52 +05:30
|
|
|
# build_events :boolean default(FALSE), not null
|
2014-09-02 18:07:02 +05:30
|
|
|
#
|
|
|
|
|
|
|
|
class CampfireService < Service
|
2015-04-26 12:48:37 +05:30
|
|
|
prop_accessor :token, :subdomain, :room
|
2014-09-02 18:07:02 +05:30
|
|
|
validates :token, presence: true, if: :activated?
|
|
|
|
|
|
|
|
def title
|
|
|
|
'Campfire'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
'Simple web-based real-time group chat'
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
'campfire'
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
|
|
|
{ type: 'text', name: 'token', placeholder: '' },
|
|
|
|
{ type: 'text', name: 'subdomain', placeholder: '' },
|
|
|
|
{ type: 'text', name: 'room', placeholder: '' }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def supported_events
|
|
|
|
%w(push)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(data)
|
|
|
|
return unless supported_events.include?(data[:object_kind])
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
room = gate.find_room_by_name(self.room)
|
|
|
|
return true unless room
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
message = build_message(data)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
room.speak(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def gate
|
|
|
|
@gate ||= Tinder::Campfire.new(subdomain, token: token)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_message(push)
|
2015-04-26 12:48:37 +05:30
|
|
|
ref = Gitlab::Git.ref_name(push[:ref])
|
2014-09-02 18:07:02 +05:30
|
|
|
before = push[:before]
|
|
|
|
after = push[:after]
|
|
|
|
|
|
|
|
message = ""
|
|
|
|
message << "[#{project.name_with_namespace}] "
|
|
|
|
message << "#{push[:user_name]} "
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
if Gitlab::Git.blank_ref?(before)
|
2014-09-02 18:07:02 +05:30
|
|
|
message << "pushed new branch #{ref} \n"
|
2015-04-26 12:48:37 +05:30
|
|
|
elsif Gitlab::Git.blank_ref?(after)
|
2014-09-02 18:07:02 +05:30
|
|
|
message << "removed branch #{ref} \n"
|
|
|
|
else
|
|
|
|
message << "pushed #{push[:total_commits_count]} commits to #{ref}. "
|
|
|
|
message << "#{project.web_url}/compare/#{before}...#{after}"
|
|
|
|
end
|
|
|
|
|
|
|
|
message
|
|
|
|
end
|
|
|
|
end
|