Skip to content

Commit b656419

Browse files
committed
Merge branch 'move-runners-page'
2 parents d8e631c + c876bfa commit b656419

19 files changed

+123
-125
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ v 8.1.0 (unreleased)
1515
- Remove "Continuous Integration" page from dashboard
1616
- Add notes and SSL verification entries to hook APIs (Ben Boeckel)
1717
- Fix grammar in admin area "labels" .nothing-here-block when no labels exist.
18+
- Move CI runners page to project settings area
1819

1920
v 8.0.3 (unreleased)
2021

app/controllers/ci/projects_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def badge
5555

5656
def toggle_shared_runners
5757
project.toggle!(:shared_runners_enabled)
58-
redirect_to :back
58+
59+
redirect_to namespace_project_runners_path(project.gl_project.namespace, project.gl_project)
5960
end
6061

6162
def dumped_yaml

app/controllers/ci/runner_projects_controller.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ def create
1111

1212
return head(403) unless current_user.ci_authorized_runners.include?(@runner)
1313

14+
path = runners_path(@project.gl_project)
15+
1416
if @runner.assign_to(project, current_user)
15-
redirect_to ci_project_runners_path(project)
17+
redirect_to path
1618
else
17-
redirect_to ci_project_runners_path(project), alert: 'Failed adding runner to project'
19+
redirect_to path, alert: 'Failed adding runner to project'
1820
end
1921
end
2022

2123
def destroy
2224
runner_project = project.runner_projects.find(params[:id])
2325
runner_project.destroy
2426

25-
redirect_to ci_project_runners_path(project)
27+
redirect_to runners_path(@project.gl_project)
2628
end
2729

2830
private

app/controllers/ci/runners_controller.rb

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
class Projects::RunnersController < Projects::ApplicationController
2+
before_action :ci_project
3+
before_action :set_runner, only: [:edit, :update, :destroy, :pause, :resume, :show]
4+
before_action :authorize_admin_project!
5+
6+
layout 'project_settings'
7+
8+
def index
9+
@runners = @ci_project.runners.order('id DESC')
10+
@specific_runners =
11+
Ci::Runner.specific.includes(:runner_projects).
12+
where(Ci::RunnerProject.table_name => { project_id: current_user.authorized_projects } ).
13+
where.not(id: @runners).order("#{Ci::Runner.table_name}.id DESC").page(params[:page]).per(20)
14+
@shared_runners = Ci::Runner.shared.active
15+
@shared_runners_count = @shared_runners.count(:all)
16+
end
17+
18+
def edit
19+
end
20+
21+
def update
22+
if @runner.update_attributes(runner_params)
23+
redirect_to runner_path(@runner), notice: 'Runner was successfully updated.'
24+
else
25+
redirect_to runner_path(@runner), alert: 'Runner was not updated.'
26+
end
27+
end
28+
29+
def destroy
30+
if @runner.only_for?(@ci_project)
31+
@runner.destroy
32+
end
33+
34+
redirect_to runners_path(@project)
35+
end
36+
37+
def resume
38+
if @runner.update_attributes(active: true)
39+
redirect_to runner_path(@runner), notice: 'Runner was successfully updated.'
40+
else
41+
redirect_to runner_path(@runner), alert: 'Runner was not updated.'
42+
end
43+
end
44+
45+
def pause
46+
if @runner.update_attributes(active: false)
47+
redirect_to runner_path(@runner), notice: 'Runner was successfully updated.'
48+
else
49+
redirect_to runner_path(@runner), alert: 'Runner was not updated.'
50+
end
51+
end
52+
53+
def show
54+
end
55+
56+
protected
57+
58+
def ci_project
59+
@ci_project = @project.gitlab_ci_project
60+
end
61+
62+
def set_runner
63+
@runner ||= @ci_project.runners.find(params[:id])
64+
end
65+
66+
def runner_params
67+
params.require(:runner).permit(:description, :tag_list, :contacted_at, :active)
68+
end
69+
end

app/helpers/gitlab_routing_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def edit_project_path(project, *args)
3333
edit_namespace_project_path(project.namespace, project, *args)
3434
end
3535

36+
def runners_path(project, *args)
37+
namespace_project_runners_path(project.namespace, project, *args)
38+
end
39+
40+
def runner_path(runner, *args)
41+
namespace_project_runner_path(@project.namespace, @project, runner, *args)
42+
end
43+
3644
def issue_path(entity, *args)
3745
namespace_project_issue_path(entity.project.namespace, entity.project, entity, *args)
3846
end

app/models/ci/project.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def already_added?(project)
100100
def unassigned(runner)
101101
joins("LEFT JOIN #{Ci::RunnerProject.table_name} ON #{Ci::RunnerProject.table_name}.project_id = #{Ci::Project.table_name}.id " \
102102
"AND #{Ci::RunnerProject.table_name}.runner_id = #{runner.id}").
103-
where('#{Ci::RunnerProject.table_name}.project_id' => nil)
103+
where("#{Ci::RunnerProject.table_name}.project_id" => nil)
104104
end
105105

106106
def ordered_by_last_commit_date

app/views/ci/projects/show.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- if current_user && can?(current_user, :manage_project, gl_project) && [email protected]_runners?
44
.alert.alert-danger
55
Builds for this project wont be served unless you configure runners on
6-
= link_to "Runners page", ci_project_runners_path(@project)
6+
= link_to "Runners page", runners_path(@project.gl_project)
77

88
%ul.nav.nav-tabs.append-bottom-20
99
%li{class: ref_tab_class}

app/views/ci/shared/_guide.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
%ol
55
%li
66
Add at least one runner to the project.
7-
Go to #{link_to 'Runners page', ci_project_runners_path(@project), target: :blank} for instructions.
7+
Go to #{link_to 'Runners page', runners_path(@project.gl_project), target: :blank} for instructions.
88
%li
99
Put the .gitlab-ci.yml in the root of your repository. Examples can be found in #{link_to "Configuring project (.gitlab-ci.yml)", "http://doc.gitlab.com/ci/yaml/README.html", target: :blank}.
1010
You can also test your .gitlab-ci.yml in the #{link_to "Lint", ci_lint_path}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
%span
1212
Commits
1313
%span.count= @project.commits.count
14-
= nav_link path: ['runners#index', 'runners#show', 'runners#edit'] do
15-
= link_to ci_project_runners_path(@project) do
16-
= icon('cog fw')
17-
%span
18-
Runners
1914
= nav_link path: 'variables#show' do
2015
= link_to ci_project_variables_path(@project) do
2116
= icon('code fw')

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@
3434
%span
3535
Protected Branches
3636

37+
- if @project.gitlab_ci?
38+
= nav_link(controller: :runners) do
39+
= link_to namespace_project_runners_path(@project.namespace, @project), title: 'Runners', data: {placement: 'right'} do
40+
= icon('cog fw')
41+
%span
42+
Runners

app/views/ci/runners/_runner.html.haml renamed to app/views/projects/runners/_runner.html.haml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
= runner_status_icon(runner)
44
%span.monospace
55
- if @runners.include?(runner)
6-
= link_to runner.short_sha, ci_project_runner_path(@project, runner)
6+
= link_to runner.short_sha, runner_path(runner)
77
%small
8-
=link_to edit_ci_project_runner_path(@project, runner) do
8+
=link_to edit_namespace_project_runner_path(@project.namespace, @project, runner) do
99
%i.fa.fa-edit.btn
1010
- else
1111
= runner.short_sha
1212

1313
.pull-right
1414
- if @runners.include?(runner)
1515
- if runner.belongs_to_one_project?
16-
= link_to 'Remove runner', [:ci, @project, runner], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-sm'
16+
= link_to 'Remove runner', runner_path(runner), data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-sm'
1717
- else
18-
- runner_project = @project.runner_projects.find_by(runner_id: runner)
19-
= link_to 'Disable for this project', [:ci, @project, runner_project], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-sm'
18+
- runner_project = @ci_project.runner_projects.find_by(runner_id: runner)
19+
= link_to 'Disable for this project', [:ci, @ci_project, runner_project], data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-sm'
2020
- elsif runner.specific?
21-
= form_for [:ci, @project, @project.runner_projects.new] do |f|
21+
= form_for [:ci, @ci_project, @ci_project.runner_projects.new] do |f|
2222
= f.hidden_field :runner_id, value: runner.id
2323
= f.submit 'Enable for this project', class: 'btn btn-sm'
2424
.pull-right
@@ -32,4 +32,3 @@
3232
- runner.tag_list.each do |tag|
3333
%span.label.label-primary
3434
= tag
35-

app/views/ci/runners/_shared_runners.html.haml renamed to app/views/projects/runners/_shared_runners.html.haml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
.bs-callout.bs-callout-warning
44
GitLab Runners do not offer secure isolation between projects that they do builds for. You are TRUSTING all GitLab users who can push code to project A, B or C to run shell scripts on the machine hosting runner X.
55
%hr
6-
- if @project.shared_runners_enabled
7-
= link_to toggle_shared_runners_ci_project_path(@project), class: 'btn btn-warning', method: :post do
6+
- if @ci_project.shared_runners_enabled
7+
= link_to toggle_shared_runners_ci_project_path(@ci_project), class: 'btn btn-warning', method: :post do
88
Disable shared runners
99
- else
10-
= link_to toggle_shared_runners_ci_project_path(@project), class: 'btn btn-success', method: :post do
10+
= link_to toggle_shared_runners_ci_project_path(@ci_project), class: 'btn btn-success', method: :post do
1111
Enable shared runners
1212
&nbsp; for this project
1313

@@ -17,7 +17,7 @@
1717
- else
1818
%h4.underlined-title Available shared runners - #{@shared_runners_count}
1919
%ul.bordered-list.available-shared-runners
20-
= render @shared_runners.first(10)
20+
= render partial: 'runner', collection: @shared_runners, as: :runner
2121
- if @shared_runners_count > 10
2222
.light
2323
and #{@shared_runners_count - 10} more...

app/views/ci/runners/_specific_runners.html.haml renamed to app/views/projects/runners/_specific_runners.html.haml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@
1212
%code #{ci_root_url(only_path: false)}
1313
%li
1414
Use the following registration token during setup:
15-
%code #{@project.token}
15+
%code #{@ci_project.token}
1616
%li
1717
Start runner!
1818

1919

2020
- if @runners.any?
2121
%h4.underlined-title Runners activated for this project
2222
%ul.bordered-list.activated-specific-runners
23-
= render @runners
23+
= render partial: 'runner', collection: @runners, as: :runner
2424

2525
- if @specific_runners.any?
2626
%h4.underlined-title Available specific runners
2727
%ul.bordered-list.available-specific-runners
28-
= render @specific_runners
28+
= render partial: 'runner', collection: @specific_runners, as: :runner
2929
= paginate @specific_runners

app/views/ci/runners/edit.html.haml renamed to app/views/projects/runners/edit.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%h4 Runner ##{@runner.id}
22
%hr
3-
= form_for [:ci, @project, @runner], html: { class: 'form-horizontal' } do |f|
3+
= form_for @runner, url: runner_path(@runner), html: { class: 'form-horizontal' } do |f|
44
.form-group
55
= label :active, "Active", class: 'control-label'
66
.col-sm-10

config/routes.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@
5555

5656
resources :triggers, only: [:index, :create, :destroy]
5757

58-
resources :runners, only: [:index, :edit, :update, :destroy, :show] do
59-
member do
60-
get :resume
61-
get :pause
62-
end
63-
end
64-
6558
resources :runner_projects, only: [:create, :destroy]
6659

6760
resources :events, only: [:index]
@@ -653,8 +646,14 @@
653646
get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
654647
end
655648
end
656-
end
657649

650+
resources :runners, only: [:index, :edit, :update, :destroy, :show] do
651+
member do
652+
get :resume
653+
get :pause
654+
end
655+
end
656+
end
658657
end
659658
end
660659

0 commit comments

Comments
 (0)