diff options
author | Keith Pitt <me@keithpitt.com> | 2014-08-18 14:54:51 +0400 |
---|---|---|
committer | Keith Pitt <me@keithpitt.com> | 2014-10-08 12:30:04 +0400 |
commit | 76594d474ca6d04c2e608e7b3df1229729288f14 (patch) | |
tree | 3438cd037ccc816762acaedd547dbf9b0a598b53 /app | |
parent | 06fd4bf7e18bd3f3e4805eee332c6bd485760e42 (diff) |
Added support for Buildbox
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project.rb | 4 | ||||
-rw-r--r-- | app/models/project_services/buildbox_service.rb | 121 | ||||
-rw-r--r-- | app/views/projects/show.html.haml | 10 |
3 files changed, 128 insertions, 7 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index f9278f19dad..99728cff9fb 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 :forked_project_link, dependent: :destroy, foreign_key: "forked_to_project_id" has_one :forked_from_project, through: :forked_project_link # Merge Requests for target project should be removed with it @@ -311,7 +312,8 @@ class Project < ActiveRecord::Base end def available_services_names - %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla emails_on_push gemnasium slack) + %w(gitlab_ci campfire hipchat pivotaltracker flowdock assembla + emails_on_push gemnasium slack 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 19bef02b51f..9239fb74e03 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -62,11 +62,10 @@ - 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) + = link_to ci_service.builds_path do + = image_tag ci_service.status_img_path, alt: "build status" - if readme .tab-pane#tab-readme @@ -77,4 +76,3 @@ = readme.name .wiki = render_readme(readme) - |