diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-05 20:58:26 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-07-05 20:58:26 +0300 |
commit | bfbf443afb3b33e4c679dc8c7d21a51a0767f2bf (patch) | |
tree | 4f1a1b90a33a49d5c369c4f12b173db230e35539 | |
parent | 2af7985d5d0399c0299eafcac3e4ce8a6f2ac342 (diff) | |
download | gitlab-ci-bfbf443afb3b33e4c679dc8c7d21a51a0767f2bf.tar.gz |
Add ability to assign runner to all projects. add ability to edit runner description
-rw-r--r-- | app/assets/javascripts/application.js | 16 | ||||
-rw-r--r-- | app/assets/javascripts/application.js.coffee | 26 | ||||
-rw-r--r-- | app/controllers/runner_projects_controller.rb | 21 | ||||
-rw-r--r-- | app/controllers/runners_controller.rb | 27 | ||||
-rw-r--r-- | app/views/runners/_runner.html.haml | 34 | ||||
-rw-r--r-- | app/views/runners/assign_all.js.haml | 2 | ||||
-rw-r--r-- | app/views/runners/index.html.haml | 29 | ||||
-rw-r--r-- | app/views/runners/update.js.haml | 2 | ||||
-rw-r--r-- | config/routes.rb | 6 |
9 files changed, 103 insertions, 60 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js deleted file mode 100644 index 0443bb7..0000000 --- a/app/assets/javascripts/application.js +++ /dev/null @@ -1,16 +0,0 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// the compiled file. -// -// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD -// GO AFTER THE REQUIRES BELOW. -// -//= require jquery -//= require jquery_ujs -//= require_tree . -// diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee new file mode 100644 index 0000000..706bb9d --- /dev/null +++ b/app/assets/javascripts/application.js.coffee @@ -0,0 +1,26 @@ +# This is a manifest file that'll be compiled into application.js, which will include all the files +# listed below. +# +# Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +# or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +# +# It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +# the compiled file. +# +# WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD +# GO AFTER THE REQUIRES BELOW. +# +#= require jquery +#= require jquery_ujs +#= require_tree . +# +# + +$ -> + $('.edit-runner-link').on 'click', -> + descr = $(this).closest('.runner-description').first() + descr.hide() + descr.next('.runner-description-form').show() + + $('.assign-all-runner').on 'click', -> + $(this).replaceWith('<i class="icon-refresh icon-spin"></i> Assign in progres..') diff --git a/app/controllers/runner_projects_controller.rb b/app/controllers/runner_projects_controller.rb index f57f317..655c16d 100644 --- a/app/controllers/runner_projects_controller.rb +++ b/app/controllers/runner_projects_controller.rb @@ -8,24 +8,13 @@ class RunnerProjectsController < ApplicationController end def create - ActiveRecord::Base.transaction do - @runner_project = project.runner_projects.create!(params[:runner_project]) + @runner = Runner.find(params[:runner_project][:runner_id]) - runner = @runner_project.runner - - opts = { - key: runner.public_key, - title: "gitlab-ci-runner-#{runner.id}", - private_token: current_user.private_token - } - - result = Network.new.add_deploy_key(current_user.url, project.gitlab_id, opts) - raise "Can't add deploy key" unless result + if @runner.assign_to(@project, current_user) + redirect_to project_runner_projects_path + else + redirect_to project_runner_projects_path, alert: 'Failed adding runner deploy key to GitLab project' end - - redirect_to project_runner_projects_path - rescue - redirect_to project_runner_projects_path, alert: 'Failed adding runner deploy key to GitLab project' end def destroy diff --git a/app/controllers/runners_controller.rb b/app/controllers/runners_controller.rb index 4a7eb3e..1b840ef 100644 --- a/app/controllers/runners_controller.rb +++ b/app/controllers/runners_controller.rb @@ -1,8 +1,18 @@ class RunnersController < ApplicationController before_filter :authenticate_user! + before_filter :runner, except: :index def index - @runners = Runner.all + @runners = Runner.page(params[:page]).per(30) + end + + def update + @runner.update_attributes(description: params[:runner][:description]) + + respond_to do |format| + format.js + format.html { redirect_to runners_path } + end end def destroy @@ -10,4 +20,19 @@ class RunnersController < ApplicationController redirect_to runners_path end + + def assign_all + Project.all.each { |project| @runner.assign_to(project, current_user) } + + respond_to do |format| + format.js + format.html { redirect_to runners_path, notice: "Runner was assigned to all projects" } + end + end + + private + + def runner + @runner ||= Runner.find(params[:id]) + end end diff --git a/app/views/runners/_runner.html.haml b/app/views/runners/_runner.html.haml new file mode 100644 index 0000000..030c803 --- /dev/null +++ b/app/views/runners/_runner.html.haml @@ -0,0 +1,34 @@ +%tr{id: dom_id(runner)} + %td + %span.badge.badge-info= runner.id + %td + = runner.token + %td + .runner-description + = runner.description + %span (#{link_to 'edit', '#', class: 'edit-runner-link'}) + .runner-description-form.hide + = form_for runner, remote: true do |f| + = f.text_field :description, class: 'pull-left' + = f.submit 'Save', class: 'btn' + %td + - last_build = runner.last_build + - if last_build + = link_to last_build.short_sha, [last_build.project, last_build] + - else + unknown + %td + = runner.projects.count + %td + %span.badge.badge-success + #{runner.builds.success.count} + %span / + %span.badge.badge-important + #{runner.builds.failed.count} + %td + #{time_ago_in_words(runner.created_at)} ago + %td + .pull-right + = link_to 'Assign to all', assign_all_runner_path(runner), class: 'btn btn-small assign-all-runner', title: 'Assign runner to all projects', method: :put, remote: true + = link_to 'Remove', runner, data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small' + diff --git a/app/views/runners/assign_all.js.haml b/app/views/runners/assign_all.js.haml new file mode 100644 index 0000000..2b7d306 --- /dev/null +++ b/app/views/runners/assign_all.js.haml @@ -0,0 +1,2 @@ +:plain + $("#runner_#{@runner.id}").replaceWith("#{escape_javascript(render(@runner))}") diff --git a/app/views/runners/index.html.haml b/app/views/runners/index.html.haml index 72570c6..1ffee8c 100644 --- a/app/views/runners/index.html.haml +++ b/app/views/runners/index.html.haml @@ -16,35 +16,12 @@ %tr %th ID %th Token + %th Description %th Last build %th Projects %th Builds Stats %th Registered %th - - @runners.each do |runner| - %tr - %td - %span.badge.badge-info= runner.id - %td - = runner.token - %td - - last_build = runner.last_build - - if last_build - = link_to last_build.short_sha, [last_build.project, last_build] - - else - unknown - %td - = runner.projects.count - %td - %span.badge.badge-success - #{runner.builds.success.count} - %span / - %span.badge.badge-important - #{runner.builds.failed.count} - %td - #{time_ago_in_words(runner.created_at)} ago - %td - = link_to 'Block', runner, data: { confirm: "Are you sure?" }, method: :delete, class: 'btn btn-danger btn-small right' - - + = render @runners + = paginate @runners diff --git a/app/views/runners/update.js.haml b/app/views/runners/update.js.haml new file mode 100644 index 0000000..2b7d306 --- /dev/null +++ b/app/views/runners/update.js.haml @@ -0,0 +1,2 @@ +:plain + $("#runner_#{@runner.id}").replaceWith("#{escape_javascript(render(@runner))}") diff --git a/config/routes.rb b/config/routes.rb index ba175c9..29d366a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,7 +29,11 @@ GitlabCi::Application.routes.draw do end resource :user_sessions - resources :runners, only: [:index, :destroy] + resources :runners, only: [:index, :update, :destroy] do + member do + put :assign_all + end + end root :to => 'projects#index' end |