Skip to content

Commit

Permalink
Fix the hardcoded query string bug for closeBuildSuccessGithubIssue (#…
Browse files Browse the repository at this point in the history
…265)

Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi authored Jul 28, 2023
1 parent 081bf34 commit 9539179
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jacocoTestReport {
}
}

String version = '5.4.0'
String version = '5.4.1'

task updateVersion {
doLast {
Expand Down
2 changes: 1 addition & 1 deletion tests/jenkins/TestCloseBuildSuccessGithubIssue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
3 changes: 2 additions & 1 deletion tests/jenkins/jobs/CloseBuildSuccessGithubIssue_JenkinsFile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import static org.hamcrest.MatcherAssert.assertThat

class CloseBuildSuccessGithubIssueLibTester extends LibFunctionTester{
private List<String> 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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion vars/closeBuildSuccessGithubIssue.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 <required> - message retrieved from buildMessage() method.
@param args.search <required> - Filter the logs based on the passed args.search.
@param args.inputManifestPath <required> - 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<String> 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())
Expand Down

0 comments on commit 9539179

Please sign in to comment.