Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 5.x] Fix the hardcoded query string bug for closeBuildSuccessGithubIssue #266

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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({[email protected], 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: '[email protected]', 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
Loading