Skip to content

Commit

Permalink
[JENKINS-73900] Un-inline JS in ModuleLocation/config.jelly and fix…
Browse files Browse the repository at this point in the history
… validation logic (#319)
  • Loading branch information
shlomomdahan authored Nov 5, 2024
1 parent 5465ce1 commit c8837f9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
18 changes: 10 additions & 8 deletions src/main/java/hudson/scm/SubversionSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -2543,15 +2543,17 @@ public FormValidation doCheckExcludedCommitMessages(@QueryParameter String value
* Validates the remote server supports custom revision properties
*/
@RequirePOST
public FormValidation doCheckRevisionPropertiesSupported(@AncestorInPath Item context,
public FormValidation doCheckExcludedRevprop(@AncestorInPath Item context,
@QueryParameter String value,
@QueryParameter String credentialsId,
@QueryParameter String excludedRevprop) throws IOException, ServletException {
String v = Util.fixNull(value).trim();
@QueryParameter String remoteLocation,
@QueryParameter String remoteCredentialsId
) throws IOException, ServletException {

String v = Util.fixNull(remoteLocation).trim();
if (v.length() == 0)
return FormValidation.ok();

String revprop = Util.fixNull(excludedRevprop).trim();
String revprop = Util.fixNull(value).trim();
if (revprop.length() == 0)
return FormValidation.ok();

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

try {
SVNURL repoURL = SVNURL.parseURIDecoded(new EnvVars(EnvVars.masterEnvVars).expand(v));
StandardCredentials credentials = lookupCredentials(context, credentialsId, repoURL);
StandardCredentials credentials = lookupCredentials(context, remoteCredentialsId, repoURL);

Check warning on line 2566 in src/main/java/hudson/scm/SubversionSCM.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 2556-2566 are not covered by tests
SVNNodeKind node = null;
try {
node = checkRepositoryPath(context,repoURL, credentials);
Expand Down Expand Up @@ -3200,10 +3202,10 @@ public ListBoxModel fillCredentialsIdItems(@CheckForNull Item context, String re
*/
@RequirePOST
public FormValidation doCheckRemote(/* TODO unused, delete */StaplerRequest req, @AncestorInPath Item context,

Check warning on line 3204 in src/main/java/hudson/scm/SubversionSCM.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: unused, delete */StaplerRequest req, @AncestorInPath Item context,
@QueryParameter String remote) {
@QueryParameter String value) {

// repository URL is required
String url = Util.fixEmptyAndTrim(remote);
String url = Util.fixEmptyAndTrim(value);
if (url == null) {
return FormValidation.error(Messages.SubversionSCM_doCheckRemote_required());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,14 @@ THE SOFTWARE.

<?jelly escape-by-default='true'?>
<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">

<f:entry title="${%Repository URL}" field="remote" help="/scm/SubversionSCM/url-help">
<f:textbox checkMethod="post" id="svn.remote.loc" onchange="{ /* workaround for JENKINS-19124 */
var self=this.targetElement ? this.targetElement : this;
var r=findNextFormItem(self,'credentialsId');
r.onchange(r);
if (self===document.getElementById('svn.remote.loc')){
r=findNextFormItem(self,'excludedRevprop');
r.onchange(r);
}
self=null;
r=null;
}"/>
<f:textbox />
</f:entry>
<f:entry title="${%Credentials}" field="credentialsId">
<c:select checkMethod="post"/>
</f:entry>

<f:entry title="${%Local module directory}" field="local">
<f:textbox value="${instance!=null?instance.local:'.'}"/>
</f:entry>
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/hudson/scm/SubversionSCM/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ THE SOFTWARE.
<f:entry title="${%Excluded Commit Messages}" field="excludedCommitMessages">
<f:textarea />
</f:entry>

<st:adjunct includes="hudson.scm.SubversionSCM.excludedRevprop-validation" />
<f:invisibleEntry>
<f:textbox field="remoteLocation" clazz="svn-remote-location-hidden"/>
</f:invisibleEntry>
<f:invisibleEntry>
<f:textbox field="remoteCredentialsId" clazz="svn-credentials-id-hidden"/>
</f:invisibleEntry>
<f:entry title="${%Exclusion revprop name}" field="excludedRevprop">
<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)"/>
<f:textbox />
</f:entry>
<f:entry title="${%Filter changelog}" field="filterChangelog">
<f:checkbox />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Behaviour.specify("input[name='_.remote']", 'SubversionSCM.RemoteLocation', 0, function(element) {
element.addEventListener('blur', updateHiddenFields);
});

Behaviour.specify("select[name='_.credentialsId'][filldependson='remote']", 'SubversionSCM.CredentialsId', 0, function(element) {
element.addEventListener('change', updateHiddenFields);
});

function updateHiddenFields() {

var remoteLocationElement = document.querySelector("input[name='_.remote']");
var credentialsIdElement = document.querySelector("select[name='_.credentialsId'][filldependson='remote']");
var selectedOption = credentialsIdElement.options[credentialsIdElement.selectedIndex].value;


var remoteHidden = document.querySelector(".svn-remote-location-hidden");
var credentialsHidden = document.querySelector(".svn-credentials-id-hidden");

if (remoteHidden) {
remoteHidden.value = remoteLocationElement.value;
}

if (credentialsHidden) {
credentialsHidden.value = selectedOption;
}

var revPropField = document.querySelector("input[name='_.excludedRevprop']");
if (revPropField) {
revPropField.dispatchEvent(new Event('change'));
}
}

0 comments on commit c8837f9

Please sign in to comment.