Commit ac952d047031dc6ee2dde8eac6f74e219378d03f
1 parent
83e2e624
Exists in
master
and in
4 other branches
Campfire service added
Showing
4 changed files
with
83 additions
and
2 deletions
Show diff stats
CHANGELOG
app/controllers/services_controller.rb
| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | +# == Schema Information | |
| 2 | +# | |
| 3 | +# Table name: services | |
| 4 | +# | |
| 5 | +# id :integer not null, primary key | |
| 6 | +# type :string(255) | |
| 7 | +# title :string(255) | |
| 8 | +# token :string(255) | |
| 9 | +# project_id :integer not null | |
| 10 | +# created_at :datetime not null | |
| 11 | +# updated_at :datetime not null | |
| 12 | +# active :boolean default(FALSE), not null | |
| 13 | +# project_url :string(255) | |
| 14 | +# | |
| 15 | + | |
| 16 | +class CampfireService < Service | |
| 17 | + attr_accessible :subdomain, :room | |
| 18 | + | |
| 19 | + validates :token, presence: true, if: :activated? | |
| 20 | + | |
| 21 | + def title | |
| 22 | + 'Campfire' | |
| 23 | + end | |
| 24 | + | |
| 25 | + def description | |
| 26 | + 'Simple web-based real-time group chat' | |
| 27 | + end | |
| 28 | + | |
| 29 | + def to_param | |
| 30 | + 'campfire' | |
| 31 | + end | |
| 32 | + | |
| 33 | + def fields | |
| 34 | + [ | |
| 35 | + { type: 'text', name: 'token', placeholder: '' }, | |
| 36 | + { type: 'text', name: 'subdomain', placeholder: '' }, | |
| 37 | + { type: 'text', name: 'room', placeholder: '' } | |
| 38 | + ] | |
| 39 | + end | |
| 40 | + | |
| 41 | + def execute(push_data) | |
| 42 | + room = gate.find_room_by_name(self.room) | |
| 43 | + return true unless room | |
| 44 | + | |
| 45 | + message = build_message(push_data) | |
| 46 | + | |
| 47 | + room.speak(message) | |
| 48 | + end | |
| 49 | + | |
| 50 | + private | |
| 51 | + | |
| 52 | + def gate | |
| 53 | + @gate ||= Tinder::Campfire.new(subdomain, token: token) | |
| 54 | + end | |
| 55 | + | |
| 56 | + def build_message(push) | |
| 57 | + ref = push[:ref].gsub("refs/heads/", "") | |
| 58 | + before = push[:before] | |
| 59 | + after = push[:after] | |
| 60 | + | |
| 61 | + message = "" | |
| 62 | + message << "[#{project.name_with_namespace}] " | |
| 63 | + message << "#{push[:user_name]} " | |
| 64 | + | |
| 65 | + if before =~ /000000/ | |
| 66 | + message << "pushed new branch #{ref} \n" | |
| 67 | + elsif after =~ /000000/ | |
| 68 | + message << "removed branch #{ref} \n" | |
| 69 | + else | |
| 70 | + message << "pushed #{push[:total_commits_count]} commits to #{ref}. " | |
| 71 | + message << "#{project.web_url}/compare/#{before}...#{after}" | |
| 72 | + end | |
| 73 | + | |
| 74 | + message | |
| 75 | + end | |
| 76 | +end | ... | ... |
app/models/project.rb
| ... | ... | @@ -45,6 +45,7 @@ class Project < ActiveRecord::Base |
| 45 | 45 | |
| 46 | 46 | has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id' |
| 47 | 47 | has_one :gitlab_ci_service, dependent: :destroy |
| 48 | + has_one :campfire_service, dependent: :destroy | |
| 48 | 49 | has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" |
| 49 | 50 | has_one :forked_from_project, through: :forked_project_link |
| 50 | 51 | |
| ... | ... | @@ -235,7 +236,7 @@ class Project < ActiveRecord::Base |
| 235 | 236 | end |
| 236 | 237 | |
| 237 | 238 | def available_services_names |
| 238 | - %w(gitlab_ci) | |
| 239 | + %w(gitlab_ci campfire) | |
| 239 | 240 | end |
| 240 | 241 | |
| 241 | 242 | def gitlab_ci? | ... | ... |