diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-10-08 15:08:22 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-10-08 15:08:22 +0300 |
commit | 80f9b758e09f04e8b7c91a889aa1f8d16057060c (patch) | |
tree | 963bea1b599a86535bde9237ea2869a730084985 | |
parent | 17835f095fb10168d5d2f6b2fd4c136844c2bfd1 (diff) | |
parent | e1123e08f4f063d359d78e1ca94288b9dd828be5 (diff) | |
download | gitlab-ce-80f9b758e09f04e8b7c91a889aa1f8d16057060c.tar.gz |
Merge branch 'master' of github.com:gitlabhq/gitlabhq
-rw-r--r-- | app/models/project.rb | 3 | ||||
-rw-r--r-- | app/models/project_services/buildbox_service.rb | 121 | ||||
-rw-r--r-- | app/views/projects/show.html.haml | 13 | ||||
-rw-r--r-- | lib/tasks/gitlab/import.rake | 5 | ||||
-rw-r--r-- | spec/models/buildbox_service_spec.rb | 78 |
5 files changed, 213 insertions, 7 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/lib/tasks/gitlab/import.rake b/lib/tasks/gitlab/import.rake index cbfa736c84c..b6ed874e11a 100644 --- a/lib/tasks/gitlab/import.rake +++ b/lib/tasks/gitlab/import.rake @@ -27,7 +27,10 @@ namespace :gitlab do group_name = nil if group_name == '.' # Skip if group or user - next if namespaces.include?(name) + if namespaces.include?(name) + puts "Skipping #{project.name} due to namespace conflict with group or user".yellow + next + end puts "Processing #{repo_path}".yellow 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 |