Skip to content

Commit

Permalink
Merge pull request #54 from imonteroperez/review-duplicated-params
Browse files Browse the repository at this point in the history
Manage escape JQL based on JRASERVER-25092 and provide support for parameterized tests
  • Loading branch information
imonteroperez committed Apr 21, 2022
2 parents 0cc6208 + e2cd08e commit 6073bb4
Showing 1 changed file with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,19 @@ public static String createIssue(Job job, Job project, EnvVars envVars, CaseResu
IssueInput issueInput = JiraUtils.createIssueInput(project, test, envVars);
SearchResult searchResult = JiraUtils.findIssues(project, test, envVars, issueInput);
if (searchResult != null && searchResult.getTotal() > 0) {
boolean duplicate = false;
FieldInput fi = JiraTestDataPublisher.JiraTestDataPublisherDescriptor.templates.get(0).getFieldInput(test, envVars);
String id = issueInput.getField(fi.getId()).getValue().toString();
JiraUtils.log(String.format("Ignoring creating issue '%s' as it would be a duplicate. (from Jira server)", id));
String text = issueInput.getField(fi.getId()).getValue().toString();
for (Issue issue: searchResult.getIssues()) {
TestToIssueMapping.getInstance().addTestToIssueMapping(job, test.getId(), issue.getKey());
if (issue.getSummary().equals(text)) {
JiraUtils.log(String.format("Ignoring creating issue '%s' as it would be a duplicate. (from Jira server)", text));
duplicate = true;
TestToIssueMapping.getInstance().addTestToIssueMapping(job, test.getId(), issue.getKey());
}
}
if (duplicate) {
return null;
}
return null;
}
String issueKey = JiraUtils.createIssueInput(issueInput, test);
TestToIssueMapping.getInstance().addTestToIssueMapping(job, test.getId(), issueKey);
Expand Down Expand Up @@ -230,35 +236,30 @@ public static SearchResult findIssues(Job project, TestResult test, EnvVars envV
/**
* Escape the JQL query of special characters.
*
* Currently:
* + - & | ! ( ) { } [ ] ^ ~ * ? \ / :
*
* Reference:
* https://confluence.atlassian.com/jiracoreserver073/search-syntax-for-text-fields-861257223.html
* Based on https://jira.atlassian.com/browse/JRASERVER-25092, currently supported:
* + - & | ~ *
*
* Unsupported:
* ! ( ) { } ^ ? \ /
*
* Provides special support for parameterized tests by ignoring the parameter in [ ]
*
* @param jql the JQL query.
* @return the JQL query with special chars escaped.
*/
static String escapeJQL(String jql) {
return jql.replace("'","\\'")
String result = jql.replace("'","\\'")
.replace("\"","\\\"")
.replace("\\+", "\\\\+")
.replace("-", "\\\\-")
.replace("&", "\\\\&")
.replace("\\|", "\\\\|")
.replace("!", "\\\\!")
.replace("\\(", "\\\\(")
.replace("\\)", "\\\\)")
.replace("\\{", "\\\\{")
.replace("}", "\\\\}")
.replace("[", "\\\\[")
.replace("]", "\\\\]")
.replace("\\^", "\\\\^")
.replace("~", "\\\\~")
.replace("\\*", "\\\\*")
.replace("\\?", "\\\\\\?")
.replace("\\\\","\\\\\\\\")
.replace("\\/", "\\\\/")
.replace(":", "\\\\\\\\:");
.replace("\\*", "\\\\*");

if (result.contains("[")) {
result = result.substring(0, result.lastIndexOf("[")); // let's remove the parameter part
}
return result;
}
}

0 comments on commit 6073bb4

Please sign in to comment.