From a8093f58cc6dd755ff75a2b8eabbd971da3ca30e Mon Sep 17 00:00:00 2001 From: Sadman Anik <36187489+sadmananik@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:02:05 +0600 Subject: [PATCH] Fix QualityGate failing (#160) --- .../coverity/CoverityParametersService.java | 2 +- .../polaris/PolarisParametersService.java | 2 +- .../scan/srm/SRMParametersService.java | 49 ++++++++++--------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/coverity/CoverityParametersService.java b/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/coverity/CoverityParametersService.java index 1548c89b..3fea9ae3 100644 --- a/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/coverity/CoverityParametersService.java +++ b/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/coverity/CoverityParametersService.java @@ -81,7 +81,7 @@ private List getCoverityMissingMandatoryParams(Map cover if (missingMandatoryParams.size() == 1) { message = missingMandatoryParams.get(0) + " is mandatory parameter for " + jobTypeName + " job type"; } else { - message = String.join(", ", missingMandatoryParams) + " is mandatory parameter for " + jobTypeName + message = String.join(", ", missingMandatoryParams) + " are mandatory parameter for " + jobTypeName + " job type"; } diff --git a/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/polaris/PolarisParametersService.java b/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/polaris/PolarisParametersService.java index f5f22020..e9ba38df 100644 --- a/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/polaris/PolarisParametersService.java +++ b/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/polaris/PolarisParametersService.java @@ -86,7 +86,7 @@ private List getPolarisMissingMandatoryParams(Map polari if (missingMandatoryParams.size() == 1) { message = missingMandatoryParams.get(0) + " is mandatory parameter for " + jobTypeName + " job type"; } else { - message = String.join(", ", missingMandatoryParams) + " is mandatory parameter for " + jobTypeName + message = String.join(", ", missingMandatoryParams) + " are mandatory parameter for " + jobTypeName + " job type"; } diff --git a/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/srm/SRMParametersService.java b/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/srm/SRMParametersService.java index d9f46bca..2b56045e 100644 --- a/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/srm/SRMParametersService.java +++ b/src/main/java/io/jenkins/plugins/synopsys/security/scan/service/scan/srm/SRMParametersService.java @@ -64,27 +64,7 @@ private List getSrmMissingMandatoryParams(Map srmParamet }); String jobType = Utility.jenkinsJobType(envVars); - if (!jobType.equalsIgnoreCase(ApplicationConstants.MULTIBRANCH_JOB_TYPE_NAME)) { - boolean isProjectNameValid = srmParameters.containsKey(ApplicationConstants.SRM_PROJECT_NAME_KEY) - && srmParameters.get(ApplicationConstants.SRM_PROJECT_NAME_KEY) != null - && !srmParameters - .get(ApplicationConstants.SRM_PROJECT_NAME_KEY) - .toString() - .isEmpty(); - - boolean isProjectIdValid = srmParameters.containsKey(ApplicationConstants.SRM_PROJECT_ID_KEY) - && srmParameters.get(ApplicationConstants.SRM_PROJECT_ID_KEY) != null - && !srmParameters - .get(ApplicationConstants.SRM_PROJECT_ID_KEY) - .toString() - .isEmpty(); - - if (!isProjectNameValid && !isProjectIdValid) { - logger.error("One of " + ApplicationConstants.SRM_PROJECT_NAME_KEY + " or " - + ApplicationConstants.SRM_PROJECT_ID_KEY + " must be present."); - missingMandatoryParams.add(ApplicationConstants.SRM_PROJECT_ID_KEY); - } - } + validateProjectParams(srmParameters, missingMandatoryParams, jobType); if (!missingMandatoryParams.isEmpty()) { String jobTypeName; @@ -99,7 +79,7 @@ private List getSrmMissingMandatoryParams(Map srmParamet if (missingMandatoryParams.size() == 1) { message = missingMandatoryParams.get(0) + " is mandatory parameter for " + jobTypeName + " job type"; } else { - message = String.join(", ", missingMandatoryParams) + " is mandatory parameter for " + jobTypeName + message = String.join(", ", missingMandatoryParams) + " are mandatory parameter for " + jobTypeName + " job type"; } @@ -109,6 +89,31 @@ private List getSrmMissingMandatoryParams(Map srmParamet return missingMandatoryParams; } + private void validateProjectParams( + Map srmParameters, List missingMandatoryParams, String jobType) { + if (!jobType.equalsIgnoreCase(ApplicationConstants.MULTIBRANCH_JOB_TYPE_NAME)) { + boolean isProjectNameValid = srmParameters.containsKey(ApplicationConstants.SRM_PROJECT_NAME_KEY) + && srmParameters.get(ApplicationConstants.SRM_PROJECT_NAME_KEY) != null + && !srmParameters + .get(ApplicationConstants.SRM_PROJECT_NAME_KEY) + .toString() + .isEmpty(); + + boolean isProjectIdValid = srmParameters.containsKey(ApplicationConstants.SRM_PROJECT_ID_KEY) + && srmParameters.get(ApplicationConstants.SRM_PROJECT_ID_KEY) != null + && !srmParameters + .get(ApplicationConstants.SRM_PROJECT_ID_KEY) + .toString() + .isEmpty(); + + if (!isProjectNameValid && !isProjectIdValid) { + logger.error("One of " + ApplicationConstants.SRM_PROJECT_NAME_KEY + " or " + + ApplicationConstants.SRM_PROJECT_ID_KEY + " must be present."); + missingMandatoryParams.add(ApplicationConstants.SRM_PROJECT_ID_KEY); + } + } + } + public SRM prepareSrmObjectForBridge(Map srmParameters) { SRM srm = new SRM(); Branch branch = new Branch();