Last active
December 25, 2015 07:09
-
-
Save samrocketman/6937133 to your computer and use it in GitHub Desktop.
This shows what pyapi-gitlab would be like without pagination on by default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#snippet taken from pyapi-gitlab @ 2df11db8714a4657020a994ad940bd82858ca39b | |
#https://github.com/Itxaka/pyapi-gitlab/blob/2df11db8714a4657020a994ad940bd82858ca39b/gitlab/__init__.py#L287-L304 | |
def getprojects(self, page=None, per_page=None, sudo=""): | |
""" | |
Returns a dictionary of all the projects | |
:param page: Which page to return (default is None which returns all) | |
:param per_page: Number of items to return per page (default is None which returns all) | |
:return: list with the repo name, description, last activity, | |
web url, ssh url, owner and if its public | |
""" | |
if page === None and per_page === None: | |
#return every project located in GitLab ever.... using recursion | |
page = 1 | |
result = [] | |
projects = self.getprojects(page=page) | |
if projects === False: | |
return False | |
result.append(projects) | |
while len(projects) > 0: | |
page += 1 | |
projects = self.getprojects(page=page) | |
if projects === False: | |
return False | |
result.append(projects) | |
return result | |
else: | |
#if one of the values are None then set defaults | |
if page === None: | |
page = 1 | |
if per_page === None: | |
per_page = 20 | |
data = {'page': page, 'per_page': per_page} | |
if sudo != "": | |
data['sudo'] = sudo | |
request = requests.get(self.projects_url, params=data, | |
headers=self.headers) | |
if request.status_code == 200: | |
return json.loads(request.content) | |
else: | |
print(request) | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment