From c889c6981f413ccc23eeac881e2981ecb642a71e Mon Sep 17 00:00:00 2001 From: GeekMasher Date: Tue, 2 Aug 2022 12:31:09 +0100 Subject: [PATCH 1/2] Encode owner name for CodeQL to work properly --- codeqlsummarize/exporters/customizations.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/codeqlsummarize/exporters/customizations.py b/codeqlsummarize/exporters/customizations.py index 5d60bc6..b057e8a 100644 --- a/codeqlsummarize/exporters/customizations.py +++ b/codeqlsummarize/exporters/customizations.py @@ -33,6 +33,7 @@ def saveQLL( database: CodeQLDatabase, output_customizations: str, github: GitHub, **kargs ): padding = " " * 6 + owner = github.owner.replace("-", "_") models = {} # initially populate data @@ -55,7 +56,7 @@ def saveQLL( # generate codeql lib for dabase custom = CODEQL_CUSTOMIZATION.format( - name=database.display_name(owner=github.owner), type=sname, models=sname, rows=rows + name=database.display_name(owner=owner), type=sname, models=sname, rows=rows ) models[sname] = custom @@ -113,11 +114,14 @@ def exportCustomizations( def exportBundle(database: CodeQLDatabase, output: str, github: GitHub, **kargs): working = kargs.get("working", os.getcwd()) logger.debug(f"Working dir :: {working}") - if not github or not github.owner: + + owner = github.owner.replace("-", "_") + + if not github or not owner: raise Exception("Failed to export Bundle: No owner / repo name set") # Create root for language - root = os.path.join(working, database.language, github.owner) + root = os.path.join(working, database.language, owner) os.makedirs(root, exist_ok=True) logger.debug(f"Root for language :: {root}") @@ -134,15 +138,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) @@ -154,7 +158,7 @@ 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: @@ -162,7 +166,7 @@ def exportBundle(database: CodeQLDatabase, output: str, github: GitHub, **kargs) CODEQL_CUSTOMIZATIONS_QLL.format( language=database.language, custom=customizations_data, - owner=github.owner, + owner=owner, ) ) From be6abd8e5a96f8cac8d5fe9b8b5af8c2368d7200 Mon Sep 17 00:00:00 2001 From: Mathew Payne <2772944+GeekMasher@users.noreply.github.com> Date: Tue, 2 Aug 2022 13:02:23 +0100 Subject: [PATCH 2/2] Update customizations.py --- codeqlsummarize/exporters/customizations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codeqlsummarize/exporters/customizations.py b/codeqlsummarize/exporters/customizations.py index 82864a6..661f816 100644 --- a/codeqlsummarize/exporters/customizations.py +++ b/codeqlsummarize/exporters/customizations.py @@ -115,7 +115,7 @@ 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("-", "_") @@ -123,7 +123,7 @@ def exportBundle(database: CodeQLDatabase, output: str, github: GitHub, **kargs) raise Exception("Failed to export Bundle: No owner / repo name set") # Create root for language - root = os.path.join(working, database.language, owner) + root = os.path.join(output, database.language, owner) os.makedirs(root, exist_ok=True) logger.debug(f"Root for language :: {root}")