summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-10-08 12:34:22 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-10-08 12:34:22 +0300
commitb694bf6f64171692fba75a54c6d98dab6e8cda8c (patch)
treeb1f71a55a2e9959c4dabd7da6bac3e01e4036169
parentd30e1f5cb827893c1f24411545399284d0994d96 (diff)
parentf013973d19b9ae145b6f642e085172f1e266d5ef (diff)
downloadgitlab-ce-b694bf6f64171692fba75a54c6d98dab6e8cda8c.tar.gz
Merge pull request #7545 from buildbox/buildbox-service
Buildbox Service Integration
-rw-r--r--app/models/project.rb3
-rw-r--r--app/models/project_services/buildbox_service.rb121
-rw-r--r--app/views/projects/show.html.haml13
-rw-r--r--spec/models/buildbox_service_spec.rb78
4 files changed, 209 insertions, 6 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 44d63d37bee..90d2649ba23 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -64,6 +64,7 @@ class Project < ActiveRecord::Base
has_one :assembla_service, dependent: :destroy
has_one :gemnasium_service, dependent: :destroy
has_one :slack_service, dependent: :destroy
+ has_one :buildbox_service, dependent: :destroy
has_one :pushover_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
@@ -312,7 +313,7 @@ class Project < ActiveRecord::Base
end
def available_services_names
- %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack pushover)
+ %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack pushover buildbox)
end
def gitlab_ci?
diff --git a/app/models/project_services/buildbox_service.rb b/app/models/project_services/buildbox_service.rb
new file mode 100644
index 00000000000..7904177f9d2
--- /dev/null
+++ b/app/models/project_services/buildbox_service.rb
@@ -0,0 +1,121 @@
+# == Schema Information
+#
+# Table name: services
+#
+# id :integer not null, primary key
+# type :string(255)
+# title :string(255)
+# project_id :integer not null
+# created_at :datetime
+# updated_at :datetime
+# active :boolean default(FALSE), not null
+# property :text
+#
+
+class BuildboxService < CiService
+ prop_accessor :project_url, :token
+
+ validates :project_url, presence: true, if: :activated?
+ validates :token, presence: true, if: :activated?
+
+ after_save :compose_service_hook, if: :activated?
+
+ def webhook_url
+ "#{buildbox_endpoint('webhook')}/deliver/#{webhook_token}"
+ end
+
+ def compose_service_hook
+ hook = service_hook || build_service_hook
+ hook.url = webhook_url
+ hook.save
+ end
+
+ def execute(data)
+ service_hook.execute(data)
+ end
+
+ def commit_status(sha)
+ response = HTTParty.get(commit_status_path(sha), verify: false)
+
+ if response.code == 200 && response['status']
+ response['status']
+ else
+ :error
+ end
+ end
+
+ def commit_status_path(sha)
+ "#{buildbox_endpoint('gitlab')}/status/#{status_token}.json?commit=#{sha}"
+ end
+
+ def build_page(sha)
+ "#{project_url}/builds?commit=#{sha}"
+ end
+
+ def builds_path
+ "#{project_url}/builds?branch=#{project.default_branch}"
+ end
+
+ def status_img_path
+ "#{buildbox_endpoint('badge')}/#{status_token}.svg"
+ end
+
+ def title
+ 'Buildbox'
+ end
+
+ def description
+ 'Continuous integration and deployments'
+ end
+
+ def to_param
+ 'buildbox'
+ end
+
+ def fields
+ [
+ { type: 'text',
+ name: 'token',
+ placeholder: 'Buildbox project GitLab token' },
+
+ { type: 'text',
+ name: 'project_url',
+ placeholder: 'https://buildbox.io/example/project' }
+ ]
+ end
+
+ private
+
+ def webhook_token
+ token_parts.first
+ end
+
+ def status_token
+ token_parts.second
+ end
+
+ def token_parts
+ if token.present?
+ token.split(':')
+ else
+ []
+ end
+ end
+
+ def buildbox_endpoint(subdomain = nil)
+ endpoint = 'https://buildbox.io'
+
+ if subdomain.present?
+ uri = Addressable::URI.parse(endpoint)
+ new_endpoint = "#{uri.scheme || 'http'}://#{subdomain}.#{uri.host}"
+
+ if uri.port.present?
+ "#{new_endpoint}:#{uri.port}"
+ else
+ new_endpoint
+ end
+ else
+ endpoint
+ end
+ end
+end
diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml
index 09664ed51eb..9b06ebe95a4 100644
--- a/app/views/projects/show.html.haml
+++ b/app/views/projects/show.html.haml
@@ -62,11 +62,14 @@
- else
#{link_to @project.owner_name, @project.owner}
-
- - if @project.gitlab_ci?
- %hr
- = link_to @project.gitlab_ci_service.builds_path do
- = image_tag @project.gitlab_ci_service.status_img_path, alt: "build status"
+ - @project.ci_services.each do |ci_service|
+ - if ci_service.active? && ci_service.respond_to?(:builds_path)
+ - if ci_service.respond_to?(:status_img_path)
+ = link_to ci_service.builds_path do
+ = image_tag ci_service.status_img_path, alt: "build status"
+ - else
+ %span.light CI provided by
+ = link_to ci_service.title, ci_service.builds_path
- if readme
.tab-pane#tab-readme
diff --git a/spec/models/buildbox_service_spec.rb b/spec/models/buildbox_service_spec.rb
new file mode 100644
index 00000000000..477ee718958
--- /dev/null
+++ b/spec/models/buildbox_service_spec.rb
@@ -0,0 +1,78 @@
+# == 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
+# updated_at :datetime
+# active :boolean default(FALSE), not null
+# project_url :string(255)
+# subdomain :string(255)
+# room :string(255)
+# recipients :text
+# api_key :string(255)
+#
+
+require 'spec_helper'
+
+describe BuildboxService do
+ describe 'Associations' do
+ it { should belong_to :project }
+ it { should have_one :service_hook }
+ end
+
+ describe 'commits methods' do
+ before do
+ @project = Project.new
+ @project.stub(
+ default_branch: 'default-brancho'
+ )
+
+ @service = BuildboxService.new
+ @service.stub(
+ project: @project,
+ service_hook: true,
+ project_url: 'https://buildbox.io/account-name/example-project',
+ token: 'secret-sauce-webhook-token:secret-sauce-status-token'
+ )
+ end
+
+ describe :webhook_url do
+ it 'returns the webhook url' do
+ @service.webhook_url.should ==
+ 'https://webhook.buildbox.io/deliver/secret-sauce-webhook-token'
+ end
+ end
+
+ describe :commit_status_path do
+ it 'returns the correct status page' do
+ @service.commit_status_path('2ab7834c').should ==
+ 'https://gitlab.buildbox.io/status/secret-sauce-status-token.json?commit=2ab7834c'
+ end
+ end
+
+ describe :build_page do
+ it 'returns the correct build page' do
+ @service.build_page('2ab7834c').should ==
+ 'https://buildbox.io/account-name/example-project/builds?commit=2ab7834c'
+ end
+ end
+
+ describe :builds_page do
+ it 'returns the correct path to the builds page' do
+ @service.builds_path.should ==
+ 'https://buildbox.io/account-name/example-project/builds?branch=default-brancho'
+ end
+ end
+
+ describe :status_img_path do
+ it 'returns the correct path to the status image' do
+ @service.status_img_path.should == 'https://badge.buildbox.io/secret-sauce-status-token.svg'
+ end
+ end
+ end
+end