Skip to content

Commit 748f4f0

Browse files
committed
Priority of branch and path parameters change
Override path/branch within smart URLs
1 parent 70b71f8 commit 748f4f0

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

src/main/java/org/commonwl/view/workflow/WorkflowFormValidator.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.commonwl.view.workflow;
2121

22+
import org.apache.commons.lang.StringUtils;
2223
import org.commonwl.view.git.GitDetails;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
@@ -68,32 +69,50 @@ public GitDetails validateAndParse(WorkflowForm form, Errors e) {
6869
// If not null and isn't just whitespace
6970
if (!e.hasErrors()) {
7071

72+
// Override if specific branch or path is given in the form
73+
String branch = null;
74+
String path = null;
75+
if (!isEmptyOrWhitespace(form.getBranch())) {
76+
branch = form.getBranch();
77+
}
78+
if (!isEmptyOrWhitespace(form.getPath())) {
79+
path = form.getPath();
80+
}
81+
7182
// Github URL
7283
Matcher m = githubCwlPattern.matcher(form.getUrl());
7384
if (m.find()) {
7485
String repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git";
75-
return new GitDetails(repoUrl, m.group(3), m.group(4));
86+
if (branch == null) branch = m.group(3);
87+
if (path == null) path = m.group(4);
88+
return new GitDetails(repoUrl, branch, path);
7689
}
7790

7891
// Gitlab URL
7992
m = gitlabCwlPattern.matcher(form.getUrl());
8093
if (m.find()) {
8194
String repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git";
82-
return new GitDetails(repoUrl, m.group(3), m.group(4));
95+
if (branch == null) branch = m.group(3);
96+
if (path == null) path = m.group(4);
97+
return new GitDetails(repoUrl, branch, path);
8398
}
8499

85100
// Github Dir URL
86101
m = githubDirPattern.matcher(form.getUrl());
87102
if (m.find()) {
88103
String repoUrl = "https://github.com/" + m.group(1) + "/" + m.group(2) + ".git";
89-
return new GitDetails(repoUrl, m.group(3), m.group(4));
104+
if (branch == null) branch = m.group(3);
105+
if (path == null) path = m.group(4);
106+
return new GitDetails(repoUrl, branch, path);
90107
}
91108

92109
// Gitlab Dir URL
93110
m = gitlabDirPattern.matcher(form.getUrl());
94111
if (m.find()) {
95112
String repoUrl = "https://gitlab.com/" + m.group(1) + "/" + m.group(2) + ".git";
96-
return new GitDetails(repoUrl, m.group(3), m.group(4));
113+
if (branch == null) branch = m.group(3);
114+
if (path == null) path = m.group(4);
115+
return new GitDetails(repoUrl, branch, path);
97116
}
98117

99118
// General Git details if didn't match the above
@@ -110,4 +129,15 @@ public GitDetails validateAndParse(WorkflowForm form, Errors e) {
110129
// Errors will stop this being used anyway
111130
return null;
112131
}
132+
133+
/**
134+
* Checks if a string is empty or whitespace
135+
* @param str The string to be checked
136+
* @return Whether the string is empty or whitespace
137+
*/
138+
private boolean isEmptyOrWhitespace(String str) {
139+
return (str == null ||
140+
str.length() == 0 ||
141+
StringUtils.isWhitespace(str));
142+
}
113143
}

0 commit comments

Comments
 (0)