(ctx: click.Context)
scan in a CI environment.
scan in a CI environment.
scan in a CI environment .
def ci_cmd(ctx: click.Context) -> int:  # pragma: no cover
    """
    scan in a CI environment.
    """
    config = ctx.obj["config"]
    try:
        check_git_dir()
        if not (
            os.getenv("CI") or os.getenv("JENKINS_HOME") or os.getenv("BUILD_BUILDID")
        ):
            raise click.ClickException("--ci should only be used in a CI environment.")

        if os.getenv("GITLAB_CI"):
            commit_list = gitlab_ci_range(config.verbose)
            ci_env = SupportedCI.GITLAB
        elif os.getenv("GITHUB_ACTIONS"):
            commit_list = github_actions_range(config.verbose)
            ci_env = SupportedCI.GITHUB
        elif os.getenv("TRAVIS"):
            commit_list = travis_range(config.verbose)
            ci_env = SupportedCI.TRAVIS
        elif os.getenv("JENKINS_HOME") or os.getenv("JENKINS_URL"):
            commit_list = jenkins_range(config.verbose)
            ci_env = SupportedCI.JENKINS
        elif os.getenv("CIRCLECI"):
            commit_list = circle_ci_range(config.verbose)
            ci_env = SupportedCI.CIRCLECI
        elif os.getenv("BITBUCKET_COMMIT"):
            commit_list = bitbucket_pipelines_range(config.verbose)
            ci_env = SupportedCI.BITBUCKET
        elif os.getenv("DRONE"):
            commit_list = drone_range(config.verbose)
            ci_env = SupportedCI.DRONE
        elif os.getenv("BUILD_BUILDID"):
            commit_list = azure_range(config.verbose)
            ci_env = SupportedCI.AZURE

        else:
            raise click.ClickException(
                f"Current CI is not detected or supported."
                f"Must be one of [{' | '.join([ci.value for ci in SupportedCI])}]"
            )

        if config.verbose:
            click.echo(f"Commits to scan: {len(commit_list)}")

        mode_header = "/".join([SupportedScanMode.CI.value, ci_env.value])

        return scan_commit_range(
            client=ctx.obj["client"],
            cache=ReadOnlyCache(),
            commit_list=commit_list,
            output_handler=ctx.obj["output_handler"],
            verbose=config.verbose,
            exclusion_regexes=ctx.obj["exclusion_regexes"],
            matches_ignore=config.matches_ignore,
            all_policies=config.all_policies,
            scan_id=" ".join(commit_list),
            mode_header=mode_header,
            banlisted_detectors=config.banlisted_detectors,
        )
    except Exception as error:
        return handle_exception(error, config.verbose)
def ci_cmd ( ctx : click . Context ) -> int : # pragma: no cover config = ctx . obj [ "config" ] try : check_git_dir ( ) if not ( os . getenv ( "CI" ) or os . getenv ( "JENKINS_HOME" ) or os . getenv ( "BUILD_BUILDID" ) ) : raise click . ClickException ( "--ci should only be used in a CI environment." ) if os . getenv ( "GITLAB_CI" ) : commit_list = gitlab_ci_range ( config . verbose ) ci_env = SupportedCI . GITLAB elif os . getenv ( "GITHUB_ACTIONS" ) : commit_list = github_actions_range ( config . verbose ) ci_env = SupportedCI . GITHUB elif os . getenv ( "TRAVIS" ) : commit_list = travis_range ( config . verbose ) ci_env = SupportedCI . TRAVIS elif os . getenv ( "JENKINS_HOME" ) or os . getenv ( "JENKINS_URL" ) : commit_list = jenkins_range ( config . verbose ) ci_env = SupportedCI . JENKINS elif os . getenv ( "CIRCLECI" ) : commit_list = circle_ci_range ( config . verbose ) ci_env = SupportedCI . CIRCLECI elif os . getenv ( "BITBUCKET_COMMIT" ) : commit_list = bitbucket_pipelines_range ( config . verbose ) ci_env = SupportedCI . BITBUCKET elif os . getenv ( "DRONE" ) : commit_list = drone_range ( config . verbose ) ci_env = SupportedCI . DRONE elif os . getenv ( "BUILD_BUILDID" ) : commit_list = azure_range ( config . verbose ) ci_env = SupportedCI . AZURE else : raise click . ClickException ( f"Current CI is not detected or supported." f"Must be one of [{' | '.join([ci.value for ci in SupportedCI])}]" ) if config . verbose : click . echo ( f"Commits to scan: {len(commit_list)}" ) mode_header = "/" . join ( [ SupportedScanMode . CI . value , ci_env . value ] ) return scan_commit_range ( client = ctx . obj [ "client" ] , cache = ReadOnlyCache ( ) , commit_list = commit_list , output_handler = ctx . obj [ "output_handler" ] , verbose = config . verbose , exclusion_regexes = ctx . obj [ "exclusion_regexes" ] , matches_ignore = config . matches_ignore , all_policies = config . all_policies , scan_id = " " . join ( commit_list ) , mode_header = mode_header , banlisted_detectors = config . banlisted_detectors , ) except Exception as error : return handle_exception ( error , config . verbose )