Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-19 01:15:49 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-09-19 01:15:49 +0300
commit442db0801aea1f11163e7e128da6cbcf2823c5cd (patch)
tree95f63e0438dcb3a157d72d4382662a22c73a5cb5 /app
parent6776dcf90b9e101b8c9341ea83621e48f87584d6 (diff)
parent5a8d73243a7b68f2724a6d5f9d482dda24e9dfe4 (diff)
Merge branch 'master' into ci-build-list
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/issuable_context.js.coffee9
-rw-r--r--app/controllers/admin/application_settings_controller.rb1
-rw-r--r--app/controllers/ci/application_controller.rb9
-rw-r--r--app/controllers/ci/projects_controller.rb20
-rw-r--r--app/models/application_setting.rb3
-rw-r--r--app/models/ci/project.rb15
-rw-r--r--app/models/project_services/buildkite_service.rb8
-rw-r--r--app/models/project_services/drone_ci_service.rb14
-rw-r--r--app/models/project_services/gitlab_ci_service.rb86
-rw-r--r--app/services/ci/create_project_service.rb9
-rw-r--r--app/services/projects/fork_service.rb2
-rw-r--r--app/views/admin/application_settings/_form.html.haml9
-rw-r--r--app/views/ci/projects/disabled.html.haml1
-rw-r--r--app/views/layouts/ci/application.html.haml2
-rw-r--r--app/views/layouts/nav/_dashboard.html.haml2
-rw-r--r--app/workers/fork_registration_worker.rb12
16 files changed, 61 insertions, 141 deletions
diff --git a/app/assets/javascripts/issuable_context.js.coffee b/app/assets/javascripts/issuable_context.js.coffee
index 176d9cabefa..c4d3e619f5e 100644
--- a/app/assets/javascripts/issuable_context.js.coffee
+++ b/app/assets/javascripts/issuable_context.js.coffee
@@ -11,12 +11,13 @@ class @IssuableContext
$(this).submit()
$('.issuable-details').waitForImages ->
+ $('.issuable-affix').on 'affix.bs.affix', ->
+ $(@).width($(@).outerWidth())
+ .on 'affixed-top.bs.affix affixed-bottom.bs.affix', ->
+ $(@).width('')
+
$('.issuable-affix').affix offset:
top: ->
@top = ($('.issuable-affix').offset().top - 70)
bottom: ->
@bottom = $('.footer').outerHeight(true)
- $('.issuable-affix').on 'affix.bs.affix', ->
- $(@).width($(@).outerWidth())
- .on 'affixed-top.bs.affix affixed-bottom.bs.affix', ->
- $(@).width('')
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb
index 7c134d2ec9b..5f70582cbb7 100644
--- a/app/controllers/admin/application_settings_controller.rb
+++ b/app/controllers/admin/application_settings_controller.rb
@@ -56,6 +56,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:restricted_signup_domains_raw,
:version_check_enabled,
:user_oauth_applications,
+ :ci_enabled,
restricted_visibility_levels: [],
import_sources: []
)
diff --git a/app/controllers/ci/application_controller.rb b/app/controllers/ci/application_controller.rb
index d45c4e9caf1..8d8ff75ff72 100644
--- a/app/controllers/ci/application_controller.rb
+++ b/app/controllers/ci/application_controller.rb
@@ -1,5 +1,7 @@
module Ci
class ApplicationController < ::ApplicationController
+ before_action :check_enable_flag!
+
def self.railtie_helpers_paths
"app/helpers/ci"
end
@@ -8,6 +10,13 @@ module Ci
private
+ def check_enable_flag!
+ unless current_application_settings.ci_enabled
+ redirect_to(disabled_ci_projects_path)
+ return
+ end
+ end
+
def authenticate_public_page!
unless project.public
authenticate_user!
diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb
index 653384b7178..40b61edb0a9 100644
--- a/app/controllers/ci/projects_controller.rb
+++ b/app/controllers/ci/projects_controller.rb
@@ -5,13 +5,17 @@ module Ci
before_action :authenticate_user!, except: [:build, :badge, :index, :show]
before_action :authenticate_public_page!, only: :show
before_action :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
- before_action :authorize_access_project!, except: [:build, :badge, :index, :show, :new, :create]
+ before_action :authorize_access_project!, except: [:build, :badge, :index, :show, :new, :create, :disabled]
before_action :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
before_action :authenticate_token!, only: [:build]
before_action :no_cache, only: [:badge]
+ skip_before_action :check_enable_flag!, only: [:disabled]
protect_from_forgery except: :build
- layout 'ci/project', except: :index
+ layout 'ci/project', except: [:index, :disabled]
+
+ def disabled
+ end
def index
@limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i
@@ -51,7 +55,7 @@ module Ci
return redirect_to ci_root_path, alert: 'You have to have at least master role to enable CI for this project'
end
- @project = Ci::CreateProjectService.new.execute(current_user, project_data, ci_project_url(":project_id"))
+ @project = Ci::CreateProjectService.new.execute(current_user, project_data)
if @project.persisted?
redirect_to ci_project_path(@project, show_guide: true), notice: 'Project was successfully created.'
@@ -82,16 +86,6 @@ module Ci
redirect_to ci_projects_url
end
- def build
- @commit = Ci::CreateCommitService.new.execute(@project, params.dup)
-
- if @commit && @commit.valid?
- head 201
- else
- head 400
- end
- end
-
# Project status badge
# Image with build status for sha or ref
def badge
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index c8841178e93..784f5c96a0a 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -83,7 +83,8 @@ class ApplicationSetting < ActiveRecord::Base
default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'],
default_snippet_visibility: Settings.gitlab.default_projects_features['visibility_level'],
restricted_signup_domains: Settings.gitlab['restricted_signup_domains'],
- import_sources: ['github','bitbucket','gitlab','gitorious','google_code','fogbugz','git']
+ import_sources: ['github','bitbucket','gitlab','gitorious','google_code','fogbugz','git'],
+ ci_enabled: Settings.gitlab_ci['enabled']
)
end
diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb
index ae901d4ccd0..37fbcc287bb 100644
--- a/app/models/ci/project.rb
+++ b/app/models/ci/project.rb
@@ -92,21 +92,6 @@ module Ci
project
end
- # TODO: remove
- def from_gitlab(user, scope = :owned, options)
- opts = user.authenticate_options
- opts.merge! options
-
- raise 'Implement me of fix'
- #projects = Ci::Network.new.projects(opts.compact, scope)
-
- if projects
- projects.map { |pr| OpenStruct.new(pr) }
- else
- []
- end
- end
-
def already_added?(project)
where(gitlab_id: project.id).any?
end
diff --git a/app/models/project_services/buildkite_service.rb b/app/models/project_services/buildkite_service.rb
index 9e5da6f45d2..40058b53df5 100644
--- a/app/models/project_services/buildkite_service.rb
+++ b/app/models/project_services/buildkite_service.rb
@@ -69,14 +69,6 @@ class BuildkiteService < CiService
"#{project_url}/builds?commit=#{sha}"
end
- def builds_path
- "#{project_url}/builds?branch=#{project.default_branch}"
- end
-
- def status_img_path
- "#{buildkite_endpoint('badge')}/#{status_token}.svg"
- end
-
def title
'Buildkite'
end
diff --git a/app/models/project_services/drone_ci_service.rb b/app/models/project_services/drone_ci_service.rb
index 3e2b7faecdb..b13fa3e9ecb 100644
--- a/app/models/project_services/drone_ci_service.rb
+++ b/app/models/project_services/drone_ci_service.rb
@@ -135,20 +135,6 @@ class DroneCiService < CiService
commit_page(sha, ref)
end
- def builds_path
- url = [drone_url, "#{project.namespace.path}/#{project.path}"]
-
- URI.join(*url).to_s
- end
-
- def status_img_path
- url = [drone_url,
- "api/badges/#{project.namespace.path}/#{project.path}/status.svg",
- "?branch=#{URI::encode(project.default_branch)}"]
-
- URI.join(*url).to_s
- end
-
def title
'Drone CI'
end
diff --git a/app/models/project_services/gitlab_ci_service.rb b/app/models/project_services/gitlab_ci_service.rb
index acbbc9935b6..820dd3f567c 100644
--- a/app/models/project_services/gitlab_ci_service.rb
+++ b/app/models/project_services/gitlab_ci_service.rb
@@ -19,22 +19,12 @@
#
class GitlabCiService < CiService
- API_PREFIX = "api/v1"
-
- prop_accessor :project_url, :token, :enable_ssl_verification
- validates :project_url,
- presence: true,
- format: { with: /\A#{URI.regexp(%w(http https))}\z/, message: "should be a valid url" }, if: :activated?
- validates :token,
- presence: true,
- format: { with: /\A([A-Za-z0-9]+)\z/ }, if: :activated?
+ prop_accessor :token
after_save :compose_service_hook, if: :activated?
def compose_service_hook
hook = service_hook || build_service_hook
- hook.url = [project_url, "/build", "?token=#{token}"].join("")
- hook.enable_ssl_verification = enable_ssl_verification
hook.save
end
@@ -55,71 +45,47 @@ class GitlabCiService < CiService
end
end
- service_hook.execute(data)
- end
-
- def commit_status_path(sha, ref)
- URI::encode(project_url + "/refs/#{ref}/commits/#{sha}/status.json?token=#{token}")
+ ci_project = Ci::Project.find_by(gitlab_id: project.id)
+ Ci::CreateCommitService.new.execute(ci_project, data)
end
- def get_ci_build(sha, ref)
- @ci_builds ||= {}
- @ci_builds[sha] ||= HTTParty.get(commit_status_path(sha, ref), verify: false)
+ def get_ci_commit(sha, ref)
+ Ci::Project.find(project.gitlab_ci_project).commits.find_by_sha_and_ref!(sha, ref)
end
def commit_status(sha, ref)
- response = get_ci_build(sha, ref)
-
- if response.code == 200 and response["status"]
- response["status"]
- else
- :error
- end
- rescue Errno::ECONNREFUSED
+ get_ci_commit(sha, ref).status
+ rescue ActiveRecord::RecordNotFound
:error
end
- def fork_registration(new_project, private_token)
- params = {
+ def fork_registration(new_project, current_user)
+ params = OpenStruct.new({
id: new_project.id,
name_with_namespace: new_project.name_with_namespace,
path_with_namespace: new_project.path_with_namespace,
web_url: new_project.web_url,
default_branch: new_project.default_branch,
ssh_url_to_repo: new_project.ssh_url_to_repo
- }
-
- HTTParty.post(
- fork_registration_path,
- body: {
- project_id: project.id,
- project_token: token,
- private_token: private_token,
- data: params },
- verify: false
+ })
+
+ ci_project = Ci::Project.find_by!(gitlab_id: project.id)
+
+ Ci::CreateProjectService.new.execute(
+ current_user,
+ params,
+ ci_project
)
end
def commit_coverage(sha, ref)
- response = get_ci_build(sha, ref)
-
- if response.code == 200 and response["coverage"]
- response["coverage"]
- end
- rescue Errno::ECONNREFUSED
- nil
+ get_ci_commit(sha, ref).coverage
+ rescue ActiveRecord::RecordNotFound
+ :error
end
def build_page(sha, ref)
- URI::encode(project_url + "/refs/#{ref}/commits/#{sha}")
- end
-
- def builds_path
- project_url + "?ref=" + project.default_branch
- end
-
- def status_img_path
- project_url + "/status.png?ref=" + project.default_branch
+ Ci::RoutesHelper.ci_project_ref_commits_path(project.gitlab_ci_project, ref, sha)
end
def title
@@ -135,11 +101,7 @@ class GitlabCiService < CiService
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' },
- { type: 'checkbox', name: 'enable_ssl_verification', title: "Enable SSL verification" }
- ]
+ []
end
private
@@ -148,10 +110,6 @@ class GitlabCiService < CiService
repository.blob_at(sha, '.gitlab-ci.yml')
end
- def fork_registration_path
- project_url.sub(/projects\/\d*/, "#{API_PREFIX}/forks")
- end
-
def repository
project.repository
end
diff --git a/app/services/ci/create_project_service.rb b/app/services/ci/create_project_service.rb
index 0419612d521..839d3f6b444 100644
--- a/app/services/ci/create_project_service.rb
+++ b/app/services/ci/create_project_service.rb
@@ -2,20 +2,15 @@ module Ci
class CreateProjectService
include Gitlab::Application.routes.url_helpers
- def execute(current_user, params, project_route, forked_project = nil)
+ def execute(current_user, params, forked_project = nil)
@project = Ci::Project.parse(params)
Ci::Project.transaction do
@project.save!
- data = {
- token: @project.token,
- project_url: project_route.gsub(":project_id", @project.id.to_s),
- }
-
gl_project = ::Project.find(@project.gitlab_id)
gl_project.build_missing_services
- gl_project.gitlab_ci_service.update_attributes(data.merge(active: true))
+ gl_project.gitlab_ci_service.update_attributes(active: true, token: @project.token)
end
if forked_project
diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb
index 50f208b11d1..2e995d6fd51 100644
--- a/app/services/projects/fork_service.rb
+++ b/app/services/projects/fork_service.rb
@@ -18,7 +18,7 @@ module Projects
if new_project.persisted?
if @project.gitlab_ci?
- ForkRegistrationWorker.perform_async(@project.id, new_project.id, @current_user.private_token)
+ @project.gitlab_ci_service.fork_registration(new_project, @current_user)
end
end
diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml
index a36ae0b766c..1476e29524c 100644
--- a/app/views/admin/application_settings/_form.html.haml
+++ b/app/views/admin/application_settings/_form.html.haml
@@ -124,5 +124,14 @@
= f.text_area :help_page_text, class: 'form-control', rows: 4
.help-block Markdown enabled
+ %fieldset
+ %legend Continuous Integration
+ .form-group
+ .col-sm-offset-2.col-sm-10
+ .checkbox
+ = f.label :ci_enabled do
+ = f.check_box :ci_enabled
+ Enable Continuous Integration
+
.form-actions
= f.submit 'Save', class: 'btn btn-primary'
diff --git a/app/views/ci/projects/disabled.html.haml b/app/views/ci/projects/disabled.html.haml
new file mode 100644
index 00000000000..95276d894ed
--- /dev/null
+++ b/app/views/ci/projects/disabled.html.haml
@@ -0,0 +1 @@
+Continuous Integration has been disabled. Please ask your administrator to enable it.
diff --git a/app/views/layouts/ci/application.html.haml b/app/views/layouts/ci/application.html.haml
index 9cc7fb85142..38023468d0b 100644
--- a/app/views/layouts/ci/application.html.haml
+++ b/app/views/layouts/ci/application.html.haml
@@ -2,7 +2,7 @@
%html{ lang: "en"}
= render 'layouts/head'
%body{class: "ci-body #{user_application_theme}", 'data-page' => body_data_page}
- - header_title = "CI Projects"
+ - header_title = "Continuous Integration"
- if current_user
= render "layouts/header/default", title: header_title
- else
diff --git a/app/views/layouts/nav/_dashboard.html.haml b/app/views/layouts/nav/_dashboard.html.haml
index 3bda7c46959..b94165aac39 100644
--- a/app/views/layouts/nav/_dashboard.html.haml
+++ b/app/views/layouts/nav/_dashboard.html.haml
@@ -31,7 +31,7 @@
%span
Merge Requests
%span.count= current_user.assigned_merge_requests.opened.count
- = nav_link(path: 'ci/projects#index') do
+ = nav_link(path: ['ci/projects#index', 'ci/projects#disabled']) do
= link_to ci_projects_path, title: 'Continuous Integration', data: {placement: 'right'} do
= icon('building fw')
%span
diff --git a/app/workers/fork_registration_worker.rb b/app/workers/fork_registration_worker.rb
deleted file mode 100644
index fffa8b3a659..00000000000
--- a/app/workers/fork_registration_worker.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-class ForkRegistrationWorker
- include Sidekiq::Worker
-
- sidekiq_options queue: :default
-
- def perform(from_project_id, to_project_id, private_token)
- from_project = Project.find(from_project_id)
- to_project = Project.find(to_project_id)
-
- from_project.gitlab_ci_service.fork_registration(to_project, private_token)
- end
-end