19
19
20
20
package org .commonwl .view .workflow ;
21
21
22
+ import org .apache .commons .lang .StringUtils ;
22
23
import org .commonwl .view .git .GitDetails ;
23
24
import org .slf4j .Logger ;
24
25
import org .slf4j .LoggerFactory ;
@@ -68,32 +69,50 @@ public GitDetails validateAndParse(WorkflowForm form, Errors e) {
68
69
// If not null and isn't just whitespace
69
70
if (!e .hasErrors ()) {
70
71
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
+
71
82
// Github URL
72
83
Matcher m = githubCwlPattern .matcher (form .getUrl ());
73
84
if (m .find ()) {
74
85
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 );
76
89
}
77
90
78
91
// Gitlab URL
79
92
m = gitlabCwlPattern .matcher (form .getUrl ());
80
93
if (m .find ()) {
81
94
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 );
83
98
}
84
99
85
100
// Github Dir URL
86
101
m = githubDirPattern .matcher (form .getUrl ());
87
102
if (m .find ()) {
88
103
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 );
90
107
}
91
108
92
109
// Gitlab Dir URL
93
110
m = gitlabDirPattern .matcher (form .getUrl ());
94
111
if (m .find ()) {
95
112
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 );
97
116
}
98
117
99
118
// General Git details if didn't match the above
@@ -110,4 +129,15 @@ public GitDetails validateAndParse(WorkflowForm form, Errors e) {
110
129
// Errors will stop this being used anyway
111
130
return null ;
112
131
}
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
+ }
113
143
}
0 commit comments