@@ -4,7 +4,30 @@ Search API
4
4
5
5
You can search for resources at the top level, in a project or in a group.
6
6
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
+
8
31
9
32
Reference
10
33
---------
@@ -23,31 +46,32 @@ Examples
23
46
Search for issues matching a specific string::
24
47
25
48
# global search
26
- gl.search('issues' , 'regression')
49
+ gl.search(gitlab.SEARCH_SCOPE_ISSUES , 'regression')
27
50
28
51
# group search
29
52
group = gl.groups.get('mygroup')
30
- group.search('issues' , 'regression')
53
+ group.search(gitlab.SEARCH_SCOPE_ISSUES , 'regression')
31
54
32
55
# project search
33
56
project = gl.projects.get('myproject')
34
- project.search('issues' , 'regression')
57
+ project.search(gitlab.SEARCH_SCOPE_ISSUES , 'regression')
35
58
36
59
The ``search() `` methods implement the pagination support::
37
60
38
61
# 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)
40
63
41
64
# get a generator that will automatically make required API calls for
42
65
# 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):
44
67
do_something(item)
45
68
46
69
The search API doesn't return objects, but dicts. If you need to act on
47
70
objects, you need to create them explicitly::
48
71
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):
50
73
issue_project = gl.projects.get(item['project_id'], lazy=True)
51
74
issue = issue_project.issues.get(item['iid'])
52
75
issue.state = 'closed'
53
76
issue.save()
77
+
0 commit comments