Commit d9273364 authored by Fatih Acet's avatar 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 ...@@ -489,13 +489,12 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@noteable = @merge_request @noteable = @merge_request
@commits_count = @merge_request.commits.count @commits_count = @merge_request.commits.count
@pipeline = @merge_request.pipeline
@statuses = @pipeline.statuses.relevant if @pipeline
if @merge_request.locked_long_ago? if @merge_request.locked_long_ago?
@merge_request.unlock_mr @merge_request.unlock_mr
@merge_request.close @merge_request.close
end end
define_pipelines_vars
end end
# Discussion tab data is rendered on html responses of actions # Discussion tab data is rendered on html responses of actions
...@@ -523,7 +522,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -523,7 +522,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def define_widget_vars def define_widget_vars
@pipeline = @merge_request.pipeline @pipeline = @merge_request.pipeline
@pipelines = [@pipeline].compact
end end
def define_commit_vars def define_commit_vars
...@@ -550,6 +548,15 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -550,6 +548,15 @@ class Projects::MergeRequestsController < Projects::ApplicationController
) )
end 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 def define_new_vars
@noteable = @merge_request @noteable = @merge_request
...@@ -565,10 +572,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -565,10 +572,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@commit = @merge_request.diff_head_commit @commit = @merge_request.diff_head_commit
@base_commit = @merge_request.diff_base_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)). @note_counts = Note.where(commit_id: @commits.map(&:id)).
group(:commit_id).count group(:commit_id).count
define_pipelines_vars
end end
def invalid_mr def invalid_mr
......
...@@ -787,21 +787,21 @@ class MergeRequest < ActiveRecord::Base ...@@ -787,21 +787,21 @@ class MergeRequest < ActiveRecord::Base
def all_pipelines def all_pipelines
return unless source_project return unless source_project
@all_pipelines ||= begin @all_pipelines ||= source_project.pipelines
sha = if persisted? .where(sha: all_commits_sha, ref: source_branch)
all_commits_sha .order(id: :desc)
else
diff_head_sha
end
source_project.pipelines.order(id: :desc).
where(sha: sha, ref: source_branch)
end
end end
# Note that this could also return SHA from now dangling commits # Note that this could also return SHA from now dangling commits
#
def all_commits_sha def all_commits_sha
merge_request_diffs.flat_map(&:commits_sha).uniq 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 end
def merge_commit def merge_commit
......
...@@ -29,7 +29,11 @@ ...@@ -29,7 +29,11 @@
= link_to url_for(params), data: {target: 'div#commits', action: 'new', toggle: 'tab'} do = link_to url_for(params), data: {target: 'div#commits', action: 'new', toggle: 'tab'} do
Commits Commits
%span.badge= @commits.size %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 %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
...@@ -44,9 +48,11 @@ ...@@ -44,9 +48,11 @@
= 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 @pipeline - if @pipelines.any?
#builds.builds.tab-pane #builds.builds.tab-pane
= render "projects/merge_requests/show/builds" = render "projects/merge_requests/show/builds"
#pipelines.pipelines.tab-pane
= render "projects/merge_requests/show/pipelines"
.mr-loading-status .mr-loading-status
= spinner = spinner
...@@ -59,5 +65,5 @@ ...@@ -59,5 +65,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: "#{@pipeline ? 'true' : 'false'}" buildsLoaded: "#{@pipelines.any? ? 'true' : 'false'}"
}); });
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
%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= @merge_request.all_pipelines.size %span.badge= @pipelines.size
%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
......
...@@ -640,32 +640,56 @@ describe MergeRequest, models: true do ...@@ -640,32 +640,56 @@ describe MergeRequest, models: true do
end end
describe '#all_commits_sha' do describe '#all_commits_sha' do
let(:all_commits_sha) do context 'when merge request is persisted' do
subject.merge_request_diffs.flat_map(&:commits).map(&:sha).uniq let(:all_commits_sha) do
end subject.merge_request_diffs.flat_map(&:commits).map(&:sha).uniq
end
shared_examples 'returning all SHA' do shared_examples 'returning all SHA' do
it 'returns all SHA from all merge_request_diffs' do it 'returns all SHA from all merge_request_diffs' do
expect(subject.merge_request_diffs.size).to eq(2) expect(subject.merge_request_diffs.size).to eq(2)
expect(subject.all_commits_sha).to eq(all_commits_sha) expect(subject.all_commits_sha).to eq(all_commits_sha)
end
end end
end
context 'with a completely different branch' do context 'with a completely different branch' do
before do before do
subject.update(target_branch: 'v1.0.0') subject.update(target_branch: 'v1.0.0')
end
it_behaves_like 'returning all SHA'
end end
it_behaves_like 'returning all SHA' context 'with a branch having no difference' do
before do
subject.update(target_branch: 'v1.1.0')
subject.reload # make sure commits were not cached
end
it_behaves_like 'returning all SHA'
end
end end
context 'with a branch having no difference' do context 'when merge request is not persisted' do
before do context 'when compare commits are set in the service' do
subject.update(target_branch: 'v1.1.0') let(:commit) { spy('commit') }
subject.reload # make sure commits were not cached
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 end
it_behaves_like 'returning all SHA' 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
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