mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 19:31:10 +00:00
Add repository search
Qualifiers can be added via keyword args in order to keep the method uncluttered. Qualifiers could also be given in the query string directly.
This commit is contained in:
@@ -290,6 +290,41 @@ class Github(object):
|
||||
)
|
||||
return github.NamedUser.NamedUser(self.__requester, headers, Legacy.convertUser(data["user"]), completed=False)
|
||||
|
||||
def search_repositories(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers):
|
||||
"""
|
||||
:calls: `GET /search/repositories <http://developer.github.com/v3/search>`_
|
||||
:param query: string
|
||||
:param sort: string ('stars', 'forks', 'updated')
|
||||
:param order: string ('asc', 'desc')
|
||||
:param qualifiers: keyword dict query qualifiers
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
|
||||
"""
|
||||
assert isinstance(query, (str, unicode)), query
|
||||
url_parameters = dict()
|
||||
if sort is not github.GithubObject.NotSet:
|
||||
assert sort in ('stars', 'forks', 'updated'), sort
|
||||
url_parameters["sort"] = sort
|
||||
if order is not github.GithubObject.NotSet:
|
||||
assert order in ('asc', 'desc'), order
|
||||
url_parameters["order"] = order
|
||||
|
||||
query_chunks = []
|
||||
if query:
|
||||
query_chunks += query.split()
|
||||
|
||||
for qualifier, value in qualifiers.items():
|
||||
query_chunks.append("%s:%s" % (qualifier, value))
|
||||
|
||||
url_parameters["q"] = ' '.join(query_chunks)
|
||||
assert url_parameters["q"], "need at least one qualifier"
|
||||
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.Repository.Repository,
|
||||
self.__requester,
|
||||
"/search/repositories",
|
||||
url_parameters
|
||||
)
|
||||
|
||||
def render_markdown(self, text, context=github.GithubObject.NotSet):
|
||||
"""
|
||||
:calls: `POST /markdown <http://developer.github.com/v3/markdown>`_
|
||||
|
||||
Reference in New Issue
Block a user