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
cba40a1f
Commit
cba40a1f
authored
Dec 07, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stop sending milestone and labels data over the wire for MR widget
requests
parent
73a79f7e
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
68 additions
and
99 deletions
+68
-99
app/assets/javascripts/vue_merge_request_widget/services/mr_widget_service.js
...ts/vue_merge_request_widget/services/mr_widget_service.js
+1
-1
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+6
-2
app/helpers/issuables_helper.rb
app/helpers/issuables_helper.rb
+2
-2
app/serializers/issuable_entity.rb
app/serializers/issuable_entity.rb
+0
-8
app/serializers/issuable_sidebar_entity.rb
app/serializers/issuable_sidebar_entity.rb
+1
-5
app/serializers/issue_entity.rb
app/serializers/issue_entity.rb
+8
-0
app/serializers/merge_request_serializer.rb
app/serializers/merge_request_serializer.rb
+3
-3
app/serializers/merge_request_widget_entity.rb
app/serializers/merge_request_widget_entity.rb
+1
-4
app/views/projects/merge_requests/show.html.haml
app/views/projects/merge_requests/show.html.haml
+1
-1
changelogs/unreleased/osw-isolate-mr-widget-exposed-attributes.yml
...s/unreleased/osw-isolate-mr-widget-exposed-attributes.yml
+5
-0
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+4
-4
spec/features/merge_requests/mini_pipeline_graph_spec.rb
spec/features/merge_requests/mini_pipeline_graph_spec.rb
+4
-4
spec/fixtures/api/schemas/entities/merge_request_widget.json
spec/fixtures/api/schemas/entities/merge_request_widget.json
+4
-4
spec/serializers/merge_request_serializer_spec.rb
spec/serializers/merge_request_serializer_spec.rb
+27
-21
spec/serializers/merge_request_widget_entity_spec.rb
spec/serializers/merge_request_widget_entity_spec.rb
+1
-40
No files found.
app/assets/javascripts/vue_merge_request_widget/services/mr_widget_service.js
View file @
cba40a1f
...
@@ -6,7 +6,7 @@ Vue.use(VueResource);
...
@@ -6,7 +6,7 @@ Vue.use(VueResource);
export
default
class
MRWidgetService
{
export
default
class
MRWidgetService
{
constructor
(
endpoints
)
{
constructor
(
endpoints
)
{
this
.
mergeResource
=
Vue
.
resource
(
endpoints
.
mergePath
);
this
.
mergeResource
=
Vue
.
resource
(
endpoints
.
mergePath
);
this
.
mergeCheckResource
=
Vue
.
resource
(
endpoints
.
statusPath
);
this
.
mergeCheckResource
=
Vue
.
resource
(
`
${
endpoints
.
statusPath
}
?serializer=widget`
);
this
.
cancelAutoMergeResource
=
Vue
.
resource
(
endpoints
.
cancelAutoMergePath
);
this
.
cancelAutoMergeResource
=
Vue
.
resource
(
endpoints
.
cancelAutoMergePath
);
this
.
removeWIPResource
=
Vue
.
resource
(
endpoints
.
removeWIPPath
);
this
.
removeWIPResource
=
Vue
.
resource
(
endpoints
.
removeWIPPath
);
this
.
removeSourceBranchResource
=
Vue
.
resource
(
endpoints
.
sourceBranchPath
);
this
.
removeSourceBranchResource
=
Vue
.
resource
(
endpoints
.
sourceBranchPath
);
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
cba40a1f
...
@@ -131,7 +131,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
...
@@ -131,7 +131,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
.
new
(
project
,
current_user
,
wip_event:
'unwip'
)
.
new
(
project
,
current_user
,
wip_event:
'unwip'
)
.
execute
(
@merge_request
)
.
execute
(
@merge_request
)
render
json:
serialize
r
.
represen
t
(
@merge_request
)
render
json:
serialize
_widge
t
(
@merge_request
)
end
end
def
commit_change_content
def
commit_change_content
...
@@ -147,7 +147,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
...
@@ -147,7 +147,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
.
new
(
@project
,
current_user
)
.
new
(
@project
,
current_user
)
.
cancel
(
@merge_request
)
.
cancel
(
@merge_request
)
render
json:
serialize
r
.
represen
t
(
@merge_request
)
render
json:
serialize
_widge
t
(
@merge_request
)
end
end
def
merge
def
merge
...
@@ -304,6 +304,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
...
@@ -304,6 +304,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
end
end
end
end
def
serialize_widget
(
merge_request
)
serializer
.
represent
(
merge_request
,
serializer:
'widget'
)
end
def
serializer
def
serializer
MergeRequestSerializer
.
new
(
current_user:
current_user
,
project:
merge_request
.
project
)
MergeRequestSerializer
.
new
(
current_user:
current_user
,
project:
merge_request
.
project
)
end
end
...
...
app/helpers/issuables_helper.rb
View file @
cba40a1f
...
@@ -32,7 +32,7 @@ module IssuablesHelper
...
@@ -32,7 +32,7 @@ module IssuablesHelper
end
end
end
end
def
serialize_issuable
(
issuable
)
def
serialize_issuable
(
issuable
,
serializer:
nil
)
serializer_klass
=
case
issuable
serializer_klass
=
case
issuable
when
Issue
when
Issue
IssueSerializer
IssueSerializer
...
@@ -42,7 +42,7 @@ module IssuablesHelper
...
@@ -42,7 +42,7 @@ module IssuablesHelper
serializer_klass
serializer_klass
.
new
(
current_user:
current_user
,
project:
issuable
.
project
)
.
new
(
current_user:
current_user
,
project:
issuable
.
project
)
.
represent
(
issuable
)
.
represent
(
issuable
,
serializer:
serializer
)
.
to_json
.
to_json
end
end
...
...
app/serializers/issuable_entity.rb
View file @
cba40a1f
...
@@ -3,14 +3,6 @@ class IssuableEntity < Grape::Entity
...
@@ -3,14 +3,6 @@ class IssuableEntity < Grape::Entity
expose
:id
expose
:id
expose
:iid
expose
:iid
expose
:author_id
expose
:description
expose
:description
expose
:lock_version
expose
:milestone_id
expose
:title
expose
:title
expose
:updated_by_id
expose
:created_at
expose
:updated_at
expose
:milestone
,
using:
API
::
Entities
::
Milestone
expose
:labels
,
using:
LabelEntity
end
end
app/serializers/issuable_sidebar_entity.rb
View file @
cba40a1f
class
IssuableSidebarEntity
<
Grape
::
Entity
class
IssuableSidebarEntity
<
Grape
::
Entity
include
TimeTrackableEntity
include
RequestAwareEntity
include
RequestAwareEntity
expose
:participants
,
using:
::
API
::
Entities
::
UserBasic
do
|
issuable
|
expose
:participants
,
using:
::
API
::
Entities
::
UserBasic
do
|
issuable
|
...
@@ -8,9 +9,4 @@ class IssuableSidebarEntity < Grape::Entity
...
@@ -8,9 +9,4 @@ class IssuableSidebarEntity < Grape::Entity
expose
:subscribed
do
|
issuable
|
expose
:subscribed
do
|
issuable
|
issuable
.
subscribed?
(
request
.
current_user
,
issuable
.
project
)
issuable
.
subscribed?
(
request
.
current_user
,
issuable
.
project
)
end
end
expose
:time_estimate
expose
:total_time_spent
expose
:human_time_estimate
expose
:human_total_time_spent
end
end
app/serializers/issue_entity.rb
View file @
cba40a1f
...
@@ -2,7 +2,15 @@ class IssueEntity < IssuableEntity
...
@@ -2,7 +2,15 @@ class IssueEntity < IssuableEntity
include
TimeTrackableEntity
include
TimeTrackableEntity
expose
:state
expose
:state
expose
:milestone_id
expose
:updated_by_id
expose
:created_at
expose
:updated_at
expose
:deleted_at
expose
:deleted_at
expose
:milestone
,
using:
API
::
Entities
::
Milestone
expose
:labels
,
using:
LabelEntity
expose
:lock_version
expose
:author_id
expose
:confidential
expose
:confidential
expose
:discussion_locked
expose
:discussion_locked
expose
:assignees
,
using:
API
::
Entities
::
UserBasic
expose
:assignees
,
using:
API
::
Entities
::
UserBasic
...
...
app/serializers/merge_request_serializer.rb
View file @
cba40a1f
class
MergeRequestSerializer
<
BaseSerializer
class
MergeRequestSerializer
<
BaseSerializer
# This overrided method takes care of which entity should be used
# This overrided method takes care of which entity should be used
# to serialize the `merge_request` based on `
basic
` key in `opts` param.
# to serialize the `merge_request` based on `
serializer
` key in `opts` param.
# Hence, `entity` doesn't need to be declared on the class scope.
# Hence, `entity` doesn't need to be declared on the class scope.
def
represent
(
merge_request
,
opts
=
{})
def
represent
(
merge_request
,
opts
=
{})
entity
=
entity
=
case
opts
[
:serializer
]
case
opts
[
:serializer
]
when
'basic'
,
'sidebar'
when
'basic'
,
'sidebar'
MergeRequestBasicEntity
MergeRequestBasicEntity
else
when
'widget'
MergeRequestEntity
MergeRequest
Widget
Entity
end
end
super
(
merge_request
,
opts
,
entity
)
super
(
merge_request
,
opts
,
entity
)
...
...
app/serializers/merge_request_entity.rb
→
app/serializers/merge_request_
widget_
entity.rb
View file @
cba40a1f
class
MergeRequestEntity
<
IssuableEntity
class
MergeRequestWidgetEntity
<
IssuableEntity
include
TimeTrackableEntity
expose
:state
expose
:state
expose
:deleted_at
expose
:in_progress_merge_commit_sha
expose
:in_progress_merge_commit_sha
expose
:merge_commit_sha
expose
:merge_commit_sha
expose
:merge_error
expose
:merge_error
...
...
app/views/projects/merge_requests/show.html.haml
View file @
cba40a1f
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
-# haml-lint:disable InlineJavaScript
-# haml-lint:disable InlineJavaScript
:javascript
:javascript
window
.
gl
=
window
.
gl
||
{};
window
.
gl
=
window
.
gl
||
{};
window
.
gl
.
mrWidgetData
=
#{
serialize_issuable
(
@merge_request
)
}
window
.
gl
.
mrWidgetData
=
#{
serialize_issuable
(
@merge_request
,
serializer:
'widget'
)
}
#js-vue-mr-widget
.mr-widget
#js-vue-mr-widget
.mr-widget
...
...
changelogs/unreleased/osw-isolate-mr-widget-exposed-attributes.yml
0 → 100644
View file @
cba40a1f
---
title
:
Stop sending milestone and labels data over the wire for MR widget requests
merge_request
:
author
:
type
:
performance
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
cba40a1f
...
@@ -91,11 +91,11 @@ describe Projects::MergeRequestsController do
...
@@ -91,11 +91,11 @@ describe Projects::MergeRequestsController do
end
end
end
end
context
'with
out basic
serializer param'
do
context
'with
widget
serializer param'
do
it
'renders
the merge request in the json format
'
do
it
'renders
widget MR entity as json
'
do
go
(
format: :json
)
go
(
serializer:
'widget'
,
format: :json
)
expect
(
response
).
to
match_response_schema
(
'entities/merge_request'
)
expect
(
response
).
to
match_response_schema
(
'entities/merge_request
_widget
'
)
end
end
end
end
end
end
...
...
spec/features/merge_requests/mini_pipeline_graph_spec.rb
View file @
cba40a1f
...
@@ -15,8 +15,8 @@ feature 'Mini Pipeline Graph', :js do
...
@@ -15,8 +15,8 @@ feature 'Mini Pipeline Graph', :js do
visit_merge_request
visit_merge_request
end
end
def
visit_merge_request
(
format
=
:htm
l
)
def
visit_merge_request
(
format
: :html
,
serializer:
ni
l
)
visit
project_merge_request_path
(
project
,
merge_request
,
format:
format
)
visit
project_merge_request_path
(
project
,
merge_request
,
format:
format
,
serializer:
serializer
)
end
end
it
'should display a mini pipeline graph'
do
it
'should display a mini pipeline graph'
do
...
@@ -33,12 +33,12 @@ feature 'Mini Pipeline Graph', :js do
...
@@ -33,12 +33,12 @@ feature 'Mini Pipeline Graph', :js do
end
end
it
'avoids repeated database queries'
do
it
'avoids repeated database queries'
do
before
=
ActiveRecord
::
QueryRecorder
.
new
{
visit_merge_request
(
:json
)
}
before
=
ActiveRecord
::
QueryRecorder
.
new
{
visit_merge_request
(
format: :json
,
serializer:
'widget'
)
}
create
(
:ci_build
,
pipeline:
pipeline
,
legacy_artifacts_file:
artifacts_file2
)
create
(
:ci_build
,
pipeline:
pipeline
,
legacy_artifacts_file:
artifacts_file2
)
create
(
:ci_build
,
pipeline:
pipeline
,
when:
'manual'
)
create
(
:ci_build
,
pipeline:
pipeline
,
when:
'manual'
)
after
=
ActiveRecord
::
QueryRecorder
.
new
{
visit_merge_request
(
:json
)
}
after
=
ActiveRecord
::
QueryRecorder
.
new
{
visit_merge_request
(
format: :json
,
serializer:
'widget'
)
}
expect
(
before
.
count
).
to
eq
(
after
.
count
)
expect
(
before
.
count
).
to
eq
(
after
.
count
)
expect
(
before
.
cached_count
).
to
eq
(
after
.
cached_count
)
expect
(
before
.
cached_count
).
to
eq
(
after
.
cached_count
)
...
...
spec/fixtures/api/schemas/entities/merge_request.json
→
spec/fixtures/api/schemas/entities/merge_request
_widget
.json
View file @
cba40a1f
...
@@ -80,15 +80,15 @@
...
@@ -80,15 +80,15 @@
"target_branch_tree_path"
:
{
"type"
:
"string"
},
"target_branch_tree_path"
:
{
"type"
:
"string"
},
"source_branch_path"
:
{
"type"
:
"string"
},
"source_branch_path"
:
{
"type"
:
"string"
},
"conflict_resolution_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"conflict_resolution_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"cancel_merge_when_pipeline_succeeds_path"
:
{
"type"
:
"string"
},
"cancel_merge_when_pipeline_succeeds_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"create_issue_to_resolve_discussions_path"
:
{
"type"
:
"string"
},
"create_issue_to_resolve_discussions_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"merge_path"
:
{
"type"
:
"string"
},
"merge_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"cherry_pick_in_fork_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"cherry_pick_in_fork_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"revert_in_fork_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"revert_in_fork_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"email_patches_path"
:
{
"type"
:
"string"
},
"email_patches_path"
:
{
"type"
:
"string"
},
"plain_diff_path"
:
{
"type"
:
"string"
},
"plain_diff_path"
:
{
"type"
:
"string"
},
"status_path"
:
{
"type"
:
"string"
},
"status_path"
:
{
"type"
:
"string"
},
"new_blob_path"
:
{
"type"
:
"string"
},
"new_blob_path"
:
{
"type"
:
[
"string"
,
"null"
]
},
"merge_check_path"
:
{
"type"
:
"string"
},
"merge_check_path"
:
{
"type"
:
"string"
},
"ci_environments_status_path"
:
{
"type"
:
"string"
},
"ci_environments_status_path"
:
{
"type"
:
"string"
},
"merge_commit_message_with_description"
:
{
"type"
:
"string"
},
"merge_commit_message_with_description"
:
{
"type"
:
"string"
},
...
...
spec/serializers/merge_request_serializer_spec.rb
View file @
cba40a1f
require
'spec_helper'
require
'spec_helper'
describe
MergeRequestSerializer
do
describe
MergeRequestSerializer
do
let
(
:user
)
{
build_stubbed
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:merge_request
)
{
build_stubbed
(
:merge_request
)
}
let
(
:resource
)
{
create
(
:merge_request
)
}
let
(
:json_entity
)
do
let
(
:serializer
)
do
described_class
.
new
(
current_user:
user
)
described_class
.
new
(
current_user:
user
)
.
represent
(
resource
,
serializer:
serializer
)
.
with_indifferent_access
end
end
describe
'#represent'
do
context
'widget merge request serialization'
do
let
(
:opts
)
{
{
serializer:
serializer_entity
}
}
let
(
:serializer
)
{
'widget'
}
subject
{
serializer
.
represent
(
merge_request
,
serializer:
serializer_entity
)
}
context
'when passing basic serializer param'
do
it
'matches issue json schema'
do
let
(
:serializer_entity
)
{
'basic'
}
expect
(
json_entity
).
to
match_schema
(
'entities/merge_request_widget'
)
end
end
it
'calls super class #represent with correct params'
do
context
'sidebar merge request serialization'
do
expect_any_instance_of
(
BaseSerializer
).
to
receive
(
:represent
)
let
(
:serializer
)
{
'sidebar'
}
.
with
(
merge_request
,
opts
,
MergeRequestBasicEntity
)
subject
it
'matches basic merge request json schema'
do
e
nd
e
xpect
(
json_entity
).
to
match_schema
(
'entities/merge_request_basic'
)
end
end
end
context
'when serializer param is falsy'
do
context
'basic merge request serialization'
do
let
(
:serializer_entity
)
{
nil
}
let
(
:serializer
)
{
'basic'
}
it
'matches basic merge request json schema'
do
expect
(
json_entity
).
to
match_schema
(
'entities/merge_request_basic'
)
end
end
it
'calls super class #represent with correct params'
do
context
'no serializer'
do
expect_any_instance_of
(
BaseSerializer
).
to
receive
(
:represent
)
let
(
:serializer
)
{
nil
}
.
with
(
merge_request
,
opts
,
MergeRequestEntity
)
subject
it
'raises an error'
do
e
nd
e
xpect
{
json_entity
}.
to
raise_error
(
NoMethodError
)
end
end
end
end
end
end
spec/serializers/merge_request_entity_spec.rb
→
spec/serializers/merge_request_
widget_
entity_spec.rb
View file @
cba40a1f
require
'spec_helper'
require
'spec_helper'
describe
MergeRequestEntity
do
describe
MergeRequest
Widget
Entity
do
let
(
:project
)
{
create
:project
,
:repository
}
let
(
:project
)
{
create
:project
,
:repository
}
let
(
:resource
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:resource
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
...
@@ -35,33 +35,6 @@ describe MergeRequestEntity do
...
@@ -35,33 +35,6 @@ describe MergeRequestEntity do
end
end
end
end
it
'includes issues_links'
do
issues_links
=
subject
[
:issues_links
]
expect
(
issues_links
).
to
include
(
:closing
,
:mentioned_but_not_closing
,
:assign_to_closing
)
end
it
'has Issuable attributes'
do
expect
(
subject
).
to
include
(
:id
,
:iid
,
:author_id
,
:description
,
:lock_version
,
:milestone_id
,
:title
,
:updated_by_id
,
:created_at
,
:updated_at
,
:milestone
,
:labels
)
end
it
'has time estimation attributes'
do
expect
(
subject
).
to
include
(
:time_estimate
,
:total_time_spent
,
:human_time_estimate
,
:human_total_time_spent
)
end
it
'has important MergeRequest attributes'
do
expect
(
subject
).
to
include
(
:state
,
:deleted_at
,
:diff_head_sha
,
:merge_commit_message
,
:has_conflicts
,
:has_ci
,
:merge_path
,
:conflict_resolution_path
,
:cancel_merge_when_pipeline_succeeds_path
,
:create_issue_to_resolve_discussions_path
,
:source_branch_path
,
:target_branch_commits_path
,
:target_branch_tree_path
,
:commits_count
,
:merge_ongoing
,
:ff_only_enabled
)
end
it
'has email_patches_path'
do
it
'has email_patches_path'
do
expect
(
subject
[
:email_patches_path
])
expect
(
subject
[
:email_patches_path
])
.
to
eq
(
"/
#{
resource
.
project
.
full_path
}
/merge_requests/
#{
resource
.
iid
}
.patch"
)
.
to
eq
(
"/
#{
resource
.
project
.
full_path
}
/merge_requests/
#{
resource
.
iid
}
.patch"
)
...
@@ -116,18 +89,6 @@ describe MergeRequestEntity do
...
@@ -116,18 +89,6 @@ describe MergeRequestEntity do
end
end
end
end
it
'includes merge_event'
do
create
(
:event
,
:merged
,
author:
user
,
project:
resource
.
project
,
target:
resource
)
expect
(
subject
[
:merge_event
]).
to
include
(
:author
,
:updated_at
)
end
it
'includes closed_event'
do
create
(
:event
,
:closed
,
author:
user
,
project:
resource
.
project
,
target:
resource
)
expect
(
subject
[
:closed_event
]).
to
include
(
:author
,
:updated_at
)
end
describe
'diverged_commits_count'
do
describe
'diverged_commits_count'
do
context
'when MR open and its diverging'
do
context
'when MR open and its diverging'
do
it
'returns diverged commits count'
do
it
'returns diverged commits count'
do
...
...
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