Commit 030b5038 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'cleanup-ci-pages' into 'master'

Cleanup CI pages

- [x] Remove `ci/projects/:id` page
- [x] Remove Continuous integration from project menu
- [x] Remove unused css/js
- [x] Remove Ci::Commit and Ci::Build controllers
- [x] Move CI services to project settings area


cc @ayufan 

Part of #2594

See merge request !1529
parents 92c33a8e 7f63a878
...@@ -35,6 +35,7 @@ v 8.1.0 (unreleased) ...@@ -35,6 +35,7 @@ v 8.1.0 (unreleased)
- Add user preference to change layout width (Peter Göbel) - Add user preference to change layout width (Peter Göbel)
- Use commit status in merge request widget as preffered source of CI status - Use commit status in merge request widget as preffered source of CI status
- Integrate CI commit and build pages into project pages - Integrate CI commit and build pages into project pages
- Move CI services page to project settings area
v 8.0.4 v 8.0.4
- Fix Message-ID header to be RFC 2111-compliant to prevent e-mails being dropped (Stan Hu) - Fix Message-ID header to be RFC 2111-compliant to prevent e-mails being dropped (Stan Hu)
......
This diff is collapsed.
$(document).on 'click', '.badge-codes-toggle', -> $(document).on 'click', '.badge-codes-toggle', ->
$('.badge-codes-block').toggleClass("hide") $('.badge-codes-block').toggleClass("hide")
return false return false
$(document).on 'click', '.sync-now', ->
$(this).find('i').addClass('fa-spin')
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
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
module Ci module Ci
class ProjectsController < Ci::ApplicationController class ProjectsController < Ci::ApplicationController
before_action :authenticate_user!, except: [:build, :badge, :show] before_action :project
before_action :authenticate_public_page!, only: :show before_action :authenticate_user!, except: [:build, :badge]
before_action :project, only: [:build, :show, :badge, :toggle_shared_runners, :dumped_yaml] before_action :authorize_access_project!, except: [:badge]
before_action :authorize_access_project!, except: [:build, :badge, :show, :new]
before_action :authorize_manage_project!, only: [:toggle_shared_runners, :dumped_yaml] before_action :authorize_manage_project!, only: [:toggle_shared_runners, :dumped_yaml]
before_action :authenticate_token!, only: [:build]
before_action :no_cache, only: [:badge] before_action :no_cache, only: [:badge]
protect_from_forgery except: :build protect_from_forgery
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
# Project status badge # Project status badge
# Image with build status for sha or ref # Image with build status for sha or ref
......
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
...@@ -2,6 +2,8 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -2,6 +2,8 @@ class Projects::BuildsController < Projects::ApplicationController
before_action :ci_project before_action :ci_project
before_action :build before_action :build
before_action :authorize_admin_project!, except: [:show, :status]
layout "project" layout "project"
def show def show
...@@ -17,9 +19,37 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -17,9 +19,37 @@ class Projects::BuildsController < Projects::ApplicationController
end end
end end
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
private private
def build def build
@build ||= ci_project.builds.unscoped.find_by!(id: params[:id]) @build ||= ci_project.builds.unscoped.find_by!(id: params[:id])
end end
def build_path(build)
namespace_project_build_path(build.gl_project.namespace, build.gl_project, build)
end
end end
class Projects::CiServicesController < Projects::ApplicationController
before_action :ci_project
before_action :authorize_admin_project!
layout "project_settings"
def index
@ci_project.build_missing_services
@services = @ci_project.services.reload
end
def edit
service
end
def update
if @service.update_attributes(service_params)
redirect_to edit_namespace_project_ci_service_path(@project, @project.namespace, @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 service
@service ||= @ci_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
...@@ -38,6 +38,14 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -38,6 +38,14 @@ class Projects::CommitController < Projects::ApplicationController
@ci_project = @project.gitlab_ci_project @ci_project = @project.gitlab_ci_project
end end
def cancel_builds
@ci_commit = @project.ci_commit(@commit.sha)
@ci_commit.builds.running_or_pending.each(&:cancel)
redirect_to ci_namespace_project_commit_path(project.namespace, project, commit.sha)
end
def branches def branches
@branches = @project.repository.branch_names_contains(commit.id) @branches = @project.repository.branch_names_contains(commit.id)
@tags = @project.repository.tag_names_contains(commit.id) @tags = @project.repository.tag_names_contains(commit.id)
......
- if no_runners_for_project?(@project)
= render 'no_runners'
= render 'ci/shared/guide' unless @project.setup_finished?
- if current_user && can?(current_user, :manage_project, gl_project) && !@project.any_runners?
.alert.alert-danger
Builds for this project wont be served unless you configure runners on
= link_to "Runners page", runners_path(@project.gl_project)
%ul.nav.nav-tabs.append-bottom-20
%li{class: ref_tab_class}
= link_to 'All commits', ci_project_path(@project)
- @project.tracked_refs.each do |ref|
%li{class: ref_tab_class(ref)}
= link_to ref, ci_project_path(@project, ref: ref)
- if @ref && !@project.tracked_refs.include?(@ref)
%li{class: 'active'}
= link_to @ref, ci_project_path(@project, ref: @ref)
%li.pull-right
= link_to 'Go to project', project_path(gl_project), class: 'btn btn-sm'
- if @ref
%p
Paste build status image for #{@ref} with next link
= link_to '#', class: 'badge-codes-toggle btn btn-default btn-xs' do
Status Badge
.badge-codes-block.bs-callout.bs-callout-info.hide
%p
Status badge for
%span.label.label-info #{@ref}
branch
%div
%label Markdown:
= text_field_tag 'badge_md', markdown_badge_code(@project, @ref), readonly: true, class: 'form-control'
%label Html:
= text_field_tag 'badge_html', html_badge_code(@project, @ref), readonly: true, class: 'form-control'
%table.table.builds
%thead
%tr
%th Status
%th Commit
%th Message
%th Branch
%th Total duration
%th Finished at
- if @project.coverage_enabled?
%th Coverage
= render @commits
= paginate @commits
- if @commits.empty?
.bs-callout
%h4 No commits yet
...@@ -5,17 +5,6 @@ ...@@ -5,17 +5,6 @@
%span %span
Back to project Back to project
%li.separate-item %li.separate-item
= nav_link path: ['projects#show', 'commits#show', 'builds#show'] do
= link_to ci_project_path(@project) do
= icon('list-alt fw')
%span
Commits
%span.count= @project.commits.count
= nav_link path: ['services#index', 'services#edit'] do
= link_to ci_project_services_path(@project) do
= icon('share fw')
%span
Services
= nav_link path: 'events#index' do = nav_link path: 'events#index' do
= link_to ci_project_events_path(@project) do = link_to ci_project_events_path(@project) do
= icon('book fw') = icon('book fw')
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
Files Files
- if project_nav_tab? :commits - if project_nav_tab? :commits
= nav_link(controller: %w(commit commits compare repositories tags branches)) do = nav_link(controller: %w(commit commits compare repositories tags branches builds)) do
= link_to project_commits_path(@project), title: 'Commits', class: 'shortcuts-commits', data: {placement: 'right'} do = link_to project_commits_path(@project), title: 'Commits', class: 'shortcuts-commits', data: {placement: 'right'} do
= icon('history fw') = icon('history fw')
%span %span
...@@ -76,13 +76,6 @@ ...@@ -76,13 +76,6 @@
Merge Requests Merge Requests
%span.count.merge_counter= @project.merge_requests.opened.count %span.count.merge_counter= @project.merge_requests.opened.count
- if @project.gitlab_ci?
= nav_link(controller: [:ci, :project]) do
= link_to ci_project_path(@project.gitlab_ci_project), title: 'Continuous Integration', data: {placement: 'right'} do
= icon('building fw')
%span
Continuous Integration
- if project_nav_tab? :settings - if project_nav_tab? :settings
= nav_link(controller: [:project_members, :teams]) do = nav_link(controller: [:project_members, :teams]) do
= link_to namespace_project_project_members_path(@project.namespace, @project), title: 'Members', class: 'team-tab tab', data: {placement: 'right'} do = link_to namespace_project_project_members_path(@project.namespace, @project), title: 'Members', class: 'team-tab tab', data: {placement: 'right'} do
......
...@@ -60,3 +60,13 @@ ...@@ -60,3 +60,13 @@
= icon('building fw') = icon('building fw')
%span %span
CI Settings CI Settings
= nav_link controller: 'ci_services' do
= link_to namespace_project_ci_services_path(@project.namespace, @project) do
= icon('share fw')
%span
CI Services
= nav_link path: 'events#index' do
= link_to ci_project_events_path(@project.gitlab_ci_project) do
= icon('book fw')
%span
CI Events
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
- if defined?(controls) && current_user && can?(current_user, :manage_builds, gl_project) - if defined?(controls) && current_user && can?(current_user, :manage_builds, gl_project)
.pull-right .pull-right
- if build.active? - if build.active?
= link_to cancel_ci_project_build_path(build.project, build, return_to: request.original_url), title: 'Cancel build' do = link_to cancel_namespace_project_build_path(gl_project.namespace, gl_project, build, return_to: request.original_url), title: 'Cancel build' do
%i.fa.fa-remove.cred %i.fa.fa-remove.cred
- elsif build.commands.present? - elsif build.commands.present?
= link_to retry_ci_project_build_path(build.project, build, return_to: request.original_url), method: :post, title: 'Retry build' do = link_to retry_namespace_project_build_path(gl_project.namespace, gl_project, build, return_to: request.original_url), method: :post, title: 'Retry build' do
%i.fa.fa-repeat %i.fa.fa-repeat
...@@ -72,9 +72,9 @@ ...@@ -72,9 +72,9 @@
- if current_user && can?(current_user, :manage_builds, @project) - if current_user && can?(current_user, :manage_builds, @project)
.pull-right .pull-right
- if @build.active? - if @build.active?
= link_to "Cancel", cancel_ci_project_build_path(@ci_project, @build), class: 'btn btn-sm btn-danger' = link_to "Cancel", cancel_namespace_project_build_path(@project.namespace, @project, @build), class: 'btn btn-sm btn-danger'
- elsif @build.commands.present? - elsif @build.commands.present?
= link_to "Retry", retry_ci_project_build_path(@ci_project, @build), class: 'btn btn-sm btn-primary', method: :post = link_to "Retry", retry_namespace_project_build_path(@project.namespace, @project, @build), class: 'btn btn-sm btn-primary', method: :post
- if @build.duration - if @build.duration
%p %p
......
...@@ -4,13 +4,10 @@ ...@@ -4,13 +4,10 @@
%p= @service.description %p= @service.description
.back-link
= link_to ci_project_services_path(@project) do
&larr; to services
%hr %hr
= form_for(@service, as: :service, url: ci_project_service_path(@project, @service.to_param), method: :put, html: { class: 'form-horizontal' }) do |f| = form_for(@service, as: :service, url: namespace_project_ci_service_path(@project.namespace, @project, @service.to_param), method: :put, html: { class: 'form-horizontal' }) do |f|
- if @service.errors.any? - if @service.errors.any?
.alert.alert-danger .alert.alert-danger
%ul %ul
...@@ -54,4 +51,4 @@ ...@@ -54,4 +51,4 @@
= f.submit 'Save', class: 'btn btn-save' = f.submit 'Save', class: 'btn btn-save'
&nbsp; &nbsp;
- if @service.valid? && @service.activated? && @service.can_test? - if @service.valid? && @service.activated? && @service.can_test?
= link_to 'Test settings', test_ci_project_service_path(@project, @service.to_param), class: 'btn' = link_to 'Test settings', test_namespace_project_ci_service_path(@project.namespace, @project, @service.to_param), class: 'btn'
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
%td %td
= boolean_to_icon service.activated? = boolean_to_icon service.activated?
%td %td
= link_to edit_ci_project_service_path(@project, service.to_param) do = link_to edit_namespace_project_ci_service_path(@project.namespace, @project, service.to_param) do
%strong= service.title %strong= service.title
%td %td
= service.description = service.description
......
...@@ -8,6 +8,22 @@ ...@@ -8,6 +8,22 @@
Edit your Edit your
#{link_to ".gitlab-ci.yml using web-editor", yaml_web_editor_link(@ci_project)} #{link_to ".gitlab-ci.yml using web-editor", yaml_web_editor_link(@ci_project)}
- unless @project.empty_repo?
%p
Paste build status image for #{@repository.root_ref} with next link
= link_to '#', class: 'badge-codes-toggle btn btn-default btn-xs' do
Status Badge
.badge-codes-block.bs-callout.bs-callout-info.hide
%p
Status badge for
%span.label.label-info #{@ref}
branch
%div
%label Markdown:
= text_field_tag 'badge_md', markdown_badge_code(@ci_project, @repository.root_ref), readonly: true, class: 'form-control'
%label Html:
= text_field_tag 'badge_html', html_badge_code(@ci_project, @repository.root_ref), readonly: true, class: 'form-control'
= nested_form_for @ci_project, url: namespace_project_ci_settings_path(@project.namespace, @project), html: { class: 'form-horizontal' } do |f| = nested_form_for @ci_project, url: namespace_project_ci_settings_path(@project.namespace, @project), html: { class: 'form-horizontal' } do |f|
- if @ci_project.errors.any? - if @ci_project.errors.any?
#error_explanation #error_explanation
......
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
%br %br
You can add Specific runner for this project on Runners page You can add Specific runner for this project on Runners page
- if current_user.is_admin - if current_user.admin
or add Shared runner for whole application in admin are. or add Shared runner for whole application in admin are.
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
yaml file which is based on your old jobs. yaml file which is based on your old jobs.
Put this file to the root of your project and name it .gitlab-ci.yml Put this file to the root of your project and name it .gitlab-ci.yml
- if no_runners_for_project?(@ci_project)
= render 'no_runners'
= render 'form' = render 'form'
- if @ci_project.generated_yaml_config - if @ci_project.generated_yaml_config
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
- if @ci_project && current_user && can?(current_user, :manage_builds, @project) - if @ci_project && current_user && can?(current_user, :manage_builds, @project)
.pull-right .pull-right
- if @ci_commit.builds.running_or_pending.any? - if @ci_commit.builds.running_or_pending.any?
= link_to "Cancel", cancel_ci_project_commits_path(@ci_project, @ci_commit), class: 'btn btn-sm btn-danger' = link_to "Cancel", cancel_builds_namespace_project_commit_path(@project.namespace, @project, @commit.sha), class: 'btn btn-sm btn-danger'
- if @ci_commit.yaml_errors.present? - if @ci_commit.yaml_errors.present?
......
...@@ -22,27 +22,6 @@ Gitlab::Application.routes.draw do ...@@ -22,27 +22,6 @@ Gitlab::Application.routes.draw do
get :dumped_yaml get :dumped_yaml
end end
resources :services, only: [:index, :edit, :update] do
member do
get :test
end
end
resources :commits, only: [] do
member do
get :status
get :cancel
end
end
resources :builds, only: [] do
member do
get :cancel
get :status
post :retry
end
end
resources :runner_projects, only: [:create, :destroy] resources :runner_projects, only: [:create, :destroy]
resources :events, only: [:index] resources :events, only: [:index]
...@@ -495,6 +474,7 @@ Gitlab::Application.routes.draw do ...@@ -495,6 +474,7 @@ Gitlab::Application.routes.draw do
member do member do
get :branches get :branches
get :ci get :ci
get :cancel_builds
end end
end end
...@@ -599,7 +579,19 @@ Gitlab::Application.routes.draw do ...@@ -599,7 +579,19 @@ Gitlab::Application.routes.draw do
end end
end end
resources :builds, only: [:show] resources :ci_services, constraints: { id: /[^\/]+/ }, only: [:index, :edit, :update] do
member do
get :test
end
end
resources :builds, only: [:show] do
member do
get :cancel
get :status
post :retry
end
end
resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do resources :hooks, only: [:index, :create, :destroy], constraints: { id: /\d+/ } do
member do member do
......
require "spec_helper"
describe Ci::CommitsController do
describe "GET /status" do
it "returns status of commit" do
commit = FactoryGirl.create :ci_commit
get :status, id: commit.sha, ref_id: commit.ref, project_id: commit.project.id
expect(response).to be_success
expect(response.code).to eq('200')
JSON.parse(response.body)["status"] == "pending"
end
it "returns not_found status" do
commit = FactoryGirl.create :ci_commit
get :status, id: commit.sha, ref_id: "deploy", project_id: commit.project.id
expect(response).to be_success
expect(response.code).to eq('200')
JSON.parse(response.body)["status"] == "not_found"
end
end
end
require 'spec_helper' require 'spec_helper'
describe "Builds" do describe "Builds" do
before do before do
login_as(:user) login_as(:user)
@commit = FactoryGirl.create :ci_commit @commit = FactoryGirl.create :ci_commit
...@@ -19,4 +18,24 @@ describe "Builds" do ...@@ -19,4 +18,24 @@ describe "Builds" do
it { expect(page).to have_content @commit.git_commit_message } it { expect(page).to have_content @commit.git_commit_message }
it { expect(page).to have_content @commit.git_author_name } it { expect(page).to have_content @commit.git_author_name }
end end
describe "GET /:project/builds/:id/cancel" do
before do
@build.run!
visit cancel_namespace_project_build_path(@gl_project.namespace, @gl_project, @build)
end
it { expect(page).to have_content 'canceled' }
it { expect(page).to have_content 'Retry' }
end
describe "POST /:project/builds/:id/retry" do
before do
visit cancel_namespace_project_build_path(@gl_project.namespace, @gl_project, @build)
click_link 'Retry'
end
it { expect(page).to have_content 'pending' }
it { expect(page).to have_content 'Cancel' }
end
end end
require 'spec_helper'
describe "Builds" do
before do
login_as(:user)
@commit = FactoryGirl.create :ci_commit
@build = FactoryGirl.create :ci_build, commit: @commit
@gl_project = @commit.project.gl_project
@gl_project.team << [@user, :master]
end
describe "GET /:project/builds/:id/cancel" do
before do
@build.run!
visit cancel_ci_project_build_path(@commit.project, @build)
end
it { expect(page).to have_content 'canceled' }
it { expect(page).to have_content 'Retry' }
end
describe "POST /:project/builds/:id/retry" do
before do
visit cancel_ci_project_build_path(@commit.project, @build)
click_link 'Retry'
end
it { expect(page).to have_content 'pending' }
it { expect(page).to have_content 'Cancel' }
end
end
require 'spec_helper'
describe "Projects" do
let(:user) { create(:user) }
before do
login_as(user)
@project = FactoryGirl.create :ci_project, name: "GitLab / gitlab-shell"
@project.gl_project.team << [user, :master]
end
describe "GET /ci/projects/:id" do
before do
visit ci_project_path(@project)
end
it { expect(page).to have_content @project.name }
it { expect(page).to have_content 'All commits' }
end
end
require 'spec_helper'
describe "Builds" do
before do
@commit = FactoryGirl.create :ci_commit
@build = FactoryGirl.create :ci_build, commit: @commit
end
describe "GET /:project/builds/:id/status.json" do
before do
get status_ci_project_build_path(@commit.project, @build), format: :json
end
it { expect(response.status).to eq(200) }
it { expect(response.body).to include(@build.sha) }
end
end
require 'spec_helper'
describe "Commits" do
before do
@commit = FactoryGirl.create :ci_commit
end
describe "GET /:project/refs/:ref_name/commits/:id/status.json" do
before do
get status_ci_project_commits_path(@commit.project, @commit.sha), format: :json
end
it { expect(response.status).to eq(200) }
it { expect(response.body).to include(@commit.sha) }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment