Fixed "github-master" type URLs

This commit is contained in:
seasnail8169 2021-04-03 01:41:03 +01:00
parent 2123042c9a
commit eb1f0c29d5
1 changed files with 19 additions and 15 deletions

View File

@ -1,32 +1,36 @@
package io.gitlab.jfronny.resclone.fetchers; package io.gitlab.jfronny.resclone.fetchers;
import io.gitlab.jfronny.resclone.data.RescloneException; import io.gitlab.jfronny.resclone.util.UrlUtils;
public class GithubMasterFetcher extends PackFetcher { public class GithubMasterFetcher extends PackFetcher {
@Override @Override
public String getSourceTypeName() { public String getSourceTypeName() {
return "github-master"; return "github-master";
} }
@Override @Override
public String getDownloadUrl(String baseUrl) throws RescloneException { public String getDownloadUrl(String baseUrl) throws Exception {
String[] parts = baseUrl.split("/"); String[] parts = baseUrl.split("/");
String url = ""; String url;
if (parts.length == 2) {
url = getStr(parts[0], parts[1], "main"); switch (parts.length) {
if (!urlValid(url)) case 2:
url = getStr(parts[0], parts[1], "master"); url = getStr(parts[0], parts[1], "main");
} if (!UrlUtils.urlValid(url)) url = getStr(parts[0], parts[1], "master");
else if (parts.length == 3) { break;
url = getStr(parts[0], parts[1], parts[2]); case 3:
} url = getStr(parts[0], parts[1], parts[2]);
else { break;
throw new RescloneException("Format for github-master is USER/REPO[/BRANCH]"); default:
throw new Exception("Format for github-master is USER/REPO[/BRANCH]");
} }
return url; return url;
} }
private String getStr(String user, String repo, String branch) { private String getStr(String user, String repo, String branch) {
return "https://github.com/" + user + "/" + repo + "/archive/" + branch + ".zip"; return "https://github.com/" + user + "/" + repo + "/archive/refs/heads/" + branch + ".zip";
} }
}
}