-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Low
-
Affects Version/s: None
-
Component/s: Pull Requests
-
None
This is pretty minor, as there are no built in Pull Request settings that can actually fail to validate, but it may cause problems for plugins.
If there is an error on the PR settings page, the build status will be reset to "enabled" and "1" because of the logic in com.atlassian.stash.internal.build.hook.RequiredBuildsFormFragment#doError:
@Override
public void doError(Appendable appendable, Map<String, String[]> requestParams, Map<String, Collection<String>> fieldErrors, Map<String, Object> context) throws IOException {
context.put(FIELD_KEY, 1); // default to 1 since the submitted number of required builds was either negative, too large or not a number
context.put(FIELD_MAX_VALUE, MAX_BUILDS);
context.put(FIELD_ERRORS, fieldErrors);
renderView(appendable, context);
}
doError is actually called if any setting fails to validate, not just this particular form fragment (see the contract on com.atlassian.stash.ui.ContextualFormFragment#doError).
com.atlassian.stash.internal.plugin.hooks.approvers.RequiredApproversFormFragment#doError suffers from the same problem.
The correct behaviour should retrieve the actual value from the form submission in the request parameters. The AutoUnapproveFormFragment in the stash-auto-unapprove-plugin does it correctly. See https://bitbucket.org/atlassian/stash-auto-unapprove-plugin/src/dc27236927c67e04be28d6a989bf30c895ed9c71/src/main/java/com/atlassian/stash/unapprove/AutoUnapproveFormFragment.java?at=master#cl-36