Skip to content

Commit

Permalink
Do update check only if git target or gist output (#401)
Browse files Browse the repository at this point in the history
This modifies the run of the CLI to only check for new PyPI updates to
the package if a given target is a GitHub address or the output is
designated to Gist. Both of these are remote, and so the cost to check
an update (also remote) only runs in the same case.

Signed-off-by: Eric Brown <eric.brown@securesauce.dev>
  • Loading branch information
ericwb committed Apr 1, 2024
1 parent 97f9587 commit dd94dc8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions precli/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
from precli.renderers.plain import Plain


GITHUB_URL = "https://github.com"


def setup_arg_parser():
parser = argparse.ArgumentParser(
description="precli - a static analysis security tool",
Expand Down Expand Up @@ -188,14 +191,14 @@ def file_to_url(owner, repo, branch, target, root, file):
prefix = root[target_len:].lstrip("/")
urlpath = f"{owner}/{repo}/blob/{branch}"
rel_path = "/".join([urlpath, prefix, file])
return urljoin("https://github.com", rel_path)
return urljoin(GITHUB_URL, rel_path)


def discover_files(targets: list[str], recursive: bool):
artifacts = []

for target in targets:
if target.startswith("https://github.com"):
if target.startswith(GITHUB_URL):
owner, repo = get_owner_repo(target)
if repo:
try:
Expand Down Expand Up @@ -304,7 +307,9 @@ def main():
args = setup_arg_parser()

# Check if a newer version is available
if args.quiet is False:
git_target = any(filter(lambda x: x.startswith(GITHUB_URL), args.targets))

if (git_target or args.gist) and not args.quiet:
check_for_update()

enabled = args.enable.split(",") if args.enable else []
Expand Down

0 comments on commit dd94dc8

Please sign in to comment.