-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run upgrades in the background, prepare release v1.1.0
- Loading branch information
Showing
6 changed files
with
74 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# encoding: utf-8 | ||
|
||
from workflow import web, Workflow, PasswordNotFound | ||
|
||
def get_projects(api_key, url): | ||
""" | ||
Parse all pages of projects | ||
:return: list | ||
""" | ||
return get_project_page(api_key, url, 1, []) | ||
|
||
def get_project_page(api_key, url, page, list): | ||
log.info("Calling API page {page}".format(page=page)) | ||
params = dict(private_token=api_key, per_page=100, page=page, membership='true') | ||
r = web.get(url, params) | ||
|
||
# throw an error if request failed | ||
# Workflow will catch this and show it to the user | ||
r.raise_for_status() | ||
|
||
# Parse the JSON returned by GitLab and extract the projects | ||
result = list + r.json() | ||
|
||
nextpage = r.headers.get('X-Next-Page') | ||
if nextpage: | ||
result = get_project_page(api_key, url, nextpage, result) | ||
|
||
return result | ||
|
||
def main(wf): | ||
try: | ||
# Get API key from Keychain | ||
api_key = wf.get_password('gitlab_api_key') | ||
api_url = wf.settings.get('api_url', None) | ||
|
||
# Retrieve projects from cache if available and no more than 600 | ||
# seconds old | ||
def wrapper(): | ||
return get_projects(api_key, api_url) | ||
|
||
projects = wf.cached_data('projects', wrapper, max_age=3600) | ||
|
||
# Record our progress in the log file | ||
log.debug('{} gitlab projects cached'.format(len(projects))) | ||
|
||
except PasswordNotFound: # API key has not yet been set | ||
# Nothing we can do about this, so just log it | ||
wf.logger.error('No API key saved') | ||
|
||
if __name__ == u"__main__": | ||
wf = Workflow() | ||
log = wf.logger | ||
wf.run(main) |