From 1381a41fcb9fe6f01c42d8d15b2b8906f7e91ef4 Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Fri, 28 Jul 2023 15:41:35 -0700 Subject: [PATCH] Fix the hardcoded query string bug for closeBuildSuccessGithubIssue Signed-off-by: Prudhvi Godithi --- build.gradle | 2 +- tests/jenkins/TestCloseBuildSuccessGithubIssue.groovy | 2 +- .../jobs/CloseBuildSuccessGithubIssue_JenkinsFile | 3 ++- .../jobs/CloseBuildSuccessGithubIssue_JenkinsFile.txt | 2 +- .../CloseBuildSuccessGithubIssueLibTester.groovy | 10 +++++++++- vars/closeBuildSuccessGithubIssue.groovy | 4 +++- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 6f02cd940..ac324d9bf 100644 --- a/build.gradle +++ b/build.gradle @@ -120,7 +120,7 @@ jacocoTestReport { } } -String version = '5.4.0' +String version = '5.4.1' task updateVersion { doLast { diff --git a/tests/jenkins/TestCloseBuildSuccessGithubIssue.groovy b/tests/jenkins/TestCloseBuildSuccessGithubIssue.groovy index db79af40e..5b417dcf9 100644 --- a/tests/jenkins/TestCloseBuildSuccessGithubIssue.groovy +++ b/tests/jenkins/TestCloseBuildSuccessGithubIssue.groovy @@ -20,7 +20,7 @@ class TestCloseBuildSuccessGithubIssue extends BuildPipelineTest { @Override @Before void setUp() { - this.registerLibTester(new CloseBuildSuccessGithubIssueLibTester(['Build successful OpenSearch'])) + this.registerLibTester(new CloseBuildSuccessGithubIssueLibTester(['Successfully built OpenSearch'], "Successfully built", "tests/data/opensearch-2.0.0.yml")) super.setUp() } diff --git a/tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile b/tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile index 2121c74ff..d647a584d 100644 --- a/tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile +++ b/tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile @@ -14,7 +14,8 @@ pipeline { steps { script { closeBuildSuccessGithubIssue( - message: ["Build successful OpenSearch"], + message: ["Successfully built OpenSearch"], + search: "Successfully built", inputManifestPath: 'tests/data/opensearch-2.0.0.yml' ) } diff --git a/tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile.txt b/tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile.txt index 256ba579a..bb7666e05 100644 --- a/tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile.txt +++ b/tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile.txt @@ -3,7 +3,7 @@ CloseBuildSuccessGithubIssue_JenkinsFile.echo(Executing on agent [label:none]) CloseBuildSuccessGithubIssue_JenkinsFile.stage(notify, groovy.lang.Closure) CloseBuildSuccessGithubIssue_JenkinsFile.script(groovy.lang.Closure) - CloseBuildSuccessGithubIssue_JenkinsFile.closeBuildSuccessGithubIssue({message=[Build successful OpenSearch], inputManifestPath=tests/data/opensearch-2.0.0.yml}) + CloseBuildSuccessGithubIssue_JenkinsFile.closeBuildSuccessGithubIssue({message=[Successfully built OpenSearch], search=Successfully built, inputManifestPath=tests/data/opensearch-2.0.0.yml}) closeBuildSuccessGithubIssue.legacySCM(groovy.lang.Closure) closeBuildSuccessGithubIssue.library({identifier=jenkins@main, retriever=null}) closeBuildSuccessGithubIssue.readYaml({file=tests/data/opensearch-2.0.0.yml}) diff --git a/tests/jenkins/lib-testers/CloseBuildSuccessGithubIssueLibTester.groovy b/tests/jenkins/lib-testers/CloseBuildSuccessGithubIssueLibTester.groovy index ce674905c..acef202e3 100644 --- a/tests/jenkins/lib-testers/CloseBuildSuccessGithubIssueLibTester.groovy +++ b/tests/jenkins/lib-testers/CloseBuildSuccessGithubIssueLibTester.groovy @@ -12,9 +12,13 @@ import static org.hamcrest.MatcherAssert.assertThat class CloseBuildSuccessGithubIssueLibTester extends LibFunctionTester{ private List message + private String search + private String inputManifestPath - public CloseBuildSuccessGithubIssueLibTester(message){ + public CloseBuildSuccessGithubIssueLibTester(message, search, inputManifestPath){ this.message = message + this.search = search + this.inputManifestPath = inputManifestPath } @Override @@ -25,11 +29,15 @@ class CloseBuildSuccessGithubIssueLibTester extends LibFunctionTester{ @Override void parameterInvariantsAssertions(Object call) { assertThat(call.args.message.first(), notNullValue()) + assertThat(call.args.search.first(), notNullValue()) + assertThat(call.args.inputManifestPath.first(), notNullValue()) } @Override boolean expectedParametersMatcher(Object call) { return call.args.message.first().equals(this.message) + return call.args.search.first().equals(this.search) + return call.args.inputManifestPath.first().equals(this.inputManifestPath) } @Override diff --git a/vars/closeBuildSuccessGithubIssue.groovy b/vars/closeBuildSuccessGithubIssue.groovy index 228f04811..3adc0fe10 100644 --- a/vars/closeBuildSuccessGithubIssue.groovy +++ b/vars/closeBuildSuccessGithubIssue.groovy @@ -9,14 +9,16 @@ /** Library to close GitHub issue across opensearch-project repositories. @param Map args = [:] args A map of the following parameters @param args.message - message retrieved from buildMessage() method. + @param args.search - Filter the logs based on the passed args.search. @param args.inputManifestPath - Path to input manifest. */ void call(Map args = [:]) { lib = library(identifier: 'jenkins@main', retriever: legacySCM(scm)) def passMessages = args.message + def queryString = args.search List passedComponents = [] for (message in passMessages.unique()) { - java.util.regex.Matcher match = (message =~ /(?<=\bBuild successful\s).*/) + java.util.regex.Matcher match = (message =~ /(?<=\b${queryString}\s).*/) String matched = match[0] println(matched.split(" ")[0].trim()) passedComponents.add(matched.split(" ")[0].trim())