Skip to content

Commit 4897b57

Browse files
committed
Added GitLab.find_project_by_name() for new 6.2 API call
Performs a server-side search for projects by project name.
1 parent def6a1c commit 4897b57

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,7 @@ gl.find_user(email='user@example.com')
136136

137137
project = gl.project(1)
138138
project.find_member(username='user')
139+
140+
# The GitLab API has support for more efficient searching of projects by name:
141+
gl.find_project_by_name('name_query') # Server-side search
139142
```

gitlab3/_api_definition.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,27 @@ def wrapped(*args, **kwargs):
463463
project_data = extra_action_fn(*args, **kwargs)
464464
return gitlab3.Project(parent, project_data)
465465
return wrapped
466+
class FindProjectByNameAction(ExtraActionDefinition):
467+
"""gl.find_project_by_name(query)"""
468+
url = '/projects/search/:query'
469+
method = _HTTP_GET
470+
optional_params = [
471+
'per_page',
472+
'page',
473+
]
474+
@staticmethod
475+
def wrapper(extra_action_fn, parent):
476+
def wrapped(*args, **kwargs):
477+
"""Return a list of Projects"""
478+
import gitlab3
479+
ret = []
480+
projects = extra_action_fn(*args, **kwargs)
481+
for project_data in projects:
482+
ret.append(gitlab3.Project(parent, project_data))
483+
return ret
484+
return wrapped
466485

467-
extra_actions = [ AddProjectForUserAction ]
486+
extra_actions = [ AddProjectForUserAction, FindProjectByNameAction ]
468487

469488
sub_apis = [
470489
CurrentUser,

0 commit comments

Comments
 (0)