Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
1f54c921
Commit
1f54c921
authored
Oct 03, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce method calls while evaluating Projects::MergeRequestsController#show.json
parent
ccfe6860
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
53 additions
and
31 deletions
+53
-31
app/models/merge_request.rb
app/models/merge_request.rb
+2
-3
app/presenters/merge_request_presenter.rb
app/presenters/merge_request_presenter.rb
+1
-1
app/serializers/merge_request_entity.rb
app/serializers/merge_request_entity.rb
+0
-2
app/views/projects/issues/_merge_requests.html.haml
app/views/projects/issues/_merge_requests.html.haml
+2
-2
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+0
-12
spec/fixtures/api/schemas/entities/merge_request.json
spec/fixtures/api/schemas/entities/merge_request.json
+1
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+43
-0
spec/presenters/merge_request_presenter_spec.rb
spec/presenters/merge_request_presenter_spec.rb
+4
-0
spec/serializers/merge_request_entity_spec.rb
spec/serializers/merge_request_entity_spec.rb
+0
-10
No files found.
app/models/merge_request.rb
View file @
1f54c921
...
...
@@ -734,10 +734,9 @@ class MergeRequest < ActiveRecord::Base
end
def
has_ci?
has_ci_integration
=
source_project
.
try
(
:ci_service
)
uses_gitlab_ci
=
all_pipelines
.
any?
return
false
if
has_no_commits?
(
has_ci_integration
||
uses_gitlab_ci
)
&&
commits
.
any?
!!
(
head_pipeline_id
||
all_pipelines
.
any?
||
source_project
&
.
ci_service
)
end
def
branch_missing?
...
...
app/presenters/merge_request_presenter.rb
View file @
1f54c921
...
...
@@ -31,7 +31,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
end
def
remove_wip_path
if
can?
(
current_user
,
:update_merge_request
,
merge_request
.
project
)
if
work_in_progress?
&&
can?
(
current_user
,
:update_merge_request
,
merge_request
.
project
)
remove_wip_project_merge_request_path
(
project
,
merge_request
)
end
end
...
...
app/serializers/merge_request_entity.rb
View file @
1f54c921
...
...
@@ -18,7 +18,6 @@ class MergeRequestEntity < IssuableEntity
expose
:closed_event
,
using:
EventEntity
# User entities
expose
:author
,
using:
UserEntity
expose
:merge_user
,
using:
UserEntity
# Diff sha's
...
...
@@ -26,7 +25,6 @@ class MergeRequestEntity < IssuableEntity
merge_request
.
diff_head_sha
if
merge_request
.
diff_head_commit
end
expose
:merge_commit_sha
expose
:merge_commit_message
expose
:head_pipeline
,
with:
PipelineDetailsEntity
,
as: :pipeline
...
...
app/views/projects/issues/_merge_requests.html.haml
View file @
1f54c921
...
...
@@ -2,13 +2,13 @@
%h2
.merge-requests-title
=
pluralize
(
@merge_requests
.
count
,
'Related Merge Request'
)
%ul
.unstyled-list.related-merge-requests
-
has_any_
ci
=
@merge_requests
.
any?
(
&
:head_pipeline
)
-
has_any_
head_pipeline
=
@merge_requests
.
any?
(
&
:head_pipeline_id
)
-
@merge_requests
.
each
do
|
merge_request
|
%li
%span
.merge-request-ci-status
-
if
merge_request
.
head_pipeline
=
render_pipeline_status
(
merge_request
.
head_pipeline
)
-
elsif
has_any_
ci
-
elsif
has_any_
head_pipeline
=
icon
(
'blank fw'
)
%span
.merge-request-id
=
merge_request
.
to_reference
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
1f54c921
...
...
@@ -96,18 +96,6 @@ describe Projects::MergeRequestsController do
expect
(
response
).
to
match_response_schema
(
'entities/merge_request'
)
end
end
context
'number of queries'
,
:request_store
do
it
'verifies number of queries'
do
# pre-create objects
merge_request
recorded
=
ActiveRecord
::
QueryRecorder
.
new
{
go
(
format: :json
)
}
expect
(
recorded
.
count
).
to
be_within
(
5
).
of
(
30
)
expect
(
recorded
.
cached_count
).
to
eq
(
0
)
end
end
end
describe
"as diff"
do
...
...
spec/fixtures/api/schemas/entities/merge_request.json
View file @
1f54c921
...
...
@@ -93,7 +93,7 @@
"merge_commit_message_with_description"
:
{
"type"
:
"string"
},
"diverged_commits_count"
:
{
"type"
:
"integer"
},
"commit_change_content_path"
:
{
"type"
:
"string"
},
"remove_wip_path"
:
{
"type"
:
"string"
},
"remove_wip_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"commits_count"
:
{
"type"
:
"integer"
},
"remove_source_branch"
:
{
"type"
:
[
"boolean"
,
"null"
]
},
"merge_ongoing"
:
{
"type"
:
"boolean"
}
...
...
spec/models/merge_request_spec.rb
View file @
1f54c921
...
...
@@ -791,6 +791,49 @@ describe MergeRequest do
end
end
describe
'#has_ci?'
do
let
(
:merge_request
)
{
build_stubbed
(
:merge_request
)
}
context
'has ci'
do
it
'returns true if MR has head_pipeline_id and commits'
do
allow
(
merge_request
).
to
receive_message_chain
(
:source_project
,
:ci_service
)
{
nil
}
allow
(
merge_request
).
to
receive
(
:head_pipeline_id
)
{
double
}
allow
(
merge_request
).
to
receive
(
:has_no_commits?
)
{
false
}
expect
(
merge_request
.
has_ci?
).
to
be
(
true
)
end
it
'returns true if MR has any pipeline and commits'
do
allow
(
merge_request
).
to
receive_message_chain
(
:source_project
,
:ci_service
)
{
nil
}
allow
(
merge_request
).
to
receive
(
:head_pipeline_id
)
{
nil
}
allow
(
merge_request
).
to
receive
(
:has_no_commits?
)
{
false
}
allow
(
merge_request
).
to
receive
(
:all_pipelines
)
{
[
double
]
}
expect
(
merge_request
.
has_ci?
).
to
be
(
true
)
end
it
'returns true if MR has CI service and commits'
do
allow
(
merge_request
).
to
receive_message_chain
(
:source_project
,
:ci_service
)
{
double
}
allow
(
merge_request
).
to
receive
(
:head_pipeline_id
)
{
nil
}
allow
(
merge_request
).
to
receive
(
:has_no_commits?
)
{
false
}
allow
(
merge_request
).
to
receive
(
:all_pipelines
)
{
[]
}
expect
(
merge_request
.
has_ci?
).
to
be
(
true
)
end
end
context
'has no ci'
do
it
'returns false if MR has no CI service nor pipeline, and no commits'
do
allow
(
merge_request
).
to
receive_message_chain
(
:source_project
,
:ci_service
)
{
nil
}
allow
(
merge_request
).
to
receive
(
:head_pipeline_id
)
{
nil
}
allow
(
merge_request
).
to
receive
(
:all_pipelines
)
{
[]
}
allow
(
merge_request
).
to
receive
(
:has_no_commits?
)
{
true
}
expect
(
merge_request
.
has_ci?
).
to
be
(
false
)
end
end
end
describe
'#all_pipelines'
do
shared_examples
'returning pipelines with proper ordering'
do
let!
(
:all_pipelines
)
do
...
...
spec/presenters/merge_request_presenter_spec.rb
View file @
1f54c921
...
...
@@ -300,6 +300,10 @@ describe MergeRequestPresenter do
described_class
.
new
(
resource
,
current_user:
user
).
remove_wip_path
end
before
do
allow
(
resource
).
to
receive
(
:work_in_progress?
).
and_return
(
true
)
end
context
'when merge request enabled and has permission'
do
it
'has remove_wip_path'
do
allow
(
project
).
to
receive
(
:merge_requests_enabled?
)
{
true
}
...
...
spec/serializers/merge_request_entity_spec.rb
View file @
1f54c921
...
...
@@ -11,16 +11,6 @@ describe MergeRequestEntity do
described_class
.
new
(
resource
,
request:
request
).
as_json
end
it
'includes author'
do
req
=
double
(
'request'
)
author_payload
=
UserEntity
.
represent
(
resource
.
author
,
request:
req
)
.
as_json
expect
(
subject
[
:author
]).
to
eq
(
author_payload
)
end
it
'includes pipeline'
do
req
=
double
(
'request'
,
current_user:
user
)
pipeline
=
build_stubbed
(
:ci_pipeline
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment