Skip to content

Commit 3b74415

Browse files
committed
rawGit for any path
1 parent 3567338 commit 3b74415

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/main/java/org/commonwl/view/git/GitDetails.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,39 @@ public String getInternalUrl() {
171171

172172
/**
173173
* Get the URL directly to the resource
174-
* @param branchOverride The branch to use instead of the one in this instance
174+
* @param branchOverride The branch to use, or <code>null</code> to use this instance's branch
175+
* @param pathOverride The path to use, or <code>null</code> to use this instance's path
175176
* @return The URL
176177
*/
177-
public String getRawUrl(String branchOverride) {
178+
public String getRawUrl(String branchOverride, String pathOverride) {
179+
if (branchOverride == null) {
180+
branchOverride = branch;
181+
}
182+
if (pathOverride == null) {
183+
pathOverride = path;
184+
}
178185
switch (getType()) {
179-
case GITHUB:
180-
return "https://raw.githubusercontent.com/" +
181-
normaliseUrl(repoUrl).replace("github.com/", "").replace(".git", "") +
182-
"/" + branchOverride + "/" + path;
183-
case GITLAB:
184-
case BITBUCKET:
185-
return "https://" + normaliseUrl(repoUrl).replace(".git", "")
186-
+ "/raw/" + branchOverride + "/" + path;
187-
default:
188-
return repoUrl;
186+
case GITHUB:
187+
return "https://raw.githubusercontent.com/" +
188+
normaliseUrl(repoUrl).replace("github.com/", "").replace(".git", "") +
189+
"/" + branchOverride + "/" + pathOverride;
190+
case GITLAB:
191+
case BITBUCKET:
192+
return "https://" + normaliseUrl(repoUrl).replace(".git", "")
193+
+ "/raw/" + branchOverride + "/" + pathOverride;
194+
default:
195+
return repoUrl;
189196
}
190197
}
198+
199+
/**
200+
* Get the URL directly to the resource
201+
* @param branchOverride The branch to use instead of the one in this instance
202+
* @return The URL
203+
*/
204+
public String getRawUrl(String branchOverride) {
205+
return getRawUrl(branchOverride, path);
206+
}
191207

192208
/**
193209
* Get the URL directly to the resource

0 commit comments

Comments
 (0)