Skip to content

Commit 34431d8

Browse files
committed
Merge branch 'move-ci-settings' into 'master'
Move CI project settings page to CE project settings area Signed-off-by: Dmitriy Zaporozhets <[email protected]> Part of gitlabhq#2594 See merge request !1465
2 parents 2e8a3e3 + 87240e9 commit 34431d8

File tree

12 files changed

+86
-71
lines changed

12 files changed

+86
-71
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ v 8.1.0 (unreleased)
1616
- Move CI runners page to project settings area
1717
- Move CI variables page to project settings area
1818
- Move CI triggers page to project settings area
19+
- Move CI project settings page to CE project settings area
1920

2021
v 8.0.3
2122
- Fix URL shown in Slack notifications

app/controllers/ci/projects_controller.rb

+2-31
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module Ci
22
class ProjectsController < Ci::ApplicationController
33
before_action :authenticate_user!, except: [:build, :badge, :show]
44
before_action :authenticate_public_page!, only: :show
5-
before_action :project, only: [:build, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
5+
before_action :project, only: [:build, :show, :badge, :toggle_shared_runners, :dumped_yaml]
66
before_action :authorize_access_project!, except: [:build, :badge, :show, :new, :disabled]
7-
before_action :authorize_manage_project!, only: [:edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml]
7+
before_action :authorize_manage_project!, only: [:toggle_shared_runners, :dumped_yaml]
88
before_action :authenticate_token!, only: [:build]
99
before_action :no_cache, only: [:badge]
1010
skip_before_action :check_enable_flag!, only: [:disabled]
@@ -23,28 +23,6 @@ def show
2323
@commits = @commits.page(params[:page]).per(20)
2424
end
2525

26-
def edit
27-
end
28-
29-
def update
30-
if project.update_attributes(project_params)
31-
Ci::EventService.new.change_project_settings(current_user, project)
32-
33-
redirect_to :back, notice: 'Project was successfully updated.'
34-
else
35-
render action: "edit"
36-
end
37-
end
38-
39-
def destroy
40-
project.gl_project.gitlab_ci_service.update_attributes(active: false)
41-
project.destroy
42-
43-
Ci::EventService.new.remove_project(current_user, project)
44-
45-
redirect_to ci_projects_url
46-
end
47-
4826
# Project status badge
4927
# Image with build status for sha or ref
5028
def badge
@@ -74,12 +52,5 @@ def no_cache
7452
response.headers["Pragma"] = "no-cache"
7553
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
7654
end
77-
78-
def project_params
79-
params.require(:project).permit(:path, :timeout, :timeout_in_minutes, :default_ref, :always_build,
80-
:polling_interval, :public, :ssh_url_to_repo, :allow_git_fetch, :email_recipients,
81-
:email_add_pusher, :email_only_broken_builds, :coverage_regex, :shared_runners_enabled, :token,
82-
{ variables_attributes: [:id, :key, :value, :_destroy] })
83-
end
8455
end
8556
end

app/controllers/projects/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ def ci_enabled
3333
end
3434

3535
def ci_project
36-
@ci_project ||= @project.gitlab_ci_project
36+
@ci_project ||= @project.ensure_gitlab_ci_project
3737
end
3838
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Projects::CiSettingsController < Projects::ApplicationController
2+
before_action :ci_project
3+
before_action :authorize_admin_project!
4+
5+
layout "project_settings"
6+
7+
def edit
8+
end
9+
10+
def update
11+
if ci_project.update_attributes(project_params)
12+
Ci::EventService.new.change_project_settings(current_user, ci_project)
13+
14+
redirect_to edit_namespace_project_ci_settings_path(project.namespace, project), notice: 'Project was successfully updated.'
15+
else
16+
render action: "edit"
17+
end
18+
end
19+
20+
def destroy
21+
ci_project.destroy
22+
Ci::EventService.new.remove_project(current_user, ci_project)
23+
project.gitlab_ci_service.update_attributes(active: false)
24+
25+
redirect_to project_path(project), notice: "CI was disabled for this project"
26+
end
27+
28+
protected
29+
30+
def project_params
31+
params.require(:project).permit(:path, :timeout, :timeout_in_minutes, :default_ref, :always_build,
32+
:polling_interval, :public, :ssh_url_to_repo, :allow_git_fetch, :email_recipients,
33+
:email_add_pusher, :email_only_broken_builds, :coverage_regex, :shared_runners_enabled, :token,
34+
{ variables_attributes: [:id, :key, :value, :_destroy] })
35+
end
36+
end

app/helpers/ci/gitlab_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def yaml_web_editor_link(project)
2727
commits = project.commits
2828

2929
if commits.any? && commits.last.push_data[:ci_yaml_file]
30-
"#{@project.gitlab_url}/edit/master/.gitlab-ci.yml"
30+
"#{project.gitlab_url}/edit/master/.gitlab-ci.yml"
3131
else
32-
"#{@project.gitlab_url}/new/master"
32+
"#{project.gitlab_url}/new/master"
3333
end
3434
end
3535
end

app/views/layouts/ci/_nav_project.html.haml

-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,3 @@
2626
= icon('book fw')
2727
%span
2828
Events
29-
%li.separate-item
30-
= nav_link path: 'projects#edit' do
31-
= link_to edit_ci_project_path(@project) do
32-
= icon('cogs fw')
33-
%span
34-
Settings

app/views/layouts/nav/_project_settings.html.haml

+5
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@
5050
= icon('retweet fw')
5151
%span
5252
Triggers
53+
= nav_link path: 'ci_settings#edit' do
54+
= link_to edit_namespace_project_ci_settings_path(@project.namespace, @project) do
55+
= icon('building fw')
56+
%span
57+
CI Settings

app/views/ci/projects/_form.html.haml renamed to app/views/projects/ci_settings/_form.html.haml

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
%h3.page-title
2+
CI settings
3+
%hr
14
.bs-callout.help-callout
25
%p
36
If you want to test your .gitlab-ci.yml, you can use special tool - #{link_to "Lint", ci_lint_path}
47
%p
5-
Edit your
6-
#{link_to ".gitlab-ci.yml using web-editor", yaml_web_editor_link(@project)}
8+
Edit your
9+
#{link_to ".gitlab-ci.yml using web-editor", yaml_web_editor_link(@ci_project)}
710

8-
= nested_form_for [:ci, @project], html: { class: 'form-horizontal' } do |f|
9-
- if @project.errors.any?
11+
= nested_form_for @ci_project, url: namespace_project_ci_settings_path(@project.namespace, @project), html: { class: 'form-horizontal' } do |f|
12+
- if @ci_project.errors.any?
1013
#error_explanation
11-
%p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:"
14+
%p.lead= "#{pluralize(@ci_project.errors.count, "error")} prohibited this project from being saved:"
1215
.alert.alert-error
1316
%ul
14-
- @project.errors.full_messages.each do |msg|
17+
- @ci_project.errors.full_messages.each do |msg|
1518
%li= msg
1619

1720
%fieldset
@@ -93,8 +96,8 @@
9396
= f.label :token, "CI token", class: 'control-label'
9497
.col-sm-10
9598
= f.text_field :token, class: 'form-control', placeholder: 'xEeFCaDAB89'
96-
99+
97100
.form-actions
98101
= f.submit 'Save changes', class: 'btn btn-save'
99-
- unless @project.new_record?
100-
= link_to 'Remove Project', ci_project_path(@project), method: :delete, data: { confirm: 'Project will be removed. Are you sure?' }, class: 'btn btn-danger pull-right'
102+
- unless @ci_project.new_record?
103+
= link_to 'Remove Project', ci_project_path(@ci_project), method: :delete, data: { confirm: 'Project will be removed. Are you sure?' }, class: 'btn btn-danger pull-right'
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
- if @project.generated_yaml_config
1+
- if @ci_project.generated_yaml_config
22
%p.alert.alert-danger
3-
CI Jobs are deprecated now, you can #{link_to "download", dumped_yaml_ci_project_path(@project)}
3+
CI Jobs are deprecated now, you can #{link_to "download", dumped_yaml_ci_project_path(@ci_project)}
44
or
55
%a.preview-yml{:href => "#yaml-content", "data-toggle" => "modal"} preview
66
yaml file which is based on your old jobs.
77
Put this file to the root of your project and name it .gitlab-ci.yml
88

99
= render 'form'
1010

11-
- if @project.generated_yaml_config
11+
- if @ci_project.generated_yaml_config
1212
#yaml-content.modal.fade{"aria-hidden" => "true", "aria-labelledby" => ".gitlab-ci.yml", :role => "dialog", :tabindex => "-1"}
1313
.modal-dialog
1414
.modal-content
1515
.modal-header
1616
%button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
1717
%h4.modal-title Content of .gitlab-ci.yml
1818
.modal-body
19-
= text_area_tag :yaml, @project.generated_yaml_config, size: "70x25", class: "form-control"
19+
= text_area_tag :yaml, @ci_project.generated_yaml_config, size: "70x25", class: "form-control"
2020
.modal-footer
2121
%button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Close

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@
590590
resources :protected_branches, only: [:index, :create, :update, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }
591591
resource :variables, only: [:show, :update]
592592
resources :triggers, only: [:index, :create, :destroy]
593+
resource :ci_settings, only: [:edit, :update, :destroy]
593594

594595
resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
595596
member do

spec/features/ci/projects_spec.rb

-18
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,4 @@
1717
it { expect(page).to have_content @project.name }
1818
it { expect(page).to have_content 'All commits' }
1919
end
20-
21-
describe "GET /ci/projects/:id/edit" do
22-
before do
23-
visit edit_ci_project_path(@project)
24-
end
25-
26-
it { expect(page).to have_content @project.name }
27-
it { expect(page).to have_content 'Build Schedule' }
28-
29-
it "updates configuration" do
30-
fill_in 'Timeout', with: '70'
31-
click_button 'Save changes'
32-
33-
expect(page).to have_content 'was successfully updated'
34-
35-
expect(find_field('Timeout').value).to eq '70'
36-
end
37-
end
3820
end

spec/features/ci_settings_spec.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'spec_helper'
2+
3+
describe "CI settings" do
4+
let(:user) { create(:user) }
5+
before { login_as(user) }
6+
7+
before do
8+
@project = FactoryGirl.create :ci_project
9+
@gl_project = @project.gl_project
10+
@gl_project.team << [user, :master]
11+
visit edit_namespace_project_ci_settings_path(@gl_project.namespace, @gl_project)
12+
end
13+
14+
it { expect(page).to have_content 'Build Schedule' }
15+
16+
it "updates configuration" do
17+
fill_in 'Timeout', with: '70'
18+
click_button 'Save changes'
19+
expect(page).to have_content 'was successfully updated'
20+
expect(find_field('Timeout').value).to eq '70'
21+
end
22+
end

0 commit comments

Comments
 (0)