Skip to content

Commit

Permalink
validateFieldConfigs json changed (#214)
Browse files Browse the repository at this point in the history
* fix typo

* seems json structure changed for publisher to JSONArray, adapted code to support that in case object is not found

* revert

Bump io.atlassian.fugue:fugue from 4.7.2 to 6.1.2 (#209) @dependabot[bot]
Bump jira-rest-client.version from 5.2.6 to 6.0.1 (#152) @dependabot[bot]

as they start to cause build issues

* fix spotless issues
  • Loading branch information
chcg authored Feb 13, 2025
1 parent a6f8dc2 commit e0ae79e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<jira-rest-client.version>6.0.1</jira-rest-client.version>
<fugue.version>6.1.2</fugue.version>
<jira-rest-client.version>5.2.8-platform7-12284590</jira-rest-client.version>
<fugue.version>4.7.2</fugue.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<spotbugs.threshold>High</spotbugs.threshold>
<spotless.check.skip>false</spotless.check.skip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
import java.util.List;
import java.util.Map;
import jenkins.model.Jenkins;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.JiraTestResultReporter.config.AbstractFields;
Expand Down Expand Up @@ -802,7 +804,28 @@ public FormValidation validateFieldConfigs(String jsonForm) throws FormException
// extracting the configurations for associated with this plugin (we receive the entire form)
StaplerRequest2 req = Stapler.getCurrentRequest2();
JSONObject jsonObject = JSONObject.fromObject(jsonForm);
JSONObject publishers = jsonObject.getJSONObject("publisher");
JSONObject publishers = null;
try {
publishers = jsonObject.getJSONObject("publisher");
} catch (JSONException e) {
JiraUtils.log("Error finding key publisher, try with array as format changed");
JSONArray publisherArray = jsonObject.getJSONArray("publisher");
// find the first array element which contains testDataPublishers
for (int i = 0; i < publisherArray.size(); i++) {
JSONObject arrayObject = publisherArray.getJSONObject(i);
for (Object o : arrayObject.keySet()) {
if (o.toString().equals("testDataPublishers")) {
publishers = arrayObject;
break;
}
}
}
}

if (publishers == null) {
return FormValidation.error("publisher object not found in json.\n");
}

JSONObject jiraPublisherJSON = null;

for (Object o : publishers.keySet()) {
Expand All @@ -821,7 +844,7 @@ public FormValidation validateFieldConfigs(String jsonForm) throws FormException
newInstancesFromHeteroList(req, jiraPublisherJSON.get("configs"), getListDescriptors());
if (configs == null) {
// nothing to validate
return FormValidation.ok("OK!");
return FormValidation.ok("OK! No validation done.");

Check warning on line 847 in src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 807-847 are not covered by tests
}
String projectKey = jiraPublisherJSON.getString("projectKey");
Long issueType = jiraPublisherJSON.getLong("issueType");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
<p>BUILD_RESULT</p>

<h3>WARNING: Your input will not be validated against the server's metadata. Check Jira to make sure you insert
a valid value for this field and use the Validate Fields button bellow, otherwise the plugin will fail to create your issue.</h3>
a valid value for this field and use the Validate Fields button below, otherwise the plugin will fail to create your issue.</h3>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
<p>BUILD_RESULT</p>

<h3>WARNING: Your input will not be validated against the server's metadata. Check Jira to make sure you insert
a valid value for this field and use the Validate Fields button bellow, otherwise the plugin will fail to create your issue.</h3>
a valid value for this field and use the Validate Fields button below, otherwise the plugin will fail to create your issue.</h3>
</div>

0 comments on commit e0ae79e

Please sign in to comment.