BigW Consortium Gitlab

Commit d9273364 by Fatih Acet

Merge branch '21444-pipeliens-new-mr' into 'master'

Add pipelines tab to new MR #### What does this MR do? Adds pipelines tab to new MRs #### Screenshots (if relevant) ![Screen_Shot_2016-10-10_at_10.23.27_AM](/uploads/6c3f8f2be0cf9ba7cc78f6d918307ec0/Screen_Shot_2016-10-10_at_10.23.27_AM.png) ![Screen_Shot_2016-10-11_at_8.59.45_AM](/uploads/e67577d92327eafef6f04073f3d94212/Screen_Shot_2016-10-11_at_8.59.45_AM.png) #### What are the relevant issue numbers? Closes #21444 See merge request !6238
parents 85fba09b 72d84e48
......@@ -489,13 +489,12 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@noteable = @merge_request
@commits_count = @merge_request.commits.count
@pipeline = @merge_request.pipeline
@statuses = @pipeline.statuses.relevant if @pipeline
if @merge_request.locked_long_ago?
@merge_request.unlock_mr
@merge_request.close
end
define_pipelines_vars
end
# Discussion tab data is rendered on html responses of actions
......@@ -523,7 +522,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def define_widget_vars
@pipeline = @merge_request.pipeline
@pipelines = [@pipeline].compact
end
def define_commit_vars
......@@ -550,6 +548,15 @@ class Projects::MergeRequestsController < Projects::ApplicationController
)
end
def define_pipelines_vars
@pipelines = @merge_request.all_pipelines
if @pipelines.any?
@pipeline = @pipelines.first
@statuses = @pipeline.statuses.relevant
end
end
def define_new_vars
@noteable = @merge_request
......@@ -565,10 +572,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@commit = @merge_request.diff_head_commit
@base_commit = @merge_request.diff_base_commit
@pipeline = @merge_request.pipeline
@statuses = @pipeline.statuses.relevant if @pipeline
@note_counts = Note.where(commit_id: @commits.map(&:id)).
group(:commit_id).count
define_pipelines_vars
end
def invalid_mr
......
......@@ -787,21 +787,21 @@ class MergeRequest < ActiveRecord::Base
def all_pipelines
return unless source_project
@all_pipelines ||= begin
sha = if persisted?
all_commits_sha
else
diff_head_sha
end
source_project.pipelines.order(id: :desc).
where(sha: sha, ref: source_branch)
end
@all_pipelines ||= source_project.pipelines
.where(sha: all_commits_sha, ref: source_branch)
.order(id: :desc)
end
# Note that this could also return SHA from now dangling commits
#
def all_commits_sha
if persisted?
merge_request_diffs.flat_map(&:commits_sha).uniq
elsif compare_commits
compare_commits.to_a.reverse.map(&:id)
else
[diff_head_sha]
end
end
def merge_commit
......
......@@ -29,7 +29,11 @@
= link_to url_for(params), data: {target: 'div#commits', action: 'new', toggle: 'tab'} do
Commits
%span.badge= @commits.size
- if @pipeline
- if @pipelines.any?
%li.builds-tab
= link_to url_for(params), data: {target: 'div#pipelines', action: 'pipelines', toggle: 'tab'} do
Pipelines
%span.badge= @pipelines.size
%li.builds-tab
= link_to url_for(params), data: {target: 'div#builds', action: 'builds', toggle: 'tab'} do
Builds
......@@ -44,9 +48,11 @@
= render "projects/merge_requests/show/commits"
#diffs.diffs.tab-pane
- # This tab is always loaded via AJAX
- if @pipeline
- if @pipelines.any?
#builds.builds.tab-pane
= render "projects/merge_requests/show/builds"
#pipelines.pipelines.tab-pane
= render "projects/merge_requests/show/pipelines"
.mr-loading-status
= spinner
......@@ -59,5 +65,5 @@
:javascript
var merge_request = new MergeRequest({
action: "#{(@show_changes_tab ? 'new/diffs' : 'new')}",
buildsLoaded: "#{@pipeline ? 'true' : 'false'}"
buildsLoaded: "#{@pipelines.any? ? 'true' : 'false'}"
});
......@@ -61,7 +61,7 @@
%li.pipelines-tab
= link_to pipelines_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: '#pipelines', action: 'pipelines', toggle: 'tab' } do
Pipelines
%span.badge= @merge_request.all_pipelines.size
%span.badge= @pipelines.size
%li.builds-tab
= link_to builds_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: '#builds', action: 'builds', toggle: 'tab' } do
Builds
......
......@@ -640,6 +640,7 @@ describe MergeRequest, models: true do
end
describe '#all_commits_sha' do
context 'when merge request is persisted' do
let(:all_commits_sha) do
subject.merge_request_diffs.flat_map(&:commits).map(&:sha).uniq
end
......@@ -669,6 +670,29 @@ describe MergeRequest, models: true do
end
end
context 'when merge request is not persisted' do
context 'when compare commits are set in the service' do
let(:commit) { spy('commit') }
subject do
build(:merge_request, compare_commits: [commit, commit])
end
it 'returns commits from compare commits temporary data' do
expect(subject.all_commits_sha).to eq [commit, commit]
end
end
context 'when compare commits are not set in the service' do
subject { build(:merge_request) }
it 'returns array with diff head sha element only' do
expect(subject.all_commits_sha).to eq [subject.diff_head_sha]
end
end
end
end
describe '#participants' do
let(:project) { create(:project, :public) }
......
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