diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-07-19 23:26:13 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-07-19 23:26:13 +0200 |
commit | 4a74798a7ba16fec37f634d0eaf52b838213e090 (patch) | |
tree | e92a68f1b516a118d01f1e9cb61d90ccb86a3f80 | |
parent | 22be5aed1d6db526bd945f9492b806c29969676d (diff) | |
download | gitlab-ce-4a74798a7ba16fec37f634d0eaf52b838213e090.tar.gz |
Move Pipelines settings under `gitlab.com/gitlab-org/gitlab-ce/pipelines/settings`
-rw-r--r-- | app/controllers/projects/builds_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/projects/pipelines_controller.rb | 33 | ||||
-rw-r--r-- | app/controllers/projects/refs_controller.rb | 2 | ||||
-rw-r--r-- | app/services/projects/update_service.rb | 1 | ||||
-rw-r--r-- | app/views/layouts/nav/_project_settings.html.haml | 4 | ||||
-rw-r--r-- | app/views/projects/pipelines/settings.html.haml (renamed from app/views/projects/builds/settings.html.haml) | 2 | ||||
-rw-r--r-- | config/routes.rb | 6 | ||||
-rw-r--r-- | spec/features/pipelines_spec.rb | 31 | ||||
-rw-r--r-- | spec/features/projects/badges/list_spec.rb | 2 |
9 files changed, 73 insertions, 15 deletions
diff --git a/app/controllers/projects/builds_controller.rb b/app/controllers/projects/builds_controller.rb index b03a37d8148..d7513d75f01 100644 --- a/app/controllers/projects/builds_controller.rb +++ b/app/controllers/projects/builds_controller.rb @@ -1,5 +1,5 @@ class Projects::BuildsController < Projects::ApplicationController - before_action :build, except: [:index, :cancel_all, :settings] + before_action :build, except: [:index, :cancel_all] before_action :authorize_read_build!, except: [:cancel, :cancel_all, :retry] before_action :authorize_update_build!, except: [:index, :show, :status, :raw] layout 'project' @@ -27,11 +27,6 @@ class Projects::BuildsController < Projects::ApplicationController redirect_to namespace_project_builds_path(project.namespace, project) end - def settings - @ref = params[:ref] || @project.default_branch || 'master' - @build_badge = Gitlab::Badge::Build.new(@project, @ref) - end - def show @builds = @project.pipelines.find_by_sha(@build.sha).builds.order('id DESC') @builds = @builds.where("id not in (?)", @build.id) diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index 487963fdcd7..990adb15133 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -1,9 +1,10 @@ class Projects::PipelinesController < Projects::ApplicationController - before_action :pipeline, except: [:index, :new, :create] + before_action :pipeline, except: [:index, :new, :create, :settings, :update_settings] before_action :commit, only: [:show] before_action :authorize_read_pipeline! before_action :authorize_create_pipeline!, only: [:new, :create] before_action :authorize_update_pipeline!, only: [:retry, :cancel] + before_action :authorize_admin_pipeline!, only: [:settings, :update_settings] def index @scope = params[:scope] @@ -43,12 +44,42 @@ class Projects::PipelinesController < Projects::ApplicationController redirect_back_or_default default: namespace_project_pipelines_path(project.namespace, project) end + def settings + @ref = params[:ref] || @project.default_branch || 'master' + @build_badge = Gitlab::Badge::Build.new(@project, @ref) + end + + def update_settings + status = ::Projects::UpdateService.new(@project, current_user, pipelines_settings_params).execute + + respond_to do |format| + if status + flash[:notice] = "CI/CD Pipelines settings for '#{@project.name}' was successfully updated." + format.html do + redirect_to( + settings_namespace_project_pipelines_path(@project.namespace, @project), + notice: "CI/CD Pipelines settings for '#{@project.name}' was successfully updated." + ) + end + else + format.html { render 'settings' } + end + end + end + private def create_params params.require(:pipeline).permit(:ref) end + def pipelines_settings_params + params.require(:project).permit( + :runners_token, :builds_enabled, :build_allow_git_fetch, :build_timeout_in_minutes, :build_coverage_regex, + :public_builds + ) + end + def pipeline @pipeline ||= project.pipelines.find_by!(id: params[:id]) end diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb index 3b08573ca99..08d74634315 100644 --- a/app/controllers/projects/refs_controller.rb +++ b/app/controllers/projects/refs_controller.rb @@ -25,7 +25,7 @@ class Projects::RefsController < Projects::ApplicationController when "graphs_commits" commits_namespace_project_graph_path(@project.namespace, @project, @id) when "badges" - settings_namespace_project_builds_path(@project.namespace, @project, ref: @id) + settings_namespace_project_pipelines_path(@project.namespace, @project, ref: @id) else namespace_project_commits_path(@project.namespace, @project, @id) end diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb index f06311511cc..47dbc214968 100644 --- a/app/services/projects/update_service.rb +++ b/app/services/projects/update_service.rb @@ -23,6 +23,7 @@ module Projects if project.previous_changes.include?('path') project.rename_repo end + true end end end diff --git a/app/views/layouts/nav/_project_settings.html.haml b/app/views/layouts/nav/_project_settings.html.haml index 1522fd2f9fb..ca7b502eb5a 100644 --- a/app/views/layouts/nav/_project_settings.html.haml +++ b/app/views/layouts/nav/_project_settings.html.haml @@ -39,7 +39,7 @@ = link_to namespace_project_triggers_path(@project.namespace, @project), title: 'Triggers' do %span Triggers - = nav_link(controller: :builds) do - = link_to settings_namespace_project_builds_path(@project.namespace, @project), title: 'CI/CD Pipelines' do + = nav_link(controller: :pipelines) do + = link_to settings_namespace_project_pipelines_path(@project.namespace, @project), title: 'CI/CD Pipelines' do %span CI/CD Pipelines diff --git a/app/views/projects/builds/settings.html.haml b/app/views/projects/pipelines/settings.html.haml index 820fb74fd51..8c90defc2be 100644 --- a/app/views/projects/builds/settings.html.haml +++ b/app/views/projects/pipelines/settings.html.haml @@ -7,7 +7,7 @@ .col-lg-9 %h5.prepend-top-0 Pipelines - = form_for [@project.namespace.becomes(Namespace), @project], remote: true, authenticity_token: true do |f| + = form_for @project, url: settings_namespace_project_pipelines_path(@project.namespace.becomes(Namespace), @project), remote: true, authenticity_token: true do |f| %fieldset.builds-feature - unless @repository.gitlab_ci_yml .form-group diff --git a/config/routes.rb b/config/routes.rb index d09c021dac7..70cbc99d614 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -733,6 +733,11 @@ Rails.application.routes.draw do resources :triggers, only: [:index, :create, :destroy] resources :pipelines, only: [:index, :new, :create, :show] do + collection do + get :settings + patch :settings, to: 'pipelines#update_settings' + end + member do post :cancel post :retry @@ -744,7 +749,6 @@ Rails.application.routes.draw do resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do collection do post :cancel_all - get :settings end member do diff --git a/spec/features/pipelines_spec.rb b/spec/features/pipelines_spec.rb index e7ee0aaea3c..01fa6394217 100644 --- a/spec/features/pipelines_spec.rb +++ b/spec/features/pipelines_spec.rb @@ -1,14 +1,15 @@ require 'spec_helper' -describe "Pipelines" do +feature "Pipelines", feature: true do include GitlabRoutingHelper let(:project) { create(:empty_project) } let(:user) { create(:user) } + let(:role) { :developer } before do login_as(user) - project.team << [user, :developer] + project.team << [user, role] end describe 'GET /:project/pipelines' do @@ -186,4 +187,30 @@ describe "Pipelines" do it { expect(page).to have_content('Reference not found') } end end + + describe 'Pipelines settings' do + background do + visit settings_namespace_project_pipelines_path(project.namespace, project) + end + + context 'for developer' do + given(:role) { :developer } + + scenario 'to be disallowed to view' do + expect(page.status_code).to eq(404) + end + end + + context 'for master' do + given(:role) { :master } + + scenario 'be allowed to change' do + fill_in('Test coverage parsing', with: 'coverage_regex') + click_on 'Save changes' + + expect(page.status_code).to eq(200) + expect(page).to have_field('Test coverage parsing', with: 'coverage_regex') + end + end + end end diff --git a/spec/features/projects/badges/list_spec.rb b/spec/features/projects/badges/list_spec.rb index e5e900b5202..d29fb265f91 100644 --- a/spec/features/projects/badges/list_spec.rb +++ b/spec/features/projects/badges/list_spec.rb @@ -6,7 +6,7 @@ feature 'list of badges' do project = create(:project) project.team << [user, :master] login_as(user) - visit settings_namespace_project_builds_path(project.namespace, project) + visit settings_namespace_project_pipelines_path(project.namespace, project) end scenario 'user displays list of badges' do |