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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
cfcc113f
Commit
cfcc113f
authored
Mar 30, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose code_navigation_path for merge request diffs
It'll help FE to implement code intelligence for MRs
parent
260e3c61
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
97 additions
and
52 deletions
+97
-52
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+1
-13
app/models/ci/build.rb
app/models/ci/build.rb
+0
-2
app/serializers/diff_file_entity.rb
app/serializers/diff_file_entity.rb
+4
-0
app/serializers/diffs_entity.rb
app/serializers/diffs_entity.rb
+9
-1
app/serializers/paginated_diff_entity.rb
app/serializers/paginated_diff_entity.rb
+5
-1
app/views/projects/blob/_blob.html.haml
app/views/projects/blob/_blob.html.haml
+2
-3
lib/gitlab/code_navigation_path.rb
lib/gitlab/code_navigation_path.rb
+37
-0
spec/controllers/projects/blob_controller_spec.rb
spec/controllers/projects/blob_controller_spec.rb
+0
-26
spec/lib/gitlab/code_navigation_path_spec.rb
spec/lib/gitlab/code_navigation_path_spec.rb
+31
-0
spec/serializers/diff_file_entity_spec.rb
spec/serializers/diff_file_entity_spec.rb
+5
-3
spec/serializers/diffs_entity_spec.rb
spec/serializers/diffs_entity_spec.rb
+1
-1
spec/serializers/diffs_metadata_entity_spec.rb
spec/serializers/diffs_metadata_entity_spec.rb
+2
-2
No files found.
app/controllers/projects/blob_controller.rb
View file @
cfcc113f
...
@@ -208,24 +208,12 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -208,24 +208,12 @@ class Projects::BlobController < Projects::ApplicationController
.
last_for_path
(
@repository
,
@ref
,
@path
).
sha
.
last_for_path
(
@repository
,
@ref
,
@path
).
sha
end
end
def
set_code_navigation_build
return
if
Feature
.
disabled?
(
:code_navigation
,
@project
)
artifact
=
Ci
::
JobArtifact
.
for_sha
(
@blob
.
commit_id
,
@project
.
id
)
.
for_job_name
(
Ci
::
Build
::
CODE_NAVIGATION_JOB_NAME
)
.
last
@code_navigation_build
=
artifact
&
.
job
end
def
show_html
def
show_html
environment_params
=
@repository
.
branch_exists?
(
@ref
)
?
{
ref:
@ref
}
:
{
commit:
@commit
}
environment_params
=
@repository
.
branch_exists?
(
@ref
)
?
{
ref:
@ref
}
:
{
commit:
@commit
}
environment_params
[
:find_latest
]
=
true
environment_params
[
:find_latest
]
=
true
@environment
=
EnvironmentsFinder
.
new
(
@project
,
current_user
,
environment_params
).
execute
.
last
@environment
=
EnvironmentsFinder
.
new
(
@project
,
current_user
,
environment_params
).
execute
.
last
@last_commit
=
@repository
.
last_commit_for_path
(
@commit
.
id
,
@blob
.
path
)
@last_commit
=
@repository
.
last_commit_for_path
(
@commit
.
id
,
@blob
.
path
)
set_code_navigation_build
@code_navigation_path
=
Gitlab
::
CodeNavigationPath
.
new
(
@project
,
@blob
.
commit_id
).
full_json_path_for
(
@blob
.
path
)
render
'show'
render
'show'
end
end
...
...
app/models/ci/build.rb
View file @
cfcc113f
...
@@ -33,8 +33,6 @@ module Ci
...
@@ -33,8 +33,6 @@ module Ci
scheduler_failure:
2
scheduler_failure:
2
}.
freeze
}.
freeze
CODE_NAVIGATION_JOB_NAME
=
'code_navigation'
has_one
:deployment
,
as: :deployable
,
class_name:
'Deployment'
has_one
:deployment
,
as: :deployable
,
class_name:
'Deployment'
has_one
:resource
,
class_name:
'Ci::Resource'
,
inverse_of: :build
has_one
:resource
,
class_name:
'Ci::Resource'
,
inverse_of: :build
has_many
:trace_sections
,
class_name:
'Ci::BuildTraceSection'
has_many
:trace_sections
,
class_name:
'Ci::BuildTraceSection'
...
...
app/serializers/diff_file_entity.rb
View file @
cfcc113f
...
@@ -64,6 +64,10 @@ class DiffFileEntity < DiffFileBaseEntity
...
@@ -64,6 +64,10 @@ class DiffFileEntity < DiffFileBaseEntity
# Used for parallel diffs
# Used for parallel diffs
expose
:parallel_diff_lines
,
using:
DiffLineParallelEntity
,
if:
->
(
diff_file
,
options
)
{
parallel_diff_view?
(
options
,
diff_file
)
&&
diff_file
.
text?
}
expose
:parallel_diff_lines
,
using:
DiffLineParallelEntity
,
if:
->
(
diff_file
,
options
)
{
parallel_diff_view?
(
options
,
diff_file
)
&&
diff_file
.
text?
}
expose
:code_navigation_path
,
if:
->
(
diff_file
)
{
options
[
:code_navigation_path
]
}
do
|
diff_file
|
options
[
:code_navigation_path
].
full_json_path_for
(
diff_file
.
new_path
)
end
private
private
def
parallel_diff_view?
(
options
,
diff_file
)
def
parallel_diff_view?
(
options
,
diff_file
)
...
...
app/serializers/diffs_entity.rb
View file @
cfcc113f
...
@@ -70,13 +70,21 @@ class DiffsEntity < Grape::Entity
...
@@ -70,13 +70,21 @@ class DiffsEntity < Grape::Entity
expose
:diff_files
do
|
diffs
,
options
|
expose
:diff_files
do
|
diffs
,
options
|
submodule_links
=
Gitlab
::
SubmoduleLinks
.
new
(
merge_request
.
project
.
repository
)
submodule_links
=
Gitlab
::
SubmoduleLinks
.
new
(
merge_request
.
project
.
repository
)
DiffFileEntity
.
represent
(
diffs
.
diff_files
,
options
.
merge
(
submodule_links:
submodule_links
))
code_navigation_path
=
Gitlab
::
CodeNavigationPath
.
new
(
merge_request
.
project
,
diffs
.
diff_refs
.
head_sha
)
DiffFileEntity
.
represent
(
diffs
.
diff_files
,
options
.
merge
(
submodule_links:
submodule_links
,
code_navigation_path:
code_navigation_path
))
end
end
expose
:merge_request_diffs
,
using:
MergeRequestDiffEntity
,
if:
->
(
_
,
options
)
{
options
[
:merge_request_diffs
]
&
.
any?
}
do
|
diffs
|
expose
:merge_request_diffs
,
using:
MergeRequestDiffEntity
,
if:
->
(
_
,
options
)
{
options
[
:merge_request_diffs
]
&
.
any?
}
do
|
diffs
|
options
[
:merge_request_diffs
]
options
[
:merge_request_diffs
]
end
end
expose
:definition_path_prefix
,
if:
->
(
diff_file
)
{
Feature
.
enabled?
(
:code_navigation
,
merge_request
.
project
)
}
do
|
diffs
|
project_blob_path
(
merge_request
.
project
,
diffs
.
diff_refs
.
head_sha
)
end
def
merge_request
def
merge_request
options
[
:merge_request
]
options
[
:merge_request
]
end
end
...
...
app/serializers/paginated_diff_entity.rb
View file @
cfcc113f
...
@@ -10,7 +10,11 @@ class PaginatedDiffEntity < Grape::Entity
...
@@ -10,7 +10,11 @@ class PaginatedDiffEntity < Grape::Entity
expose
:diff_files
do
|
diffs
,
options
|
expose
:diff_files
do
|
diffs
,
options
|
submodule_links
=
Gitlab
::
SubmoduleLinks
.
new
(
merge_request
.
project
.
repository
)
submodule_links
=
Gitlab
::
SubmoduleLinks
.
new
(
merge_request
.
project
.
repository
)
DiffFileEntity
.
represent
(
diffs
.
diff_files
,
options
.
merge
(
submodule_links:
submodule_links
))
code_navigation_path
=
Gitlab
::
CodeNavigationPath
.
new
(
merge_request
.
project
,
diffs
.
diff_refs
.
head_sha
)
DiffFileEntity
.
represent
(
diffs
.
diff_files
,
options
.
merge
(
submodule_links:
submodule_links
,
code_navigation_path:
code_navigation_path
))
end
end
expose
:pagination
do
expose
:pagination
do
...
...
app/views/projects/blob/_blob.html.haml
View file @
cfcc113f
...
@@ -9,9 +9,8 @@
...
@@ -9,9 +9,8 @@
=
render
"projects/blob/auxiliary_viewer"
,
blob:
blob
=
render
"projects/blob/auxiliary_viewer"
,
blob:
blob
#blob-content-holder
.blob-content-holder
#blob-content-holder
.blob-content-holder
-
if
@code_navigation_build
-
if
@code_navigation_path
-
code_nav_url
=
raw_project_job_artifacts_url
(
@project
,
@code_navigation_build
,
path:
"lsif/
#{
blob
.
path
}
"
)
#js-code-navigation
{
data:
{
code_nav_url:
@code_navigation_path
,
definition_path_prefix:
project_blob_path
(
@project
,
@ref
)
}
}
#js-code-navigation
{
data:
{
code_nav_url:
"#{code_nav_url}.json"
,
definition_path_prefix:
project_blob_path
(
@project
,
@ref
)
}
}
%article
.file-holder
%article
.file-holder
=
render
'projects/blob/header'
,
blob:
blob
=
render
'projects/blob/header'
,
blob:
blob
=
render
'projects/blob/content'
,
blob:
blob
=
render
'projects/blob/content'
,
blob:
blob
lib/gitlab/code_navigation_path.rb
0 → 100644
View file @
cfcc113f
# frozen_string_literal: true
module
Gitlab
class
CodeNavigationPath
include
Gitlab
::
Utils
::
StrongMemoize
include
Gitlab
::
Routing
CODE_NAVIGATION_JOB_NAME
=
'code_navigation'
def
initialize
(
project
,
commit_sha
)
@project
=
project
@commit_sha
=
commit_sha
end
def
full_json_path_for
(
path
)
return
if
Feature
.
disabled?
(
:code_navigation
,
project
)
return
unless
build
raw_project_job_artifacts_path
(
project
,
build
,
path:
"lsif/
#{
path
}
.json"
)
end
private
attr_reader
:project
,
:commit_sha
def
build
strong_memoize
(
:build
)
do
artifact
=
::
Ci
::
JobArtifact
.
for_sha
(
commit_sha
,
project
.
id
)
.
for_job_name
(
CODE_NAVIGATION_JOB_NAME
)
.
last
artifact
&
.
job
end
end
end
end
spec/controllers/projects/blob_controller_spec.rb
View file @
cfcc113f
...
@@ -118,32 +118,6 @@ describe Projects::BlobController do
...
@@ -118,32 +118,6 @@ describe Projects::BlobController do
end
end
end
end
end
end
context
'when there is an artifact with code navigation data'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
)
}
let!
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
Ci
::
Build
::
CODE_NAVIGATION_JOB_NAME
)
}
let!
(
:artifact
)
{
create
(
:ci_job_artifact
,
:lsif
,
job:
job
)
}
let
(
:id
)
{
'master/README.md'
}
it
'assigns code_navigation_build variable'
do
request
expect
(
assigns
[
:code_navigation_build
]).
to
eq
(
job
)
end
context
'when code_navigation feature is disabled'
do
before
do
stub_feature_flags
(
code_navigation:
false
)
end
it
'does not assign code_navigation_build variable'
do
request
expect
(
assigns
[
:code_navigation_build
]).
to
be_nil
end
end
end
end
end
describe
'GET diff'
do
describe
'GET diff'
do
...
...
spec/lib/gitlab/code_navigation_path_spec.rb
0 → 100644
View file @
cfcc113f
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
CodeNavigationPath
do
context
'when there is an artifact with code navigation data'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:sha
)
{
project
.
commit
.
id
}
let
(
:build_name
)
{
Gitlab
::
CodeNavigationPath
::
CODE_NAVIGATION_JOB_NAME
}
let
(
:path
)
{
'lib/app.rb'
}
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
sha:
sha
)
}
let!
(
:job
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
name:
build_name
)
}
let!
(
:artifact
)
{
create
(
:ci_job_artifact
,
:lsif
,
job:
job
)
}
subject
{
described_class
.
new
(
project
,
sha
).
full_json_path_for
(
path
)
}
it
'assigns code_navigation_build variable'
do
expect
(
subject
).
to
eq
(
"/
#{
project
.
full_path
}
/-/jobs/
#{
job
.
id
}
/artifacts/raw/lsif/
#{
path
}
.json"
)
end
context
'when code_navigation feature is disabled'
do
before
do
stub_feature_flags
(
code_navigation:
false
)
end
it
'does not assign code_navigation_build variable'
do
expect
(
subject
).
to
be_nil
end
end
end
end
spec/serializers/diff_file_entity_spec.rb
View file @
cfcc113f
...
@@ -5,7 +5,7 @@ require 'spec_helper'
...
@@ -5,7 +5,7 @@ require 'spec_helper'
describe
DiffFileEntity
do
describe
DiffFileEntity
do
include
RepoHelpers
include
RepoHelpers
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:repository
)
{
project
.
repository
}
let
(
:commit
)
{
project
.
commit
(
sample_commit
.
id
)
}
let
(
:commit
)
{
project
.
commit
(
sample_commit
.
id
)
}
let
(
:diff_refs
)
{
commit
.
diff_refs
}
let
(
:diff_refs
)
{
commit
.
diff_refs
}
...
@@ -21,10 +21,11 @@ describe DiffFileEntity do
...
@@ -21,10 +21,11 @@ describe DiffFileEntity do
end
end
context
'when there is a merge request'
do
context
'when there is a merge request'
do
let_it_be
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:code_navigation_path
)
{
Gitlab
::
CodeNavigationPath
.
new
(
project
,
project
.
commit
.
sha
)
}
let
(
:request
)
{
EntityRequest
.
new
(
project:
project
,
current_user:
user
)
}
let
(
:request
)
{
EntityRequest
.
new
(
project:
project
,
current_user:
user
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
}
let
(
:entity
)
{
described_class
.
new
(
diff_file
,
options
.
merge
(
request:
request
,
merge_request:
merge_request
,
code_navigation_path:
code_navigation_path
))
}
let
(
:entity
)
{
described_class
.
new
(
diff_file
,
options
.
merge
(
request:
request
,
merge_request:
merge_request
))
}
let
(
:exposed_urls
)
{
%i(edit_path view_path context_lines_path)
}
let
(
:exposed_urls
)
{
%i(edit_path view_path context_lines_path)
}
it_behaves_like
'diff file entity'
it_behaves_like
'diff file entity'
...
@@ -32,6 +33,7 @@ describe DiffFileEntity do
...
@@ -32,6 +33,7 @@ describe DiffFileEntity do
it
'exposes additional attributes'
do
it
'exposes additional attributes'
do
expect
(
subject
).
to
include
(
*
exposed_urls
)
expect
(
subject
).
to
include
(
*
exposed_urls
)
expect
(
subject
).
to
include
(
:replaced_view_path
)
expect
(
subject
).
to
include
(
:replaced_view_path
)
expect
(
subject
).
to
include
(
:code_navigation_path
)
end
end
it
'points all urls to merge request target project'
do
it
'points all urls to merge request target project'
do
...
...
spec/serializers/diffs_entity_spec.rb
View file @
cfcc113f
...
@@ -23,7 +23,7 @@ describe DiffsEntity do
...
@@ -23,7 +23,7 @@ describe DiffsEntity do
:start_version
,
:latest_diff
,
:latest_version_path
,
:start_version
,
:latest_diff
,
:latest_version_path
,
:added_lines
,
:removed_lines
,
:render_overflow_warning
,
:added_lines
,
:removed_lines
,
:render_overflow_warning
,
:email_patch_path
,
:plain_diff_path
,
:diff_files
,
:email_patch_path
,
:plain_diff_path
,
:diff_files
,
:merge_request_diffs
:merge_request_diffs
,
:definition_path_prefix
)
)
end
end
end
end
...
...
spec/serializers/diffs_metadata_entity_spec.rb
View file @
cfcc113f
...
@@ -28,8 +28,8 @@ describe DiffsMetadataEntity do
...
@@ -28,8 +28,8 @@ describe DiffsMetadataEntity do
:start_version
,
:latest_diff
,
:latest_version_path
,
:start_version
,
:latest_diff
,
:latest_version_path
,
:added_lines
,
:removed_lines
,
:render_overflow_warning
,
:added_lines
,
:removed_lines
,
:render_overflow_warning
,
:email_patch_path
,
:plain_diff_path
,
:email_patch_path
,
:plain_diff_path
,
:merge_request_diffs
,
:merge_request_diffs
,
:context_commits
,
:
context_commits
,
:
definition_path_prefix
,
# Attributes
# Attributes
:diff_files
:diff_files
)
)
...
...
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