19
19
20
20
package org .commonwl .view .git ;
21
21
22
+ import com .fasterxml .jackson .annotation .JsonAutoDetect ;
23
+ import com .fasterxml .jackson .annotation .JsonCreator ;
22
24
import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
23
25
import com .fasterxml .jackson .databind .JsonNode ;
24
26
import com .fasterxml .jackson .databind .ObjectMapper ;
28
30
import java .net .URISyntaxException ;
29
31
import java .nio .file .Path ;
30
32
import java .util .Objects ;
33
+
31
34
import org .commonwl .view .util .LicenseUtils ;
32
35
import org .slf4j .Logger ;
33
36
import org .slf4j .LoggerFactory ;
34
37
35
38
/** Represents all the parameters necessary to access a file/directory with Git */
36
39
@ JsonIgnoreProperties (
37
- value = {"internalUrl" },
40
+ value = {"internalUrl" , "logger" },
38
41
ignoreUnknown = true )
39
42
public class GitDetails implements Serializable {
40
43
@@ -45,6 +48,7 @@ public class GitDetails implements Serializable {
45
48
private String path ;
46
49
private String packedId ;
47
50
51
+ @ JsonCreator
48
52
public GitDetails (String repoUrl , String branch , String path ) {
49
53
this .repoUrl = repoUrl ;
50
54
@@ -110,16 +114,12 @@ public GitType getType() {
110
114
if (domain .startsWith ("www." )) {
111
115
domain = domain .substring (4 );
112
116
}
113
- switch (domain ) {
114
- case "github.com" :
115
- return GitType .GITHUB ;
116
- case "gitlab.com" :
117
- return GitType .GITLAB ;
118
- case "bitbucket.org" :
119
- return GitType .BITBUCKET ;
120
- default :
121
- return GitType .GENERIC ;
122
- }
117
+ return switch (domain ) {
118
+ case "github.com" -> GitType .GITHUB ;
119
+ case "gitlab.com" -> GitType .GITLAB ;
120
+ case "bitbucket.org" -> GitType .BITBUCKET ;
121
+ default -> GitType .GENERIC ;
122
+ };
123
123
} catch (URISyntaxException ex ) {
124
124
return GitType .GENERIC ;
125
125
}
@@ -133,27 +133,23 @@ public GitType getType() {
133
133
*/
134
134
public String getUrl (String branchOverride ) {
135
135
String packedPart = packedId == null ? "" : "#" + packedId ;
136
- switch (getType ()) {
137
- case GITHUB :
138
- case GITLAB :
139
- return "https://"
140
- + normaliseUrl (repoUrl ).replace (".git" , "" )
141
- + "/blob/"
142
- + branchOverride
143
- + "/"
144
- + path
145
- + packedPart ;
146
- case BITBUCKET :
147
- return "https://"
148
- + normaliseUrl (repoUrl ).replace (".git" , "" )
149
- + "/src/"
150
- + branchOverride
151
- + "/"
152
- + path
153
- + packedPart ;
154
- default :
155
- return repoUrl ;
156
- }
136
+ return switch (getType ()) {
137
+ case GITHUB , GITLAB -> "https://"
138
+ + normaliseUrl (repoUrl ).replace (".git" , "" )
139
+ + "/blob/"
140
+ + branchOverride
141
+ + "/"
142
+ + path
143
+ + packedPart ;
144
+ case BITBUCKET -> "https://"
145
+ + normaliseUrl (repoUrl ).replace (".git" , "" )
146
+ + "/src/"
147
+ + branchOverride
148
+ + "/"
149
+ + path
150
+ + packedPart ;
151
+ default -> repoUrl ;
152
+ };
157
153
}
158
154
159
155
/**
@@ -174,18 +170,15 @@ public String getUrl() {
174
170
public String getInternalUrl (String branchOverride ) {
175
171
String packedPart = packedId == null ? "" : "%23" + packedId ;
176
172
String pathPart = path .equals ("/" ) ? "" : "/" + path ;
177
- switch (getType ()) {
178
- case GITHUB :
179
- case GITLAB :
180
- return "/workflows/"
181
- + normaliseUrl (repoUrl ).replace (".git" , "" )
182
- + "/blob/"
183
- + branchOverride
184
- + pathPart
185
- + packedPart ;
186
- default :
187
- return "/workflows/" + normaliseUrl (repoUrl ) + "/" + branchOverride + pathPart + packedPart ;
188
- }
173
+ return switch (getType ()) {
174
+ case GITHUB , GITLAB -> "/workflows/"
175
+ + normaliseUrl (repoUrl ).replace (".git" , "" )
176
+ + "/blob/"
177
+ + branchOverride
178
+ + pathPart
179
+ + packedPart ;
180
+ default -> "/workflows/" + normaliseUrl (repoUrl ) + "/" + branchOverride + pathPart + packedPart ;
181
+ };
189
182
}
190
183
191
184
/**
@@ -211,25 +204,21 @@ public String getRawUrl(String branchOverride, String pathOverride) {
211
204
if (pathOverride == null ) {
212
205
pathOverride = path ;
213
206
}
214
- switch (getType ()) {
215
- case GITHUB :
216
- return "https://raw.githubusercontent.com/"
217
- + normaliseUrl (repoUrl ).replace ("github.com/" , "" ).replace (".git" , "" )
218
- + "/"
219
- + branchOverride
220
- + "/"
221
- + pathOverride ;
222
- case GITLAB :
223
- case BITBUCKET :
224
- return "https://"
225
- + normaliseUrl (repoUrl ).replace (".git" , "" )
226
- + "/raw/"
227
- + branchOverride
228
- + "/"
229
- + pathOverride ;
230
- default :
231
- return repoUrl ;
232
- }
207
+ return switch (getType ()) {
208
+ case GITHUB -> "https://raw.githubusercontent.com/"
209
+ + normaliseUrl (repoUrl ).replace ("github.com/" , "" ).replace (".git" , "" )
210
+ + "/"
211
+ + branchOverride
212
+ + "/"
213
+ + pathOverride ;
214
+ case GITLAB , BITBUCKET -> "https://"
215
+ + normaliseUrl (repoUrl ).replace (".git" , "" )
216
+ + "/raw/"
217
+ + branchOverride
218
+ + "/"
219
+ + pathOverride ;
220
+ default -> repoUrl ;
221
+ };
233
222
}
234
223
235
224
/**
0 commit comments