2013-05-22 14:59:59 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: services
|
|
|
|
#
|
2015-03-04 22:14:00 +00:00
|
|
|
# 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)
|
2015-02-19 05:02:57 +00:00
|
|
|
# push_events :boolean default(TRUE)
|
|
|
|
# issues_events :boolean default(TRUE)
|
|
|
|
# merge_requests_events :boolean default(TRUE)
|
|
|
|
# tag_push_events :boolean default(TRUE)
|
2015-03-05 18:38:23 +00:00
|
|
|
# note_events :boolean default(TRUE), not null
|
2013-05-22 14:59:59 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
class CampfireService < Service
|
2014-09-08 00:54:18 +00:00
|
|
|
prop_accessor :token, :subdomain, :room
|
2013-05-22 14:59:59 +00: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 16:33:18 +00:00
|
|
|
def supported_events
|
|
|
|
%w(push)
|
|
|
|
end
|
|
|
|
|
2015-02-20 13:49:26 +00:00
|
|
|
def execute(data)
|
2015-02-28 16:33:18 +00:00
|
|
|
return unless supported_events.include?(data[:object_kind])
|
2015-02-19 05:02:57 +00:00
|
|
|
|
2013-05-22 14:59:59 +00:00
|
|
|
room = gate.find_room_by_name(self.room)
|
|
|
|
return true unless room
|
|
|
|
|
2015-02-20 13:49:26 +00:00
|
|
|
message = build_message(data)
|
2013-05-22 14:59:59 +00:00
|
|
|
|
|
|
|
room.speak(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def gate
|
|
|
|
@gate ||= Tinder::Campfire.new(subdomain, token: token)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_message(push)
|
|
|
|
ref = push[:ref].gsub("refs/heads/", "")
|
|
|
|
before = push[:before]
|
|
|
|
after = push[:after]
|
|
|
|
|
|
|
|
message = ""
|
|
|
|
message << "[#{project.name_with_namespace}] "
|
|
|
|
message << "#{push[:user_name]} "
|
|
|
|
|
2014-10-19 14:09:38 +00:00
|
|
|
if before.include?('000000')
|
2013-05-22 14:59:59 +00:00
|
|
|
message << "pushed new branch #{ref} \n"
|
2014-10-19 14:09:38 +00:00
|
|
|
elsif after.include?('000000')
|
2013-05-22 14:59:59 +00: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
|