Skip to content

Commit 739d20e

Browse files
committed
Add support for default code scanning config
1 parent 1f2f6d6 commit 739d20e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

codeql_bundle/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pathlib import Path
1212
from codeql_bundle.helpers.codeql import CodeQLException
1313
from codeql_bundle.helpers.bundle import CustomBundle, BundleException, BundlePlatform
14-
from typing import List
14+
from typing import List, Optional
1515
import sys
1616
import logging
1717

@@ -50,13 +50,15 @@
5050
default="WARNING",
5151
)
5252
@click.option("-p", "--platform", multiple=True, type=click.Choice(["linux64", "osx64", "win64"], case_sensitive=False), help="Target platform for the bundle")
53+
@click.option("-c", "--code-scanning-config", type=click.Path(exists=True, path_type=Path), help="Path to a Code Scanning configuration file that will be the default for the bundle")
5354
@click.argument("packs", nargs=-1, required=True)
5455
def main(
5556
bundle_path: Path,
5657
output: Path,
5758
workspace: Path,
5859
loglevel: str,
5960
platform: List[str],
61+
code_scanning_config: Optional[Path],
6062
packs: List[str],
6163
) -> None:
6264

@@ -119,6 +121,9 @@ def main(
119121
f"Adding the pack(s) {','.join(map(lambda p: p.config.name, selected_packs))} and its workspace dependencies to the custom bundle."
120122
)
121123
bundle.add_packs(*selected_packs)
124+
if code_scanning_config:
125+
logger.info(f"Adding the Code Scanning configuration file {code_scanning_config} to the custom bundle.")
126+
bundle.add_code_scanning_config(code_scanning_config)
122127
logger.info(f"Bundling custom bundle(s) at {output}")
123128
platforms = set(map(BundlePlatform.from_string, platform))
124129
bundle.bundle(output, platforms)

codeql_bundle/helpers/bundle.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,14 @@ def bundle_query_pack(pack: ResolvedCodeQLPack):
550550
elif pack.kind == CodeQLPackKind.QUERY_PACK:
551551
bundle_query_pack(pack)
552552

553-
def bundle(self, output_path: Path, platforms: set[BundlePlatform] = set()):
553+
def add_code_scanning_config(self, default_config: Path):
554+
if not default_config.exists():
555+
raise BundleException(f"Default config {default_config} does not exist.")
556+
if not default_config.is_file():
557+
raise BundleException(f"Default config {default_config} is not a file.")
558+
shutil.copy(default_config, self.bundle_path / "default-codeql-config.yml")
559+
560+
def bundle(self, output_path: Path, platforms: set[BundlePlatform] = set(), default_config : Optional[Path] = None):
554561
if len(platforms) == 0:
555562
if output_path.is_dir():
556563
output_path = output_path / "codeql-bundle.tar.gz"

0 commit comments

Comments
 (0)