Skip to content

Commit a4e9259

Browse files
ltickettgodfat
authored andcommitted
#46469 - Added ref querystring parameter to project search to allow searching on branches other than master
1 parent f7ebea0 commit a4e9259

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Added ref querystring parameter to project search API to allow searching on branches/tags other than the default
3+
merge_request: 28069
4+
author: Lee Tickett
5+
type: added

doc/api/search.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ GET /projects/:id/search
556556
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
557557
| `scope` | string | yes | The scope to search in |
558558
| `search` | string | yes | The search query |
559+
| `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. |
559560

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

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

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

856857
Example response:
@@ -863,7 +864,7 @@ Example response:
863864
"data": "```\n\n## Installation\n\nQuick start using the [pre-built",
864865
"filename": "README.md",
865866
"id": null,
866-
"ref": "master",
867+
"ref": "feature",
867868
"startline": 46,
868869
"project_id": 6
869870
}

lib/api/search.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,13 @@ def check_users_search_allowed!
112112
type: String,
113113
desc: 'The scope of the search',
114114
values: Helpers::SearchHelpers.project_search_scopes
115+
optional :ref, type: String, desc: 'The name of a repository branch or tag. If not given, the default branch is used'
115116
use :pagination
116117
end
117118
get ':id/(-/)search' do
118119
check_users_search_allowed!
119120

120-
present search(project_id: user_project.id), with: entity
121+
present search({ project_id: user_project.id, repository_ref: params[:ref] }), with: entity
121122
end
122123
end
123124
end

spec/requests/api/search_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@
414414
expect(response).to have_gitlab_http_status(200)
415415
expect(json_response.size).to eq(11)
416416
end
417+
418+
it 'by ref' do
419+
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' }
420+
421+
expect(response).to have_gitlab_http_status(200)
422+
expect(json_response.size).to eq(1)
423+
end
417424
end
418425
end
419426
end

0 commit comments

Comments
 (0)