From 3afef5d55902f82c4a011f4e1b09fc0c49458d2a Mon Sep 17 00:00:00 2001 From: pyth0n1c <87383215+pyth0n1c@users.noreply.github.com> Date: Wed, 12 Jan 2022 10:38:23 -0800 Subject: [PATCH] Updated the error for providing both PR and commit_hash to a warning. This was causing an error during PR triggered testing in github actions as both of these are provided. Perhaps we actually can include both of these and can get old PRs based on commit hash, but until then we will just test using the PR number and ignore the commit_hash if we find both. --- .../detection_testing_execution.py | 4 +++- .../modules/github_service.py | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bin/automated_detection_testing/ci/detection_testing_batch/detection_testing_execution.py b/bin/automated_detection_testing/ci/detection_testing_batch/detection_testing_execution.py index 6e63261ef6..32e2d045bb 100644 --- a/bin/automated_detection_testing/ci/detection_testing_batch/detection_testing_execution.py +++ b/bin/automated_detection_testing/ci/detection_testing_batch/detection_testing_execution.py @@ -98,7 +98,7 @@ def copy_local_apps_to_directory(apps: dict[str, dict], target_directory) -> Non -def ensure_security_content(branch: str, commit_hash: str, pr_number: Union[int, None], persist_security_content: bool) -> tuple[GithubService, bool]: +def ensure_security_content(branch: str, commit_hash: Union[str,None], pr_number: Union[int, None], persist_security_content: bool) -> tuple[GithubService, bool]: if persist_security_content is True and os.path.exists("security_content"): print("****** You chose --persist_security_content and the security_content directory exists. " "We will not check out the repo again. Please be aware, this could cause issues if your " @@ -508,6 +508,8 @@ def main(args: list[str]): sys.exit(0) else: print("Test Execution Failed - review the logs for more details") + print("IN THE FUTURE, THIS WILL RETURN NONZERO CAUSING THE WORKFLOW TO FAIL!") + sys.exit(0) sys.exit(1) diff --git a/bin/automated_detection_testing/ci/detection_testing_batch/modules/github_service.py b/bin/automated_detection_testing/ci/detection_testing_batch/modules/github_service.py index a1962a710d..ffedd07ea2 100644 --- a/bin/automated_detection_testing/ci/detection_testing_batch/modules/github_service.py +++ b/bin/automated_detection_testing/ci/detection_testing_batch/modules/github_service.py @@ -24,7 +24,7 @@ SECURITY_CONTENT_URL = "https://github.com/splunk/security_content" class GithubService: - def __init__(self, security_content_branch: str, commit_hash: str, PR_number: int = None, persist_security_content: bool = False): + def __init__(self, security_content_branch: str, commit_hash: Union[str,None], PR_number: int = None, persist_security_content: bool = False): self.security_content_branch = security_content_branch if persist_security_content: @@ -44,12 +44,15 @@ class GithubService: "'git branch -a' to examine [%d] branches"%(security_content_branch, len(branch_names)))) - if commit_hash is not None and PR_number is not None: - raise(Exception("Error - both the PR number [%d] and the commit hash [%s] were provided. " - "Only 0 or 1 can be passed." % (PR_number, commit_hash))) + if commit_hash is not None and PR_number is not None: + print(f"\n************\nWARNING - both the PR_number {PR_number} and the commit_hash {commit_hash} were provided. " + f"You should only pass neither or one of these. We will ASSUME you want to use the PR_number, not the commit_hash. " + f"Removing the commit_hash...\n************\n") + commit_hash = None + - elif PR_number: + if PR_number: ret = subprocess.run(["git", "-C", "security_content/", "fetch", "origin", "refs/pull/%d/head:%s" % (PR_number, security_content_branch)], capture_output=True) #ret = subprocess.call(["git", "-C", "security_content/", "fetch", "origin",