Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Bauersfeld committed Apr 12, 2022
1 parent b9d8f8e commit 9e65276
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
32 changes: 32 additions & 0 deletions customize/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
import ghlib


def download(args):
gh = ghlib.GitHub('https://api.github.com', os.environ['GITHUB_TOKEN'])
repo = gh.getRepo(args.repo_id)
a = repo.latest_asset(args.tag_filter, 'codeql-bundle-*.tar.gz')
if a is None:
util.error('No distribution available for tag filter "%s"!' % (args.tag_filter))

repo.download_asset(a, args.output_dir)

def upload(args):
git = util.Git('.')
gh = ghlib.GitHub('https://api.github.com', os.environ['GITHUB_TOKEN'])
Expand Down Expand Up @@ -95,6 +104,29 @@ def main():
)
upload_parser.set_defaults(func=upload)

# download
download_parser = subparsers.add_parser(
'download',
help='Download a customized distribution using the GitHub Releases REST API',
description='Download a customized CodeQL distribution using the GitHub Releases REST API',
)
download_parser.add_argument(
'--output-dir',
required=True,
help='The directory in which to store the downloaded CodeQL distribution',
)
download_parser.add_argument(
'--repo-id',
required=True,
help='The repository id in the format of "orgoruser/reponame"',
)
download_parser.add_argument(
'--tag-filter',
required=True,
help='A tag filter, which may contain globs ("*").',
)
download_parser.set_defaults(func=download)

def print_usage(args):
print(parser.format_usage())

Expand Down
6 changes: 3 additions & 3 deletions customize/ghlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def json_accept_header():
def sort_by_created_at(releasesorassets):
return sorted(
releasesorassets,
key=lambda e: parse_date(e['created_at']),
key=lambda e: util.parse_date(e['created_at']),
reverse=True
)

Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(self, github, repo_id):
self.repo_id = repo_id


def latest_asset(tagfilter, assetfilter):
def latest_asset(self, tagfilter, assetfilter):
''' note that this will not necessarily return a file
from the _latest_ release. It will return a file
from the newest release which matches the given
Expand All @@ -56,7 +56,7 @@ def latest_asset(tagfilter, assetfilter):
process of uploading an asset, which first requires
to create an empty release (race condition)'''
for r in sort_by_created_at(self.list_releases()):
if fnmatch(r['name'], tagfilter):
if fnmatch(r['tag_name'], tagfilter):
for a in sort_by_created_at(r['assets']):
if fnmatch(a['name'], assetfilter):
return a
Expand Down

0 comments on commit 9e65276

Please sign in to comment.