Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# --download is legacy flag to specify download action or name of desired download file
# --download == None indicates download intent where filename is based on upstream
if args.action == 'download':
if args.download is False:
args.download = None
if args.download is not False:
args.action = 'download'
if args.format != 'assets':
args.format = 'source'
# other action are either getting release or doing something with release (extend get action)
try:
res = latest(args.repo, args.format, args.pre, args.filter,
args.shorter_urls, args.major)
except (ApiCredentialsError, BadProjectError) as error:
sys.stderr.write(str(error) + os.linesep)
sys.exit(4)
if res:
# download command
if args.action == 'download':
if args.format == 'source':
# there is only one source, but we need an array
res = [res]
for url in res:
log.info("Downloading {} ...".format(url))
# there can be many assets, so we do not "rename" them
# there can be only one source, so we allow passing custom filename for it
download_file(url, args.download if args.format == 'source' else None)
sys.exit(0)
self.headers.update({
'Accept': 'application/vnd.github.v3+json'
})
if self.api_token:
log.info('Using API token.')
self.headers.update({'Authorization': "token {}".format(self.api_token)})
if self.hostname != self.DEFAULT_HOSTNAME:
self.api_base = 'https://{}/api/v3'.format(self.hostname)
else:
self.api_base = 'https://api.{}'.format(self.DEFAULT_HOSTNAME)
if '/' not in repo:
r = self.get(
'{}/search/repositories?q={}+in:name'.format(self.api_base, repo))
data = r.json()
if not data['items']:
raise BadProjectError(
'No project found on GitHub for search query: {}'.format(repo)
)
self.repo = data['items'][0]['full_name']
else:
self.repo = repo
self.rate_limited_count = 0