Skip to content

Commit

Permalink
Merge branch 'patch-54' into 'master'
Browse files Browse the repository at this point in the history
Add ref (branch/tag) parameter to project search API

See merge request gitlab-org/gitlab-ce!28069
  • Loading branch information
godfat committed May 17, 2019
2 parents f7ebea0 + a4e9259 commit a73ee1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelogs/unreleased/add-branch-to-project-search-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Added ref querystring parameter to project search API to allow searching on branches/tags other than the default
merge_request: 28069
author: Lee Tickett
type: added
5 changes: 3 additions & 2 deletions doc/api/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ GET /projects/:id/search
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `scope` | string | yes | The scope to search in |
| `search` | string | yes | The search query |
| `ref` | string | no | The name of a repository branch or tag to search on. The project's default branch is used by default. This is only applicable for scopes: commits, blobs, and wiki_blobs. |

Search the expression within the specified scope. Currently these scopes are supported: issues, merge_requests, milestones, notes, wiki_blobs, commits, blobs, users.

Expand Down Expand Up @@ -850,7 +851,7 @@ Blobs searches are performed on both filenames and contents. Search results:
times in the content.

```bash
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/6/search?scope=blobs&search=installation
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/6/search?scope=blobs&search=installation&ref=feature
```

Example response:
Expand All @@ -863,7 +864,7 @@ Example response:
"data": "```\n\n## Installation\n\nQuick start using the [pre-built",
"filename": "README.md",
"id": null,
"ref": "master",
"ref": "feature",
"startline": 46,
"project_id": 6
}
Expand Down
3 changes: 2 additions & 1 deletion lib/api/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ def check_users_search_allowed!
type: String,
desc: 'The scope of the search',
values: Helpers::SearchHelpers.project_search_scopes
optional :ref, type: String, desc: 'The name of a repository branch or tag. If not given, the default branch is used'
use :pagination
end
get ':id/(-/)search' do
check_users_search_allowed!

present search(project_id: user_project.id), with: entity
present search({ project_id: user_project.id, repository_ref: params[:ref] }), with: entity
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/requests/api/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(11)
end

it 'by ref' do
get api("/projects/#{repo_project.id}/search", user), params: { scope: 'blobs', search: 'This file is used in tests for ci_environments_status', ref: 'pages-deploy' }

expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(1)
end
end
end
end
Expand Down

0 comments on commit a73ee1c

Please sign in to comment.