Skip to content

Commit c8837f9

Browse files
authored
[JENKINS-73900] Un-inline JS in ModuleLocation/config.jelly and fix validation logic (#319)
1 parent 5465ce1 commit c8837f9

File tree

4 files changed

+53
-20
lines changed

4 files changed

+53
-20
lines changed

src/main/java/hudson/scm/SubversionSCM.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,15 +2543,17 @@ public FormValidation doCheckExcludedCommitMessages(@QueryParameter String value
25432543
* Validates the remote server supports custom revision properties
25442544
*/
25452545
@RequirePOST
2546-
public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Item context,
2546+
public FormValidation doCheckExcludedRevprop(@AncestorInPath Item context,
25472547
@QueryParameter String value,
2548-
@QueryParameter String credentialsId,
2549-
@QueryParameter String excludedRevprop) throws IOException, ServletException {
2550-
String v = Util.fixNull(value).trim();
2548+
@QueryParameter String remoteLocation,
2549+
@QueryParameter String remoteCredentialsId
2550+
) throws IOException, ServletException {
2551+
2552+
String v = Util.fixNull(remoteLocation).trim();
25512553
if (v.length() == 0)
25522554
return FormValidation.ok();
25532555

2554-
String revprop = Util.fixNull(excludedRevprop).trim();
2556+
String revprop = Util.fixNull(value).trim();
25552557
if (revprop.length() == 0)
25562558
return FormValidation.ok();
25572559

@@ -2561,7 +2563,7 @@ public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Item co
25612563

25622564
try {
25632565
SVNURL repoURL = SVNURL.parseURIDecoded(new EnvVars(EnvVars.masterEnvVars).expand(v));
2564-
StandardCredentials credentials = lookupCredentials(context, credentialsId, repoURL);
2566+
StandardCredentials credentials = lookupCredentials(context, remoteCredentialsId, repoURL);
25652567
SVNNodeKind node = null;
25662568
try {
25672569
node = checkRepositoryPath(context,repoURL, credentials);
@@ -3200,10 +3202,10 @@ public ListBoxModel fillCredentialsIdItems(@CheckForNull Item context, String re
32003202
*/
32013203
@RequirePOST
32023204
public FormValidation doCheckRemote(/* TODO unused, delete */StaplerRequest req, @AncestorInPath Item context,
3203-
@QueryParameter String remote) {
3205+
@QueryParameter String value) {
32043206

32053207
// repository URL is required
3206-
String url = Util.fixEmptyAndTrim(remote);
3208+
String url = Util.fixEmptyAndTrim(value);
32073209
if (url == null) {
32083210
return FormValidation.error(Messages.SubversionSCM_doCheckRemote_required());
32093211
}

src/main/resources/hudson/scm/SubversionSCM/ModuleLocation/config.jelly

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,14 @@ THE SOFTWARE.
2424

2525
<?jelly escape-by-default='true'?>
2626
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:c="/lib/credentials">
27+
2728
<f:entry title="${%Repository URL}" field="remote" help="/scm/SubversionSCM/url-help">
28-
<f:textbox checkMethod="post" id="svn.remote.loc" onchange="{ /* workaround for JENKINS-19124 */
29-
var self=this.targetElement ? this.targetElement : this;
30-
var r=findNextFormItem(self,'credentialsId');
31-
r.onchange(r);
32-
if (self===document.getElementById('svn.remote.loc')){
33-
r=findNextFormItem(self,'excludedRevprop');
34-
r.onchange(r);
35-
}
36-
self=null;
37-
r=null;
38-
}"/>
29+
<f:textbox />
3930
</f:entry>
4031
<f:entry title="${%Credentials}" field="credentialsId">
4132
<c:select checkMethod="post"/>
4233
</f:entry>
34+
4335
<f:entry title="${%Local module directory}" field="local">
4436
<f:textbox value="${instance!=null?instance.local:'.'}"/>
4537
</f:entry>

src/main/resources/hudson/scm/SubversionSCM/config.jelly

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,16 @@ THE SOFTWARE.
5656
<f:entry title="${%Excluded Commit Messages}" field="excludedCommitMessages">
5757
<f:textarea />
5858
</f:entry>
59+
60+
<st:adjunct includes="hudson.scm.SubversionSCM.excludedRevprop-validation" />
61+
<f:invisibleEntry>
62+
<f:textbox field="remoteLocation" clazz="svn-remote-location-hidden"/>
63+
</f:invisibleEntry>
64+
<f:invisibleEntry>
65+
<f:textbox field="remoteCredentialsId" clazz="svn-credentials-id-hidden"/>
66+
</f:invisibleEntry>
5967
<f:entry title="${%Exclusion revprop name}" field="excludedRevprop">
60-
<f:textbox checkMethod="post" checkUrl="'descriptorByName/hudson.scm.SubversionSCM/checkRevisionPropertiesSupported?value='+toValue(document.getElementById('svn.remote.loc'))+'&amp;credentialsId='+toValue(document.getElementById('svn.remote.cred'))+'&amp;excludedRevprop='+toValue(this)"/>
68+
<f:textbox />
6169
</f:entry>
6270
<f:entry title="${%Filter changelog}" field="filterChangelog">
6371
<f:checkbox />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Behaviour.specify("input[name='_.remote']", 'SubversionSCM.RemoteLocation', 0, function(element) {
2+
element.addEventListener('blur', updateHiddenFields);
3+
});
4+
5+
Behaviour.specify("select[name='_.credentialsId'][filldependson='remote']", 'SubversionSCM.CredentialsId', 0, function(element) {
6+
element.addEventListener('change', updateHiddenFields);
7+
});
8+
9+
function updateHiddenFields() {
10+
11+
var remoteLocationElement = document.querySelector("input[name='_.remote']");
12+
var credentialsIdElement = document.querySelector("select[name='_.credentialsId'][filldependson='remote']");
13+
var selectedOption = credentialsIdElement.options[credentialsIdElement.selectedIndex].value;
14+
15+
16+
var remoteHidden = document.querySelector(".svn-remote-location-hidden");
17+
var credentialsHidden = document.querySelector(".svn-credentials-id-hidden");
18+
19+
if (remoteHidden) {
20+
remoteHidden.value = remoteLocationElement.value;
21+
}
22+
23+
if (credentialsHidden) {
24+
credentialsHidden.value = selectedOption;
25+
}
26+
27+
var revPropField = document.querySelector("input[name='_.excludedRevprop']");
28+
if (revPropField) {
29+
revPropField.dispatchEvent(new Event('change'));
30+
}
31+
}

0 commit comments

Comments
 (0)