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
Boxiang Sun
gitlab-ce
Commits
b0b4ae18
Commit
b0b4ae18
authored
Feb 13, 2018
by
Jarka Kadlecová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API - Include project in commits&blobs search results
parent
bf5e617a
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
37 additions
and
22 deletions
+37
-22
app/models/commit.rb
app/models/commit.rb
+4
-0
doc/api/README.md
doc/api/README.md
+1
-0
doc/api/search.md
doc/api/search.md
+6
-3
lib/api/entities.rb
lib/api/entities.rb
+2
-0
lib/api/search.rb
lib/api/search.rb
+4
-8
lib/gitlab/file_finder.rb
lib/gitlab/file_finder.rb
+3
-2
lib/gitlab/project_search_results.rb
lib/gitlab/project_search_results.rb
+3
-2
lib/gitlab/search_results.rb
lib/gitlab/search_results.rb
+2
-1
spec/fixtures/api/schemas/public_api/v4/blobs.json
spec/fixtures/api/schemas/public_api/v4/blobs.json
+2
-1
spec/fixtures/api/schemas/public_api/v4/commit/detail.json
spec/fixtures/api/schemas/public_api/v4/commit/detail.json
+4
-3
spec/fixtures/api/schemas/public_api/v4/commits_details.json
spec/fixtures/api/schemas/public_api/v4/commits_details.json
+4
-0
spec/requests/api/search_spec.rb
spec/requests/api/search_spec.rb
+2
-2
No files found.
app/models/commit.rb
View file @
b0b4ae18
...
@@ -116,6 +116,10 @@ class Commit
...
@@ -116,6 +116,10 @@ class Commit
raw
.
id
raw
.
id
end
end
def
project_id
project
.
id
end
def
==
(
other
)
def
==
(
other
)
other
.
is_a?
(
self
.
class
)
&&
raw
==
other
.
raw
other
.
is_a?
(
self
.
class
)
&&
raw
==
other
.
raw
end
end
...
...
doc/api/README.md
View file @
b0b4ae18
...
@@ -49,6 +49,7 @@ following locations:
...
@@ -49,6 +49,7 @@ following locations:
-
[
Repositories
](
repositories.md
)
-
[
Repositories
](
repositories.md
)
-
[
Repository Files
](
repository_files.md
)
-
[
Repository Files
](
repository_files.md
)
-
[
Runners
](
runners.md
)
-
[
Runners
](
runners.md
)
-
[
Search
](
search.md
)
-
[
Services
](
services.md
)
-
[
Services
](
services.md
)
-
[
Settings
](
settings.md
)
-
[
Settings
](
settings.md
)
-
[
Sidekiq metrics
](
sidekiq_metrics.md
)
-
[
Sidekiq metrics
](
sidekiq_metrics.md
)
...
...
doc/api/search.md
View file @
b0b4ae18
...
@@ -737,7 +737,8 @@ Example response:
...
@@ -737,7 +737,8 @@ Example response:
"filename"
:
"home.md"
,
"filename"
:
"home.md"
,
"id"
:
null
,
"id"
:
null
,
"ref"
:
"master"
,
"ref"
:
"master"
,
"startline"
:
5
"startline"
:
5
,
"project_id"
:
6
}
}
]
]
```
```
...
@@ -767,7 +768,8 @@ Example response:
...
@@ -767,7 +768,8 @@ Example response:
"authored_date"
:
"2013-02-18T22:02:54.000Z"
,
"authored_date"
:
"2013-02-18T22:02:54.000Z"
,
"committer_name"
:
"angus croll"
,
"committer_name"
:
"angus croll"
,
"committer_email"
:
"anguscroll@gmail.com"
,
"committer_email"
:
"anguscroll@gmail.com"
,
"committed_date"
:
"2013-02-18T22:02:54.000Z"
"committed_date"
:
"2013-02-18T22:02:54.000Z"
,
"project_id"
:
6
}
}
]
]
```
```
...
@@ -789,7 +791,8 @@ Example response:
...
@@ -789,7 +791,8 @@ Example response:
"filename"
:
"README.md"
,
"filename"
:
"README.md"
,
"id"
:
null
,
"id"
:
null
,
"ref"
:
"master"
,
"ref"
:
"master"
,
"startline"
:
46
"startline"
:
46
,
"project_id"
:
6
}
}
]
]
```
```
...
...
lib/api/entities.rb
View file @
b0b4ae18
...
@@ -274,6 +274,7 @@ module API
...
@@ -274,6 +274,7 @@ module API
expose
:stats
,
using:
Entities
::
CommitStats
,
if: :stats
expose
:stats
,
using:
Entities
::
CommitStats
,
if: :stats
expose
:status
expose
:status
expose
:last_pipeline
,
using:
'API::Entities::PipelineBasic'
expose
:last_pipeline
,
using:
'API::Entities::PipelineBasic'
expose
:project_id
end
end
class
Branch
<
Grape
::
Entity
class
Branch
<
Grape
::
Entity
...
@@ -1172,6 +1173,7 @@ module API
...
@@ -1172,6 +1173,7 @@ module API
expose
:id
expose
:id
expose
:ref
expose
:ref
expose
:startline
expose
:startline
expose
:project_id
end
end
end
end
end
end
lib/api/search.rb
View file @
b0b4ae18
...
@@ -11,7 +11,7 @@ module API
...
@@ -11,7 +11,7 @@ module API
projects:
Entities
::
BasicProjectDetails
,
projects:
Entities
::
BasicProjectDetails
,
milestones:
Entities
::
Milestone
,
milestones:
Entities
::
Milestone
,
notes:
Entities
::
Note
,
notes:
Entities
::
Note
,
commits:
Entities
::
Commit
,
commits:
Entities
::
Commit
Detail
,
blobs:
Entities
::
Blob
,
blobs:
Entities
::
Blob
,
wiki_blobs:
Entities
::
Blob
,
wiki_blobs:
Entities
::
Blob
,
snippet_titles:
Entities
::
Snippet
,
snippet_titles:
Entities
::
Snippet
,
...
@@ -35,7 +35,7 @@ module API
...
@@ -35,7 +35,7 @@ module API
def
process_results
(
results
)
def
process_results
(
results
)
case
params
[
:scope
]
case
params
[
:scope
]
when
'wiki_blobs'
when
'wiki_blobs'
paginate
(
results
).
map
{
|
blob
|
Gitlab
::
ProjectSearchResults
.
parse_search_result
(
blob
)
}
paginate
(
results
).
map
{
|
blob
|
Gitlab
::
ProjectSearchResults
.
parse_search_result
(
blob
,
user_project
)
}
when
'blobs'
when
'blobs'
paginate
(
results
).
map
{
|
blob
|
blob
[
1
]
}
paginate
(
results
).
map
{
|
blob
|
blob
[
1
]
}
else
else
...
@@ -85,9 +85,7 @@ module API
...
@@ -85,9 +85,7 @@ module API
use
:pagination
use
:pagination
end
end
get
':id/-/search'
do
get
':id/-/search'
do
group
=
find_group!
(
params
[
:id
])
present
search
(
group_id:
user_group
.
id
),
with:
entity
present
search
(
group_id:
group
.
id
),
with:
entity
end
end
end
end
...
@@ -106,9 +104,7 @@ module API
...
@@ -106,9 +104,7 @@ module API
use
:pagination
use
:pagination
end
end
get
':id/-/search'
do
get
':id/-/search'
do
project
=
find_project!
(
params
[
:id
])
present
search
(
project_id:
user_project
.
id
),
with:
entity
present
search
(
project_id:
project
.
id
),
with:
entity
end
end
end
end
end
end
...
...
lib/gitlab/file_finder.rb
View file @
b0b4ae18
...
@@ -28,7 +28,7 @@ module Gitlab
...
@@ -28,7 +28,7 @@ module Gitlab
def
find_by_content
(
query
)
def
find_by_content
(
query
)
results
=
repository
.
search_files_by_content
(
query
,
ref
).
first
(
BATCH_SIZE
)
results
=
repository
.
search_files_by_content
(
query
,
ref
).
first
(
BATCH_SIZE
)
results
.
map
{
|
result
|
Gitlab
::
ProjectSearchResults
.
parse_search_result
(
result
)
}
results
.
map
{
|
result
|
Gitlab
::
ProjectSearchResults
.
parse_search_result
(
result
,
project
)
}
end
end
def
find_by_filename
(
query
,
except:
[])
def
find_by_filename
(
query
,
except:
[])
...
@@ -45,7 +45,8 @@ module Gitlab
...
@@ -45,7 +45,8 @@ module Gitlab
basename:
File
.
basename
(
blob
.
path
),
basename:
File
.
basename
(
blob
.
path
),
ref:
ref
,
ref:
ref
,
startline:
1
,
startline:
1
,
data:
blob
.
data
data:
blob
.
data
,
project:
project
)
)
end
end
end
end
...
...
lib/gitlab/project_search_results.rb
View file @
b0b4ae18
...
@@ -41,7 +41,7 @@ module Gitlab
...
@@ -41,7 +41,7 @@ module Gitlab
@commits_count
||=
commits
.
count
@commits_count
||=
commits
.
count
end
end
def
self
.
parse_search_result
(
result
)
def
self
.
parse_search_result
(
result
,
project
=
nil
)
ref
=
nil
ref
=
nil
filename
=
nil
filename
=
nil
basename
=
nil
basename
=
nil
...
@@ -66,7 +66,8 @@ module Gitlab
...
@@ -66,7 +66,8 @@ module Gitlab
basename:
basename
,
basename:
basename
,
ref:
ref
,
ref:
ref
,
startline:
startline
,
startline:
startline
,
data:
data
data:
data
,
project_id:
project
?
project
.
id
:
nil
)
)
end
end
...
...
lib/gitlab/search_results.rb
View file @
b0b4ae18
module
Gitlab
module
Gitlab
class
SearchResults
class
SearchResults
class
FoundBlob
class
FoundBlob
attr_reader
:id
,
:filename
,
:basename
,
:ref
,
:startline
,
:data
attr_reader
:id
,
:filename
,
:basename
,
:ref
,
:startline
,
:data
,
:project_id
def
initialize
(
opts
=
{})
def
initialize
(
opts
=
{})
@id
=
opts
.
fetch
(
:id
,
nil
)
@id
=
opts
.
fetch
(
:id
,
nil
)
...
@@ -11,6 +11,7 @@ module Gitlab
...
@@ -11,6 +11,7 @@ module Gitlab
@startline
=
opts
.
fetch
(
:startline
,
nil
)
@startline
=
opts
.
fetch
(
:startline
,
nil
)
@data
=
opts
.
fetch
(
:data
,
nil
)
@data
=
opts
.
fetch
(
:data
,
nil
)
@per_page
=
opts
.
fetch
(
:per_page
,
20
)
@per_page
=
opts
.
fetch
(
:per_page
,
20
)
@project_id
=
opts
.
fetch
(
:project_id
,
nil
)
end
end
def
path
def
path
...
...
spec/fixtures/api/schemas/public_api/v4/blobs.json
View file @
b0b4ae18
...
@@ -7,11 +7,12 @@
...
@@ -7,11 +7,12 @@
"data"
:
{
"type"
:
"string"
},
"data"
:
{
"type"
:
"string"
},
"filename"
:
{
"type"
:
[
"string"
]
},
"filename"
:
{
"type"
:
[
"string"
]
},
"id"
:
{
"type"
:
[
"string"
,
"null"
]
},
"id"
:
{
"type"
:
[
"string"
,
"null"
]
},
"project_id"
:
{
"type"
:
"integer"
},
"ref"
:
{
"type"
:
"string"
},
"ref"
:
{
"type"
:
"string"
},
"startline"
:
{
"type"
:
"integer"
}
"startline"
:
{
"type"
:
"integer"
}
},
},
"required"
:
[
"required"
:
[
"basename"
,
"data"
,
"filename"
,
"id"
,
"ref"
,
"startline"
"basename"
,
"data"
,
"filename"
,
"id"
,
"ref"
,
"startline"
,
"project_id"
],
],
"additionalProperties"
:
false
"additionalProperties"
:
false
}
}
...
...
spec/fixtures/api/schemas/public_api/v4/commit/detail.json
View file @
b0b4ae18
...
@@ -4,9 +4,9 @@
...
@@ -4,9 +4,9 @@
{
"$ref"
:
"basic.json"
},
{
"$ref"
:
"basic.json"
},
{
{
"required"
:
[
"required"
:
[
"stats"
,
"status"
,
"status"
,
"last_pipeline"
"last_pipeline"
,
"project_id"
],
],
"properties"
:
{
"properties"
:
{
"stats"
:
{
"$ref"
:
"../commit_stats.json"
},
"stats"
:
{
"$ref"
:
"../commit_stats.json"
},
...
@@ -16,7 +16,8 @@
...
@@ -16,7 +16,8 @@
{
"type"
:
"null"
},
{
"type"
:
"null"
},
{
"$ref"
:
"../pipeline/basic.json"
}
{
"$ref"
:
"../pipeline/basic.json"
}
]
]
}
},
"project_id"
:
{
"type"
:
"integer"
}
}
}
}
}
]
]
...
...
spec/fixtures/api/schemas/public_api/v4/commits_details.json
0 → 100644
View file @
b0b4ae18
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"commit/detail.json"
}
}
spec/requests/api/search_spec.rb
View file @
b0b4ae18
...
@@ -295,7 +295,7 @@ describe API::Search do
...
@@ -295,7 +295,7 @@ describe API::Search do
get
api
(
"/projects/
#{
repo_project
.
id
}
/-/search"
,
user
),
scope:
'commits'
,
search:
'498214de67004b1da3d820901307bed2a68a8ef6'
get
api
(
"/projects/
#{
repo_project
.
id
}
/-/search"
,
user
),
scope:
'commits'
,
search:
'498214de67004b1da3d820901307bed2a68a8ef6'
end
end
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/commits'
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/commits
_details
'
end
end
context
'for commits scope with project path as id'
do
context
'for commits scope with project path as id'
do
...
@@ -303,7 +303,7 @@ describe API::Search do
...
@@ -303,7 +303,7 @@ describe API::Search do
get
api
(
"/projects/
#{
CGI
.
escape
(
repo_project
.
full_path
)
}
/-/search"
,
user
),
scope:
'commits'
,
search:
'498214de67004b1da3d820901307bed2a68a8ef6'
get
api
(
"/projects/
#{
CGI
.
escape
(
repo_project
.
full_path
)
}
/-/search"
,
user
),
scope:
'commits'
,
search:
'498214de67004b1da3d820901307bed2a68a8ef6'
end
end
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/commits'
it_behaves_like
'response is correct'
,
schema:
'public_api/v4/commits
_details
'
end
end
context
'for blobs scope'
do
context
'for blobs scope'
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