From fc795d6ee2bdc1229f82c535222752364b5c9e44 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 5 Oct 2015 21:20:54 +0200 Subject: Fix graphical glitches --- app/controllers/ci/projects_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index 33b8ae64659..64d544acfd9 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -14,9 +14,11 @@ module Ci def show @ref = params[:ref] - @commits = @project.commits.reverse_order - # TODO: this is broken - # @commits = @commits.where(ref: @ref) if @ref + @commits = @project.commits.group(:sha).reverse_order + if @ref + builds = @project.builds.where(ref: @ref).select(:commit_id).distinct + @commits = @commits.where(id: builds) + end @commits = @commits.page(params[:page]).per(20) end -- cgit v1.2.1 From 17de909a42fa5d641eb9554e94fee59fb0762cbc Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 6 Oct 2015 16:25:27 +0200 Subject: Fix broken grouping sql clause when rendering commits for CI --- app/controllers/ci/projects_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index 64d544acfd9..adb913a783f 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -14,9 +14,10 @@ module Ci def show @ref = params[:ref] - @commits = @project.commits.group(:sha).reverse_order + @commits = @project.commits.reverse_order if @ref - builds = @project.builds.where(ref: @ref).select(:commit_id).distinct + # unscope is required, because of default_scope defined in Ci::Build + builds = @project.builds.unscope(:select, :order).where(ref: @ref).select(:commit_id).distinct @commits = @commits.where(id: builds) end @commits = @commits.page(params[:page]).per(20) -- cgit v1.2.1 From 04c7dc2a9e2385ce47a70205eafd4cf4f91a0bba Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 6 Oct 2015 20:15:06 +0200 Subject: Cleanup CI code after refactoring and fix several 500 errors Signed-off-by: Dmitriy Zaporozhets --- app/controllers/ci/builds_controller.rb | 40 ++++---------------------------- app/controllers/ci/commits_controller.rb | 6 ----- 2 files changed, 5 insertions(+), 41 deletions(-) (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/builds_controller.rb b/app/controllers/ci/builds_controller.rb index bf87f81439a..daf3bcf72a9 100644 --- a/app/controllers/ci/builds_controller.rb +++ b/app/controllers/ci/builds_controller.rb @@ -1,41 +1,11 @@ module Ci class BuildsController < Ci::ApplicationController - before_action :authenticate_user!, except: [:status, :show] - before_action :authenticate_public_page!, only: :show + before_action :authenticate_user!, except: [:status] before_action :project - before_action :authorize_access_project!, except: [:status, :show] - before_action :authorize_manage_project!, except: [:status, :show, :retry, :cancel] + before_action :authorize_access_project!, except: [:status] + before_action :authorize_manage_project!, except: [:status, :retry, :cancel] before_action :authorize_manage_builds!, only: [:retry, :cancel] - before_action :build, except: [:show] - layout 'ci/build' - - def show - if params[:id] =~ /\A\d+\Z/ - @build = build - else - # try to find commit by sha - commit = commit_by_sha - - if commit - # Redirect to commit page - redirect_to ci_project_commit_path(@project, @build.commit) - return - end - end - - raise ActiveRecord::RecordNotFound unless @build - - @builds = @project.commits.find_by_sha(@build.sha).builds.order('id DESC') - @builds = @builds.where("id not in (?)", @build.id).page(params[:page]).per(20) - @commit = @build.commit - - respond_to do |format| - format.html - format.json do - render json: @build.to_json(methods: :trace_html) - end - end - end + before_action :build def retry if @build.commands.blank? @@ -68,7 +38,7 @@ module Ci end def build - @build ||= project.builds.unscoped.find_by(id: params[:id]) + @build ||= project.builds.unscoped.find_by!(id: params[:id]) end def commit_by_sha diff --git a/app/controllers/ci/commits_controller.rb b/app/controllers/ci/commits_controller.rb index 887e92f84cf..404e0e4b412 100644 --- a/app/controllers/ci/commits_controller.rb +++ b/app/controllers/ci/commits_controller.rb @@ -5,12 +5,6 @@ module Ci before_action :project before_action :authorize_access_project!, except: [:status, :show, :cancel] before_action :authorize_manage_builds!, only: [:cancel] - before_action :commit, only: :show - layout 'ci/commit' - - def show - @builds = @commit.builds - end def status commit = Ci::Project.find(params[:project_id]).commits.find_by_sha!(params[:id]) -- cgit v1.2.1 From 27b75b2b2d9c274fca005949f645d97ce9333d71 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 6 Oct 2015 20:36:22 +0200 Subject: Refactor commit/build tests and fix CI cancel Signed-off-by: Dmitriy Zaporozhets --- app/controllers/ci/commits_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/commits_controller.rb b/app/controllers/ci/commits_controller.rb index 404e0e4b412..7e6705c9702 100644 --- a/app/controllers/ci/commits_controller.rb +++ b/app/controllers/ci/commits_controller.rb @@ -16,7 +16,7 @@ module Ci def cancel commit.builds.running_or_pending.each(&:cancel) - redirect_to ci_project_commits_path(project, commit.sha) + redirect_to namespace_project_commit_path(commit.gl_project.namespace, commit.gl_project, commit.sha) end private -- cgit v1.2.1 From 82b6a17ca70a20015e654b4a0fdb8aec6d244f95 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 6 Oct 2015 21:41:37 +0200 Subject: Fix ci build routing and few tests Signed-off-by: Dmitriy Zaporozhets --- app/controllers/ci/builds_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/builds_controller.rb b/app/controllers/ci/builds_controller.rb index daf3bcf72a9..b0b8b62fced 100644 --- a/app/controllers/ci/builds_controller.rb +++ b/app/controllers/ci/builds_controller.rb @@ -17,7 +17,7 @@ module Ci if params[:return_to] redirect_to URI.parse(params[:return_to]).path else - redirect_to ci_project_build_path(project, build) + redirect_to build_path(build) end end @@ -28,7 +28,7 @@ module Ci def cancel @build.cancel - redirect_to ci_project_build_path(@project, @build) + redirect_to build_path(@build) end protected @@ -44,5 +44,9 @@ module Ci def commit_by_sha @project.commits.find_by(sha: params[:id]) end + + def build_path(build) + namespace_project_build_path(build.gl_project.namespace, build.gl_project, build) + end end end -- cgit v1.2.1 From e52de6771f6bf9629fc85213b94ec60721354e80 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Oct 2015 14:43:58 +0200 Subject: Remove Continuous Integration from project menu Signed-off-by: Dmitriy Zaporozhets --- app/controllers/ci/projects_controller.rb | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index adb913a783f..5484ae643a6 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -1,27 +1,10 @@ module Ci class ProjectsController < Ci::ApplicationController - before_action :authenticate_user!, except: [:build, :badge, :show] - before_action :authenticate_public_page!, only: :show - before_action :project, only: [:build, :show, :badge, :toggle_shared_runners, :dumped_yaml] - before_action :authorize_access_project!, except: [:build, :badge, :show, :new] + before_action :authenticate_user!, except: [:build, :badge] + before_action :authorize_access_project!, except: [:badge] before_action :authorize_manage_project!, only: [:toggle_shared_runners, :dumped_yaml] - before_action :authenticate_token!, only: [:build] before_action :no_cache, only: [:badge] - protect_from_forgery except: :build - - layout 'ci/project', except: [:index] - - def show - @ref = params[:ref] - - @commits = @project.commits.reverse_order - if @ref - # unscope is required, because of default_scope defined in Ci::Build - builds = @project.builds.unscope(:select, :order).where(ref: @ref).select(:commit_id).distinct - @commits = @commits.where(id: builds) - end - @commits = @commits.page(params[:page]).per(20) - end + protect_from_forgery # Project status badge # Image with build status for sha or ref -- cgit v1.2.1 From 1e06cabf4a8fa4d4c7acb9898682a5b4b41a9f58 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Oct 2015 15:24:32 +0200 Subject: Remove Ci::Commit and Ci::Build controllers Signed-off-by: Dmitriy Zaporozhets --- app/controllers/ci/builds_controller.rb | 52 -------------------------------- app/controllers/ci/commits_controller.rb | 32 -------------------- 2 files changed, 84 deletions(-) delete mode 100644 app/controllers/ci/builds_controller.rb delete mode 100644 app/controllers/ci/commits_controller.rb (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/builds_controller.rb b/app/controllers/ci/builds_controller.rb deleted file mode 100644 index b0b8b62fced..00000000000 --- a/app/controllers/ci/builds_controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -module Ci - class BuildsController < Ci::ApplicationController - before_action :authenticate_user!, except: [:status] - before_action :project - before_action :authorize_access_project!, except: [:status] - before_action :authorize_manage_project!, except: [:status, :retry, :cancel] - before_action :authorize_manage_builds!, only: [:retry, :cancel] - before_action :build - - def retry - if @build.commands.blank? - return page_404 - end - - build = Ci::Build.retry(@build) - - if params[:return_to] - redirect_to URI.parse(params[:return_to]).path - else - redirect_to build_path(build) - end - end - - def status - render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha) - end - - def cancel - @build.cancel - - redirect_to build_path(@build) - end - - protected - - def project - @project = Ci::Project.find(params[:project_id]) - end - - def build - @build ||= project.builds.unscoped.find_by!(id: params[:id]) - end - - def commit_by_sha - @project.commits.find_by(sha: params[:id]) - end - - def build_path(build) - namespace_project_build_path(build.gl_project.namespace, build.gl_project, build) - end - end -end diff --git a/app/controllers/ci/commits_controller.rb b/app/controllers/ci/commits_controller.rb deleted file mode 100644 index 7e6705c9702..00000000000 --- a/app/controllers/ci/commits_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Ci - class CommitsController < Ci::ApplicationController - before_action :authenticate_user!, except: [:status, :show] - before_action :authenticate_public_page!, only: :show - before_action :project - before_action :authorize_access_project!, except: [:status, :show, :cancel] - before_action :authorize_manage_builds!, only: [:cancel] - - def status - commit = Ci::Project.find(params[:project_id]).commits.find_by_sha!(params[:id]) - render json: commit.to_json(only: [:id, :sha], methods: [:status, :coverage]) - rescue ActiveRecord::RecordNotFound - render json: { status: "not_found" } - end - - def cancel - commit.builds.running_or_pending.each(&:cancel) - - redirect_to namespace_project_commit_path(commit.gl_project.namespace, commit.gl_project, commit.sha) - end - - private - - def project - @project ||= Ci::Project.find(params[:project_id]) - end - - def commit - @commit ||= Ci::Project.find(params[:project_id]).commits.find_by_sha!(params[:id]) - end - end -end -- cgit v1.2.1 From a30b68fe1ded96c5aafe4348d1afec269354c469 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Oct 2015 16:20:31 +0200 Subject: Move CI services to project settings area Signed-off-by: Dmitriy Zaporozhets --- app/controllers/ci/services_controller.rb | 59 ------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 app/controllers/ci/services_controller.rb (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/services_controller.rb b/app/controllers/ci/services_controller.rb deleted file mode 100644 index 52c96a34ce8..00000000000 --- a/app/controllers/ci/services_controller.rb +++ /dev/null @@ -1,59 +0,0 @@ -module Ci - class ServicesController < Ci::ApplicationController - before_action :authenticate_user! - before_action :project - before_action :authorize_access_project! - before_action :authorize_manage_project! - before_action :service, only: [:edit, :update, :test] - - respond_to :html - - layout 'ci/project' - - def index - @project.build_missing_services - @services = @project.services.reload - end - - def edit - end - - def update - if @service.update_attributes(service_params) - redirect_to edit_ci_project_service_path(@project, @service.to_param) - else - render 'edit' - end - end - - def test - last_build = @project.builds.last - - if @service.execute(last_build) - message = { notice: 'We successfully tested the service' } - else - message = { alert: 'We tried to test the service but error occurred' } - end - - redirect_to :back, message - end - - private - - def project - @project = Ci::Project.find(params[:project_id]) - end - - def service - @service ||= @project.services.find { |service| service.to_param == params[:id] } - end - - def service_params - params.require(:service).permit( - :type, :active, :webhook, :notify_only_broken_builds, - :email_recipients, :email_only_broken_builds, :email_add_pusher, - :hipchat_token, :hipchat_room, :hipchat_server - ) - end - end -end -- cgit v1.2.1 From 7f63a8787ce454a61f72393ccbe22fc283ba8313 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Oct 2015 17:54:49 +0200 Subject: Fix tests and few CI features Signed-off-by: Dmitriy Zaporozhets --- app/controllers/ci/projects_controller.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index 5484ae643a6..7777aa18031 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -1,5 +1,6 @@ module Ci class ProjectsController < Ci::ApplicationController + before_action :project before_action :authenticate_user!, except: [:build, :badge] before_action :authorize_access_project!, except: [:badge] before_action :authorize_manage_project!, only: [:toggle_shared_runners, :dumped_yaml] -- cgit v1.2.1 From 7af4f5215e28927830cbc74d383cdfeb9e4ef587 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 12 Oct 2015 21:12:31 +0200 Subject: Show warning if build doesn't have runners with specified tags or runners didn't connect recently Slightly refactor runner status detection: moving it to Runner class Signed-off-by: Kamil Trzcinski --- app/controllers/ci/admin/runners_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers/ci') diff --git a/app/controllers/ci/admin/runners_controller.rb b/app/controllers/ci/admin/runners_controller.rb index 9a68add9083..110954a612d 100644 --- a/app/controllers/ci/admin/runners_controller.rb +++ b/app/controllers/ci/admin/runners_controller.rb @@ -6,7 +6,7 @@ module Ci @runners = Ci::Runner.order('id DESC') @runners = @runners.search(params[:search]) if params[:search].present? @runners = @runners.page(params[:page]).per(30) - @active_runners_cnt = Ci::Runner.where("contacted_at > ?", 1.minutes.ago).count + @active_runners_cnt = Ci::Runner.online.count end def show @@ -66,7 +66,7 @@ module Ci end def runner_params - params.require(:runner).permit(:token, :description, :tag_list, :contacted_at, :active) + params.require(:runner).permit(:token, :description, :tag_list, :active) end end end -- cgit v1.2.1