Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions codeqlsummarize/exporters/customizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def saveQLL(
database: CodeQLDatabase, output_customizations: str, github: GitHub, **kargs
):
padding = " " * 6
owner = github.owner.replace("-", "_")

models = {}
# initially populate data
Expand All @@ -55,7 +56,7 @@ def saveQLL(

# generate codeql lib for dabase
custom = CODEQL_CUSTOMIZATION.format(
name=database.display_name(owner=github.owner),
name=database.display_name(owner=owner),
type=sname,
models=sname,
rows=rows,
Expand Down Expand Up @@ -114,12 +115,15 @@ def exportCustomizations(


def exportBundle(database: CodeQLDatabase, output: str, github: GitHub, **kargs):
logger.debug(f"Working dir :: {output}")
logger.debug(f"Output directory :: {output}")

owner = github.owner.replace("-", "_")

if not github or not github.owner:
raise Exception("Failed to export Bundle: No owner / repo name set")

# Create root for language
root = os.path.join(output, database.language, github.owner)
root = os.path.join(output, database.language, owner)
os.makedirs(root, exist_ok=True)
logger.debug(f"Root for language :: {root}")

Expand All @@ -136,15 +140,15 @@ def exportBundle(database: CodeQLDatabase, output: str, github: GitHub, **kargs)
with open(codeql_lang_pack, "w") as handle:
handle.write(
CODEQL_PACK.format(
owner=github.owner, version="0.1.0", language=database.language
owner=owner, version="0.1.0", language=database.language
)
)

# Create language subfolder (if needed)
sub = os.path.join(root, github.owner, database.language)
sub = os.path.join(root, owner, database.language)
os.makedirs(sub, exist_ok=True)

name = database.display_name(owner=github.owner) + "Generated"
name = database.display_name(owner=owner) + "Generated"

db_custom_lib_path = os.path.join(sub, name + ".qll")
saveQLL(database, db_custom_lib_path, github)
Expand All @@ -156,15 +160,15 @@ def exportBundle(database: CodeQLDatabase, output: str, github: GitHub, **kargs)
if custom == "Customizations.qll":
continue

impt = f" private import {github.owner}.{database.language}.{name}\n"
impt = f" private import {owner}.{database.language}.{name}\n"
customizations_data += impt

with open(customizations_path, "w") as handle:
handle.write(
CODEQL_CUSTOMIZATIONS_QLL.format(
language=database.language,
custom=customizations_data,
owner=github.owner,
owner=owner,
)
)

Expand Down