Skip to content

Commit

Permalink
feat: update codeql
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekMasher committed Jul 26, 2023
1 parent 11f9dd2 commit f230354
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
export PYTHONPATH=$PWD/src
for f in examples/*.py; do
echo "Running :: $f"
echo "[+] Running :: $f"
pipenv run python $f
done
10 changes: 3 additions & 7 deletions examples/codeql.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import json
"""CodeQL Example."""
import os
from ghastoolkit.codeql import databases
from ghastoolkit.codeql.cli import CodeQL
from ghastoolkit.codeql.databases import CodeQLDatabases
import json
from ghastoolkit import CodeQL, CodeQLDatabases

codeql = CodeQL()
print(codeql)
Expand All @@ -18,5 +16,3 @@

for result in results:
print(f"- {result}")


15 changes: 12 additions & 3 deletions src/ghastoolkit/codeql/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This is the CodeQL CLI Module."""
from glob import glob
import os
import json
import logging
Expand All @@ -15,14 +16,22 @@

def findCodeQLBinary() -> Optional[List[str]]:
"""Find CodeQL Binary on current system."""
locations = [["codeql"], ["gh", "codeql"], ["/usr/bin/codeql/codeql"]]
locations = [
# generic
["codeql"],
# local bin
["/usr/bin/codeql/codeql"],
# gh cli
["gh", "codeql"],
# Actions
glob("/opt/hostedtoolcache/CodeQL/*/x64/codeql/codeql"),
]

for location in locations:
try:
cmd = location + ["version"]
with open(os.devnull, "w") as null:
subprocess.check_call(cmd, stdout=null, stderr=null)

return location
except Exception as err:
logger.debug(f"Failed to find codeql :: {err}")
Expand Down Expand Up @@ -64,7 +73,7 @@ def runCommand(self, *argvs, display: bool = False) -> Optional[str]:
@property
def version(self) -> str:
"""Get CodeQL Version from the CLI binary."""
version = self.runCommand("version", "--format", "terse", display=True)
version = self.runCommand("version", "--format", "terse")
if not version:
raise Exception("CodeQL version not found")
return version
Expand Down

0 comments on commit f230354

Please sign in to comment.