summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG4
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock19
-rw-r--r--app/assets/javascripts/wall.js.coffee2
-rw-r--r--app/controllers/services_controller.rb19
-rw-r--r--app/models/campfire_service.rb76
-rw-r--r--app/models/gitlab_ci_service.rb19
-rw-r--r--app/models/project.rb16
-rw-r--r--app/models/service.rb23
-rw-r--r--app/views/services/_form.html.haml48
-rw-r--r--app/views/services/_gitlab_ci.html.haml46
-rw-r--r--app/views/services/edit.html.haml2
-rw-r--r--app/views/services/index.html.haml38
-rw-r--r--db/migrate/20130522141856_add_more_fields_to_service.rb6
-rw-r--r--db/schema.rb4
-rw-r--r--features/steps/project/project_services.rb8
16 files changed, 242 insertions, 91 deletions
diff --git a/CHANGELOG b/CHANGELOG
index f21a9e8a943..99529d6a204 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+v 5.3.0
+ - Refactored services
+ - Campfire service added
+
v 5.2.0
- Turbolinks
- Git over http with ldap credentials
diff --git a/Gemfile b/Gemfile
index 2bc55bfa1cd..851a407abae 100644
--- a/Gemfile
+++ b/Gemfile
@@ -101,6 +101,9 @@ gem "foreman"
# Cache
gem "redis-rails"
+# Campfire integration
+gem 'tinder', '~> 1.9.2'
+
group :assets do
gem "sass-rails"
gem "coffee-rails"
diff --git a/Gemfile.lock b/Gemfile.lock
index 93798439d8c..4c4d9fa0e2d 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -130,6 +130,8 @@ GEM
railties (>= 3.0.0)
faraday (0.8.7)
multipart-post (~> 1.1)
+ faraday_middleware (0.9.0)
+ faraday (>= 0.7.4, < 0.9)
faye-websocket (0.4.7)
eventmachine (>= 0.12.0)
ffaker (1.16.0)
@@ -214,7 +216,7 @@ GEM
activesupport (>= 3.1, < 4.1)
haml (>= 3.1, < 4.1)
railties (>= 3.1, < 4.1)
- hashie (2.0.4)
+ hashie (1.2.0)
hike (1.2.2)
http_parser.rb (0.5.3)
httparty (0.11.0)
@@ -420,6 +422,7 @@ GEM
multi_json (~> 1)
redis (~> 3)
redis-namespace
+ simple_oauth (0.1.9)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
@@ -461,11 +464,24 @@ GEM
thor (0.18.1)
tilt (1.3.7)
timers (1.1.0)
+ tinder (1.9.2)
+ eventmachine (~> 1.0)
+ faraday (~> 0.8)
+ faraday_middleware (~> 0.9)
+ hashie (~> 1.0)
+ json (~> 1.7.5)
+ mime-types (~> 1.19)
+ multi_json (~> 1.5)
+ twitter-stream (~> 0.1)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
turbolinks (1.1.1)
coffee-rails
+ twitter-stream (0.1.16)
+ eventmachine (>= 0.12.8)
+ http_parser.rb (~> 0.5.1)
+ simple_oauth (~> 0.1.4)
tzinfo (0.3.37)
uglifier (2.0.1)
execjs (>= 0.3.0)
@@ -570,6 +586,7 @@ DEPENDENCIES
test_after_commit
therubyracer
thin
+ tinder (~> 1.9.2)
turbolinks
uglifier
webmock
diff --git a/app/assets/javascripts/wall.js.coffee b/app/assets/javascripts/wall.js.coffee
index c8fc960e174..9f8f62947cf 100644
--- a/app/assets/javascripts/wall.js.coffee
+++ b/app/assets/javascripts/wall.js.coffee
@@ -60,7 +60,7 @@ class Wall
renderNote: (note) ->
template = @noteTemplate()
template = template.replace('{{author_name}}', note.author.name)
- template = template.replace('{{created_at}}', note.created_at)
+ template = template.replace(/{{created_at}}/g, note.created_at)
template = template.replace('{{text}}', linkify(sanitize(note.body)))
if note.attachment
diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb
index 25a06501e07..fcfc4c84a91 100644
--- a/app/controllers/services_controller.rb
+++ b/app/controllers/services_controller.rb
@@ -1,25 +1,21 @@
class ServicesController < ProjectResourceController
# Authorize
before_filter :authorize_admin_project!
+ before_filter :service, only: [:edit, :update, :test]
respond_to :html
def index
- @gitlab_ci_service = @project.gitlab_ci_service
+ @project.build_missing_services
+ @services = @project.services.reload
end
def edit
- @service = @project.gitlab_ci_service
-
- # Create if missing
- @service = @project.create_gitlab_ci_service unless @service
end
def update
- @service = @project.gitlab_ci_service
-
if @service.update_attributes(params[:service])
- redirect_to edit_project_service_path(@project, :gitlab_ci)
+ redirect_to edit_project_service_path(@project, @service.to_param)
else
render 'edit'
end
@@ -28,9 +24,14 @@ class ServicesController < ProjectResourceController
def test
data = GitPushService.new.sample_data(project, current_user)
- @service = project.gitlab_ci_service
@service.execute(data)
redirect_to :back
end
+
+ private
+
+ def service
+ @service ||= @project.services.find { |service| service.to_param == params[:id] }
+ end
end
diff --git a/app/models/campfire_service.rb b/app/models/campfire_service.rb
new file mode 100644
index 00000000000..6450ffe7318
--- /dev/null
+++ b/app/models/campfire_service.rb
@@ -0,0 +1,76 @@
+# == Schema Information
+#
+# Table name: services
+#
+# id :integer not null, primary key
+# type :string(255)
+# title :string(255)
+# token :string(255)
+# project_id :integer not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# active :boolean default(FALSE), not null
+# project_url :string(255)
+#
+
+class CampfireService < Service
+ attr_accessible :subdomain, :room
+
+ 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
+
+ def execute(push_data)
+ room = gate.find_room_by_name(self.room)
+ return true unless room
+
+ message = build_message(push_data)
+
+ 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]} "
+
+ if before =~ /000000/
+ message << "pushed new branch #{ref} \n"
+ elsif after =~ /000000/
+ 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
diff --git a/app/models/gitlab_ci_service.rb b/app/models/gitlab_ci_service.rb
index 9b1c707a6c9..bdbe7724be0 100644
--- a/app/models/gitlab_ci_service.rb
+++ b/app/models/gitlab_ci_service.rb
@@ -54,4 +54,23 @@ class GitlabCiService < Service
def status_img_path
project_url + "/status.png?ref=" + project.default_branch
end
+
+ def title
+ 'GitLab CI'
+ end
+
+ def description
+ 'Continuous integration server from GitLab'
+ end
+
+ def to_param
+ 'gitlab_ci'
+ end
+
+ def fields
+ [
+ { type: 'text', name: 'token', placeholder: 'GitLab CI project specific token' },
+ { type: 'text', name: 'project_url', placeholder: 'http://ci.gitlabhq.com/projects/3'}
+ ]
+ end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index bd33e3a4c13..f214eeb525d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -45,9 +45,11 @@ class Project < ActiveRecord::Base
has_one :last_event, class_name: 'Event', order: 'events.created_at DESC', foreign_key: 'project_id'
has_one :gitlab_ci_service, dependent: :destroy
+ has_one :campfire_service, dependent: :destroy
has_one :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id"
has_one :forked_from_project, through: :forked_project_link
+ has_many :services, dependent: :destroy
has_many :events, dependent: :destroy
has_many :merge_requests, dependent: :destroy
has_many :issues, dependent: :destroy, order: "state DESC, created_at DESC"
@@ -223,8 +225,18 @@ class Project < ActiveRecord::Base
self.issues_enabled && !self.used_default_issues_tracker?
end
- def services
- [gitlab_ci_service].compact
+ def build_missing_services
+ available_services_names.each do |service_name|
+ service = services.find { |service| service.to_param == service_name }
+
+ # If service is available but missing in db
+ # we should create an instance. Ex `create_gitlab_ci_service`
+ service = self.send :"create_#{service_name}_service" if service.nil?
+ end
+ end
+
+ def available_services_names
+ %w(gitlab_ci campfire)
end
def gitlab_ci?
diff --git a/app/models/service.rb b/app/models/service.rb
index d3486d29200..3e945aa898c 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -13,6 +13,8 @@
# project_url :string(255)
#
+# To add new service you should build a class inherited from Service
+# and implement a set of methods
class Service < ActiveRecord::Base
attr_accessible :title, :token, :type, :active
@@ -24,4 +26,25 @@ class Service < ActiveRecord::Base
def activated?
active
end
+
+ def title
+ # implement inside child
+ end
+
+ def description
+ # implement inside child
+ end
+
+ def to_param
+ # implement inside child
+ end
+
+ def fields
+ # implement inside child
+ []
+ end
+
+ def execute
+ # implement inside child
+ end
end
diff --git a/app/views/services/_form.html.haml b/app/views/services/_form.html.haml
new file mode 100644
index 00000000000..ff6769531c4
--- /dev/null
+++ b/app/views/services/_form.html.haml
@@ -0,0 +1,48 @@
+%h3.page_title
+ - if @service.activated?
+ %span.cgreen
+ %i.icon-circle
+ - else
+ %span.cgray
+ %i.icon-circle-blank
+ = @service.title
+
+%p= @service.description
+
+.back_link
+ = link_to project_services_path(@project) do
+ &larr; to services
+
+%hr
+
+= form_for(@service, as: :service, url: project_service_path(@project, @service.to_param), method: :put) do |f|
+ - if @service.errors.any?
+ .alert.alert-error
+ %ul
+ - @service.errors.full_messages.each do |msg|
+ %li= msg
+
+
+ .control-group
+ = f.label :active, "Active", class: "control-label"
+ .controls
+ = f.check_box :active
+
+ - @service.fields.each do |field|
+ - name = field[:name]
+ - type = field[:type]
+ - placeholder = field[:placeholder]
+
+ .control-group
+ = f.label name, class: "control-label"
+ .controls
+ - if type == 'text'
+ = f.text_field name, class: "input-xlarge", placeholder: placeholder
+ - elsif type == 'checkbox'
+ = f.check_box name
+
+ .form-actions
+ = f.submit 'Save', class: 'btn btn-save'
+ &nbsp;
+ - if @service.valid? && @service.activated?
+ = link_to 'Test settings', test_project_service_path(@project, @service.to_param), class: 'btn btn-small'
diff --git a/app/views/services/_gitlab_ci.html.haml b/app/views/services/_gitlab_ci.html.haml
deleted file mode 100644
index dfde643849e..00000000000
--- a/app/views/services/_gitlab_ci.html.haml
+++ /dev/null
@@ -1,46 +0,0 @@
-%h3.page_title
- GitLab CI
- %small Continuous integration server from GitLab
- .pull-right
- - if @service.active
- %small.cgreen Enabled
- - else
- %small.cgray Disabled
-
-
-
-.back_link
- = link_to project_services_path(@project) do
- &larr; to services
-
-%hr
-= form_for(@service, :as => :service, :url => project_service_path(@project, :gitlab_ci), :method => :put) do |f|
- - if @service.errors.any?
- .alert.alert-error
- %ul
- - @service.errors.full_messages.each do |msg|
- %li= msg
-
-
- .control-group
- = f.label :active, "Active", class: "control-label"
- .controls
- = f.check_box :active
-
- .control-group
- = f.label :project_url, "Project URL", class: "control-label"
- .controls
- = f.text_field :project_url, class: "input-xlarge", placeholder: "http://ci.gitlabhq.com/projects/3"
-
- .control-group
- = f.label :token, class: "control-label" do
- CI Project token
- .controls
- = f.text_field :token, class: "input-xlarge", placeholder: "GitLab CI project specific token"
-
-
- .form-actions
- = f.submit 'Save', class: 'btn btn-save'
- &nbsp;
- - if @service.valid? && @service.active
- = link_to 'Test settings', test_project_service_path(@project), class: 'btn btn-small'
diff --git a/app/views/services/edit.html.haml b/app/views/services/edit.html.haml
index 0c63a7ed58c..d4bc9e41c27 100644
--- a/app/views/services/edit.html.haml
+++ b/app/views/services/edit.html.haml
@@ -1,3 +1,3 @@
= render "projects/settings_nav"
-= render 'gitlab_ci'
+= render 'form'
diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml
index eb2f8d0ca1c..bd52948a6fd 100644
--- a/app/views/services/index.html.haml
+++ b/app/views/services/index.html.haml
@@ -3,30 +3,16 @@
%h3.page_title Services
%br
-%ul.ui-box.well-list
- %li
- %h4.cgreen
- = link_to edit_project_service_path(@project, :gitlab_ci) do
- GitLab CI
- %small Continuous integration server from GitLab
- .pull-right
- - if @gitlab_ci_service.try(:active)
- %small.cgreen
- %i.icon-ok
- Enabled
+%ul.bordered-list
+ - @services.each do |service|
+ %li
+ %h4
+ - if service.activated?
+ %span.cgreen
+ %i.icon-circle
- else
- %small.cgray
- %i.icon-off
- Disabled
- %li.disabled
- %h4
- Jenkins CI
- %small An extendable open source continuous integration server
- .pull-right
- %small Not implemented yet
- %li.disabled
- %h4
- Campfire
- %small Web-based group chat tool
- .pull-right
- %small Not implemented yet
+ %span.cgray
+ %i.icon-circle-blank
+ = link_to edit_project_service_path(@project, service.to_param) do
+ = service.title
+ %p= service.description
diff --git a/db/migrate/20130522141856_add_more_fields_to_service.rb b/db/migrate/20130522141856_add_more_fields_to_service.rb
new file mode 100644
index 00000000000..298e902df2f
--- /dev/null
+++ b/db/migrate/20130522141856_add_more_fields_to_service.rb
@@ -0,0 +1,6 @@
+class AddMoreFieldsToService < ActiveRecord::Migration
+ def change
+ add_column :services, :subdomain, :string
+ add_column :services, :room, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index d2fa70cc374..6a16caf59d8 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130506095501) do
+ActiveRecord::Schema.define(:version => 20130522141856) do
create_table "deploy_keys_projects", :force => true do |t|
t.integer "deploy_key_id", :null => false
@@ -194,6 +194,8 @@ ActiveRecord::Schema.define(:version => 20130506095501) do
t.datetime "updated_at", :null => false
t.boolean "active", :default => false, :null => false
t.string "project_url"
+ t.string "subdomain"
+ t.string "room"
end
add_index "services", ["project_id"], :name => "index_services_on_project_id"
diff --git a/features/steps/project/project_services.rb b/features/steps/project/project_services.rb
index b1668ff7207..4b270cb5c8a 100644
--- a/features/steps/project/project_services.rb
+++ b/features/steps/project/project_services.rb
@@ -9,7 +9,7 @@ class ProjectServices < Spinach::FeatureSteps
Then 'I should see list of available services' do
page.should have_content 'Services'
- page.should have_content 'Jenkins'
+ page.should have_content 'Campfire'
page.should have_content 'GitLab CI'
end
@@ -19,12 +19,12 @@ class ProjectServices < Spinach::FeatureSteps
And 'I fill gitlab-ci settings' do
check 'Active'
- fill_in 'Project URL', with: 'http://ci.gitlab.org/projects/3'
- fill_in 'CI Project token', with: 'verySecret'
+ fill_in 'Project url', with: 'http://ci.gitlab.org/projects/3'
+ fill_in 'Token', with: 'verySecret'
click_button 'Save'
end
Then 'I should see service settings saved' do
- find_field('Project URL').value.should == 'http://ci.gitlab.org/projects/3'
+ find_field('Project url').value.should == 'http://ci.gitlab.org/projects/3'
end
end