2013-05-22 10:59:59 -04:00
|
|
|
class CampfireService < Service
|
2014-09-07 20:54:18 -04:00
|
|
|
prop_accessor :token, :subdomain, :room
|
2013-05-22 10:59:59 -04:00
|
|
|
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-02-28 11:33:18 -05:00
|
|
|
def supported_events
|
|
|
|
%w(push)
|
|
|
|
end
|
|
|
|
|
2015-02-20 08:49:26 -05:00
|
|
|
def execute(data)
|
2015-02-28 11:33:18 -05:00
|
|
|
return unless supported_events.include?(data[:object_kind])
|
2015-02-19 00:02:57 -05:00
|
|
|
|
2013-05-22 10:59:59 -04:00
|
|
|
room = gate.find_room_by_name(self.room)
|
|
|
|
return true unless room
|
|
|
|
|
2015-02-20 08:49:26 -05:00
|
|
|
message = build_message(data)
|
2013-05-22 10:59:59 -04:00
|
|
|
|
|
|
|
room.speak(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def gate
|
|
|
|
@gate ||= Tinder::Campfire.new(subdomain, token: token)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_message(push)
|
2015-03-10 06:51:36 -04:00
|
|
|
ref = Gitlab::Git.ref_name(push[:ref])
|
2013-05-22 10:59:59 -04:00
|
|
|
before = push[:before]
|
|
|
|
after = push[:after]
|
|
|
|
|
|
|
|
message = ""
|
|
|
|
message << "[#{project.name_with_namespace}] "
|
|
|
|
message << "#{push[:user_name]} "
|
|
|
|
|
2015-03-10 06:51:36 -04:00
|
|
|
if Gitlab::Git.blank_ref?(before)
|
2013-05-22 10:59:59 -04:00
|
|
|
message << "pushed new branch #{ref} \n"
|
2015-03-10 06:51:36 -04:00
|
|
|
elsif Gitlab::Git.blank_ref?(after)
|
2013-05-22 10:59:59 -04:00
|
|
|
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
|