Skip to content

Commit 8cb8040

Browse files
authored
Merge pull request #1131 from valentingregoire/master
feat: added constants for search API
2 parents 68a4162 + 16fc048 commit 8cb8040

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

docs/gl_objects/badges.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ List badges::
2828

2929
badges = group_or_project.badges.list()
3030

31-
Get ad badge::
31+
Get a badge::
3232

3333
badge = group_or_project.badges.get(badge_id)
3434

docs/gl_objects/search.rst

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@ Search API
44

55
You can search for resources at the top level, in a project or in a group.
66
Searches are based on a scope (issues, merge requests, and so on) and a search
7-
string.
7+
string. The following constants are provided to represent the possible scopes:
8+
9+
10+
* Shared scopes (global, group and project):
11+
12+
+ ``gitlab.SEARCH_SCOPE_PROJECTS``: ``projects``
13+
+ ``gitlab.SEARCH_SCOPE_ISSUES``: ``issues``
14+
+ ``gitlab.SEARCH_SCOPE_MERGE_REQUESTS``: ``merge_requests``
15+
+ ``gitlab.SEARCH_SCOPE_MILESTONES``: ``milestones``
16+
+ ``gitlab.SEARCH_SCOPE_WIKI_BLOBS``: ``wiki_blobs``
17+
+ ``gitlab.SEARCH_SCOPE_COMMITS``: ``commits``
18+
+ ``gitlab.SEARCH_SCOPE_BLOBS``: ``blobs``
19+
+ ``gitlab.SEARCH_SCOPE_USERS``: ``users``
20+
21+
22+
* specific global scope:
23+
24+
+ ``gitlab.SEARCH_SCOPE_GLOBAL_SNIPPET_TITLES``: ``snippet_titles``
25+
26+
27+
* specific project scope:
28+
29+
+ ``gitlab.SEARCH_SCOPE_PROJECT_NOTES``: ``notes``
30+
831

932
Reference
1033
---------
@@ -23,31 +46,32 @@ Examples
2346
Search for issues matching a specific string::
2447

2548
# global search
26-
gl.search('issues', 'regression')
49+
gl.search(gitlab.SEARCH_SCOPE_ISSUES, 'regression')
2750

2851
# group search
2952
group = gl.groups.get('mygroup')
30-
group.search('issues', 'regression')
53+
group.search(gitlab.SEARCH_SCOPE_ISSUES, 'regression')
3154

3255
# project search
3356
project = gl.projects.get('myproject')
34-
project.search('issues', 'regression')
57+
project.search(gitlab.SEARCH_SCOPE_ISSUES, 'regression')
3558

3659
The ``search()`` methods implement the pagination support::
3760

3861
# get lists of 10 items, and start at page 2
39-
gl.search('issues', search_str, page=2, per_page=10)
62+
gl.search(gitlab.SEARCH_SCOPE_ISSUES, search_str, page=2, per_page=10)
4063

4164
# get a generator that will automatically make required API calls for
4265
# pagination
43-
for item in gl.search('issues', search_str, as_list=False):
66+
for item in gl.search(gitlab.SEARCH_SCOPE_ISSUES, search_str, as_list=False):
4467
do_something(item)
4568

4669
The search API doesn't return objects, but dicts. If you need to act on
4770
objects, you need to create them explicitly::
4871

49-
for item in gl.search('issues', search_str, as_list=False):
72+
for item in gl.search(gitlab.SEARCH_SCOPE_ISSUES, search_str, as_list=False):
5073
issue_project = gl.projects.get(item['project_id'], lazy=True)
5174
issue = issue_project.issues.get(item['iid'])
5275
issue.state = 'closed'
5376
issue.save()
77+

gitlab/const.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,20 @@
3333
NOTIFICATION_LEVEL_GLOBAL = "global"
3434
NOTIFICATION_LEVEL_MENTION = "mention"
3535
NOTIFICATION_LEVEL_CUSTOM = "custom"
36+
37+
# Search scopes
38+
# all scopes (global, group and project)
39+
SEARCH_SCOPE_PROJECTS = "projects"
40+
SEARCH_SCOPE_ISSUES = "issues"
41+
SEARCH_SCOPE_MERGE_REQUESTS = "merge_requests"
42+
SEARCH_SCOPE_MILESTONES = "milestones"
43+
SEARCH_SCOPE_WIKI_BLOBS = "wiki_blobs"
44+
SEARCH_SCOPE_COMMITS = "commits"
45+
SEARCH_SCOPE_BLOBS = "blobs"
46+
SEARCH_SCOPE_USERS = "users"
47+
48+
# specific global scope
49+
SEARCH_SCOPE_GLOBAL_SNIPPET_TITLES = "snippet_titles"
50+
51+
# specific project scope
52+
SEARCH_SCOPE_PROJECT_NOTES = "notes"

0 commit comments

Comments
 (0)