From 2dd5db749f3bb5458bc09b81077fe91b81298930 Mon Sep 17 00:00:00 2001 From: Takuya Noguchi Date: Tue, 27 Dec 2016 16:30:52 +0900 Subject: [PATCH] Add sorting pipeline for a commit --- app/controllers/projects/commit_controller.rb | 5 --- app/views/projects/commit/_ci_menu.html.haml | 2 +- app/views/projects/commit/pipelines.html.haml | 2 +- .../26117-sort-pipeline-for-commit.yml | 4 ++ .../projects/commit_controller_spec.rb | 38 +++++++++++++++++-- 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 changelogs/unreleased/26117-sort-pipeline-for-commit.yml diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 791ed88db30..bfc59bcc862 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -12,7 +12,6 @@ class Projects::CommitController < Projects::ApplicationController before_action :authorize_read_pipeline!, only: [:pipelines] before_action :commit before_action :define_commit_vars, only: [:show, :diff_for_path, :pipelines] - before_action :define_status_vars, only: [:show, :pipelines] before_action :define_note_vars, only: [:show, :diff_for_path] before_action :authorize_edit_tree!, only: [:revert, :cherry_pick] @@ -106,10 +105,6 @@ class Projects::CommitController < Projects::ApplicationController } end - def define_status_vars - @ci_pipelines = project.pipelines.where(sha: commit.sha) - end - def assign_change_commit_vars(mr_source_branch) @commit = project.commit(params[:id]) @target_branch = params[:target_branch] diff --git a/app/views/projects/commit/_ci_menu.html.haml b/app/views/projects/commit/_ci_menu.html.haml index 13ab2253733..8aed88da38b 100644 --- a/app/views/projects/commit/_ci_menu.html.haml +++ b/app/views/projects/commit/_ci_menu.html.haml @@ -7,4 +7,4 @@ = nav_link(path: 'commit#pipelines') do = link_to pipelines_namespace_project_commit_path(@project.namespace, @project, @commit.id) do Pipelines - %span.badge= @ci_pipelines.count + %span.badge= @commit.pipelines.size diff --git a/app/views/projects/commit/pipelines.html.haml b/app/views/projects/commit/pipelines.html.haml index 8233e26e4e7..00e7cdd1729 100644 --- a/app/views/projects/commit/pipelines.html.haml +++ b/app/views/projects/commit/pipelines.html.haml @@ -3,4 +3,4 @@ = render "commit_box" = render "ci_menu" -= render "pipelines_list", pipelines: @ci_pipelines += render "pipelines_list", pipelines: @commit.pipelines.order(id: :desc) diff --git a/changelogs/unreleased/26117-sort-pipeline-for-commit.yml b/changelogs/unreleased/26117-sort-pipeline-for-commit.yml new file mode 100644 index 00000000000..b2f5294d380 --- /dev/null +++ b/changelogs/unreleased/26117-sort-pipeline-for-commit.yml @@ -0,0 +1,4 @@ +--- +title: Add sorting pipeline for a commit +merge_request: 8319 +author: Takuya Noguchi diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb index 646b097d74e..0fa06a38d2a 100644 --- a/spec/controllers/projects/commit_controller_spec.rb +++ b/spec/controllers/projects/commit_controller_spec.rb @@ -1,9 +1,10 @@ require 'spec_helper' describe Projects::CommitController do - let(:project) { create(:project) } - let(:user) { create(:user) } - let(:commit) { project.commit("master") } + let(:project) { create(:project) } + let(:user) { create(:user) } + let(:commit) { project.commit("master") } + let(:pipeline) { create(:ci_pipeline, project: project, commit: commit) } let(:master_pickable_sha) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' } let(:master_pickable_commit) { project.commit(master_pickable_sha) } @@ -309,4 +310,35 @@ describe Projects::CommitController do end end end + + describe 'GET pipelines' do + def get_pipelines(extra_params = {}) + params = { + namespace_id: project.namespace.to_param, + project_id: project.to_param + } + + get :pipelines, params.merge(extra_params) + end + + context 'when the commit exists' do + context 'when the commit has one or more pipelines' do + it 'shows pipelines' do + get_pipelines(id: commit.id) + + expect(response).to be_ok + end + end + end + + context 'when the commit does not exist' do + before do + get_pipelines(id: 'e7a412c8da9f6d0081a633a4a402dde1c4694ebd') + end + + it 'returns a 404' do + expect(response).to have_http_status(404) + end + end + end end -- GitLab