Resclone/src/main/java/io/gitlab/jfronny/resclone/fetchers/GithubMasterFetcher.java

36 lines
1.0 KiB
Java
Raw Normal View History

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