Prevent error when submitting a merge request and pipeline is not defined
This commit is contained in:
parent
6ea0b8d563
commit
d9a2093e7e
6 changed files with 45 additions and 7 deletions
|
@ -564,7 +564,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
|
||||||
def define_pipelines_vars
|
def define_pipelines_vars
|
||||||
@pipelines = @merge_request.all_pipelines
|
@pipelines = @merge_request.all_pipelines
|
||||||
@pipeline = @merge_request.pipeline
|
@pipeline = @merge_request.pipeline
|
||||||
@statuses = @pipeline.statuses.relevant if @pipeline.present?
|
@statuses_count = @pipeline.present? ? @pipeline.statuses.relevant.count : 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def define_new_vars
|
def define_new_vars
|
||||||
|
|
|
@ -781,7 +781,7 @@ class MergeRequest < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_pipelines
|
def all_pipelines
|
||||||
return unless source_project
|
return Ci::Pipeline.none unless source_project
|
||||||
|
|
||||||
@all_pipelines ||= source_project.pipelines
|
@all_pipelines ||= source_project.pipelines
|
||||||
.where(sha: all_commits_sha, ref: source_branch)
|
.where(sha: all_commits_sha, ref: source_branch)
|
||||||
|
|
|
@ -34,10 +34,11 @@
|
||||||
= link_to url_for(params), data: {target: 'div#pipelines', action: 'pipelines', toggle: 'tab'} do
|
= link_to url_for(params), data: {target: 'div#pipelines', action: 'pipelines', toggle: 'tab'} do
|
||||||
Pipelines
|
Pipelines
|
||||||
%span.badge= @pipelines.size
|
%span.badge= @pipelines.size
|
||||||
|
- if @pipeline.present?
|
||||||
%li.builds-tab
|
%li.builds-tab
|
||||||
= link_to url_for(params), data: {target: 'div#builds', action: 'builds', toggle: 'tab'} do
|
= link_to url_for(params), data: {target: 'div#builds', action: 'builds', toggle: 'tab'} do
|
||||||
Builds
|
Builds
|
||||||
%span.badge= @statuses.size
|
%span.badge= @statuses_count
|
||||||
%li.diffs-tab
|
%li.diffs-tab
|
||||||
= link_to url_for(params.merge(action: 'new_diffs')), data: {target: 'div#diffs', action: 'new/diffs', toggle: 'tab'} do
|
= link_to url_for(params.merge(action: 'new_diffs')), data: {target: 'div#diffs', action: 'new/diffs', toggle: 'tab'} do
|
||||||
Changes
|
Changes
|
||||||
|
@ -48,9 +49,10 @@
|
||||||
= render "projects/merge_requests/show/commits"
|
= render "projects/merge_requests/show/commits"
|
||||||
#diffs.diffs.tab-pane
|
#diffs.diffs.tab-pane
|
||||||
- # This tab is always loaded via AJAX
|
- # This tab is always loaded via AJAX
|
||||||
- if @pipelines.any?
|
- if @pipeline.present?
|
||||||
#builds.builds.tab-pane
|
#builds.builds.tab-pane
|
||||||
= render "projects/merge_requests/show/builds"
|
= render "projects/merge_requests/show/builds"
|
||||||
|
- if @pipelines.any?
|
||||||
#pipelines.pipelines.tab-pane
|
#pipelines.pipelines.tab-pane
|
||||||
= render "projects/merge_requests/show/pipelines"
|
= render "projects/merge_requests/show/pipelines"
|
||||||
|
|
||||||
|
@ -65,5 +67,5 @@
|
||||||
:javascript
|
:javascript
|
||||||
var merge_request = new MergeRequest({
|
var merge_request = new MergeRequest({
|
||||||
action: "#{(@show_changes_tab ? 'new/diffs' : 'new')}",
|
action: "#{(@show_changes_tab ? 'new/diffs' : 'new')}",
|
||||||
buildsLoaded: "#{@pipelines.any? ? 'true' : 'false'}"
|
buildsLoaded: "#{@pipeline.present? ? 'true' : 'false'}"
|
||||||
});
|
});
|
||||||
|
|
|
@ -59,15 +59,16 @@
|
||||||
= link_to commits_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#commits', action: 'commits', toggle: 'tab' } do
|
= link_to commits_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#commits', action: 'commits', toggle: 'tab' } do
|
||||||
Commits
|
Commits
|
||||||
%span.badge= @commits_count
|
%span.badge= @commits_count
|
||||||
- if @pipeline
|
- if @pipelines.any?
|
||||||
%li.pipelines-tab
|
%li.pipelines-tab
|
||||||
= link_to pipelines_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: '#pipelines', action: 'pipelines', toggle: 'tab' } do
|
= link_to pipelines_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: '#pipelines', action: 'pipelines', toggle: 'tab' } do
|
||||||
Pipelines
|
Pipelines
|
||||||
%span.badge= @pipelines.size
|
%span.badge= @pipelines.size
|
||||||
|
- if @pipeline.present?
|
||||||
%li.builds-tab
|
%li.builds-tab
|
||||||
= link_to builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: '#builds', action: 'builds', toggle: 'tab' } do
|
= link_to builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: '#builds', action: 'builds', toggle: 'tab' } do
|
||||||
Builds
|
Builds
|
||||||
%span.badge= @statuses.size
|
%span.badge= @statuses_count
|
||||||
%li.diffs-tab
|
%li.diffs-tab
|
||||||
= link_to diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#diffs', action: 'diffs', toggle: 'tab' } do
|
= link_to diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#diffs', action: 'diffs', toggle: 'tab' } do
|
||||||
Changes
|
Changes
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
title: Prevent error when submitting a merge request and pipeline is not defined
|
||||||
|
merge_request: 7707
|
||||||
|
author:
|
|
@ -0,0 +1,31 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'projects/merge_requests/_new_submit.html.haml', :view do
|
||||||
|
let(:merge_request) { create(:merge_request) }
|
||||||
|
let!(:pipeline) { create(:ci_empty_pipeline) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
controller.prepend_view_path('app/views/projects')
|
||||||
|
|
||||||
|
assign(:merge_request, merge_request)
|
||||||
|
assign(:commits, merge_request.commits)
|
||||||
|
assign(:project, merge_request.target_project)
|
||||||
|
|
||||||
|
allow(view).to receive(:can?).and_return(true)
|
||||||
|
allow(view).to receive(:url_for).and_return('#')
|
||||||
|
allow(view).to receive(:current_user).and_return(merge_request.author)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when there are pipelines for merge request but no pipeline for last commit' do
|
||||||
|
before do
|
||||||
|
assign(:pipelines, Ci::Pipeline.all)
|
||||||
|
assign(:pipeline, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows <<Pipelines>> tab and hides <<Builds>> tab' do
|
||||||
|
render
|
||||||
|
expect(rendered).to have_text('Pipelines 1')
|
||||||
|
expect(rendered).not_to have_text('Builds')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue