Do the same thing for getFromTag

This commit is contained in:
JFronny 2021-05-11 13:19:29 +02:00
parent 887d1d2233
commit e9c5038010
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
1 changed files with 8 additions and 10 deletions

View File

@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException; import java.io.IOException;
public class GitHubFetcher extends PackFetcher { public class GitHubFetcher extends PackFetcher {
@Override @Override
public String getSourceTypeName() { public String getSourceTypeName() {
return "github"; return "github";
@ -23,12 +22,12 @@ public class GitHubFetcher extends PackFetcher {
throw new Exception("Minimum source must contain \"user/repo\"."); throw new Exception("Minimum source must contain \"user/repo\".");
} }
/* "user/repo" - Gets from latest commit of main/master branch. */ //"user/repo" - Gets from latest commit of main/master branch.
else if (parts.length == 2) { else if (parts.length == 2) {
return getFromBranch(parts[0] + "/" + parts[1], null); return getFromBranch(baseUrl, null);
} }
/* "user/repo/branch/branchName" - Gets from latest commit of specified branch. */ //"user/repo/branch/branchName" - Gets from latest commit of specified branch.
else if (parts[2].equalsIgnoreCase("branch")) { else if (parts[2].equalsIgnoreCase("branch")) {
if (parts.length < 4) throw new Exception("Missing branch name in source definition."); if (parts.length < 4) throw new Exception("Missing branch name in source definition.");
else { else {
@ -37,7 +36,7 @@ public class GitHubFetcher extends PackFetcher {
} }
} }
/* "user/repo/release" - Gets from the latest release. */ //"user/repo/release" - Gets from the latest release.
else if (parts[2].equalsIgnoreCase("release")) { else if (parts[2].equalsIgnoreCase("release")) {
try { try {
JsonObject latestRelease = UrlUtils.readJsonFromURL("https://api.github.com/repos/" + parts[0] + "/" + parts[1] + "/releases/latest", JsonObject.class); JsonObject latestRelease = UrlUtils.readJsonFromURL("https://api.github.com/repos/" + parts[0] + "/" + parts[1] + "/releases/latest", JsonObject.class);
@ -61,11 +60,11 @@ public class GitHubFetcher extends PackFetcher {
} }
} }
/* "user/repo/tag/tagNum" - Gets from a specified tag. */ //"user/repo/tag/tagNum" - Gets from a specified tag.
else if (parts[2].equalsIgnoreCase("tag")) { else if (parts[2].equalsIgnoreCase("tag")) {
if (parts.length < 4) throw new Exception("Missing tag number in source definition."); if (parts.length < 4) throw new Exception("Missing tag number in source definition.");
else { else {
return getFromTag(parts[0], parts[1], parts[3]); return getFromTag(parts[0] + "/" + parts[1], parts[3]);
} }
} }
@ -85,9 +84,8 @@ public class GitHubFetcher extends PackFetcher {
return "https://codeload.github.com/" + repo + "/legacy.zip/refs/heads/" + branch; return "https://codeload.github.com/" + repo + "/legacy.zip/refs/heads/" + branch;
} }
private String getFromTag(String user, String repo, String tag) { private String getFromTag(String repo, String tag) {
Resclone.LOGGER.info("Getting from tag " + tag + "."); Resclone.LOGGER.info("Getting from tag " + tag + ".");
return "https://codeload.github.com/" + user + "/" + repo + "/legacy.zip/refs/tags/" + tag; return "https://codeload.github.com/" + repo + "/legacy.zip/refs/tags/" + tag;
} }
} }