Skip to content

Commit a71f52b

Browse files
committed
Fixed the release server
1 parent c1e5aab commit a71f52b

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/main/java/me/TechsCode/ReleaseServer/GithubReleaseFetcher.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import me.TechsCode.ReleaseServer.objects.Project;
88
import org.apache.commons.io.IOUtils;
99

10+
import java.io.BufferedReader;
1011
import java.io.IOException;
12+
import java.io.InputStreamReader;
13+
import java.net.HttpURLConnection;
1114
import java.net.URL;
1215
import java.nio.charset.StandardCharsets;
1316
import java.util.ArrayList;
@@ -35,11 +38,26 @@ public void run() {
3538

3639
for(Project project : projects){
3740
try {
38-
String randomParameter = "?rnd="+random.nextInt();
39-
String accessTokenParameter = project.getGithubToken().isPresent() ? "&access_token="+project.getGithubToken().get() : "";
40-
String url = "https://api.github.com/repos/"+project.getGithubRepository()+"/releases"+randomParameter+accessTokenParameter;
41+
String accessTokenParameter = project.getGithubToken().isPresent() ? project.getGithubToken().get() : "";
42+
String urlString = "https://api.github.com/repos/"+project.getGithubRepository()+"/releases";
43+
44+
URL url = new URL(urlString);
45+
HttpURLConnection con = (HttpURLConnection) url.openConnection();
46+
con.setRequestMethod("GET");
47+
con.setRequestProperty("Authorization", "token "+accessTokenParameter);
48+
con.setRequestProperty("Accept", "application/json");
49+
50+
BufferedReader in = new BufferedReader(
51+
new InputStreamReader(con.getInputStream()));
52+
String inputLine;
53+
StringBuilder content = new StringBuilder();
54+
while ((inputLine = in.readLine()) != null) {
55+
content.append(inputLine);
56+
}
57+
in.close();
58+
con.disconnect();
4159

42-
JsonArray jsonArray = (JsonArray) JsonParser.parseString(IOUtils.toString(new URL(url), StandardCharsets.UTF_8));
60+
JsonArray jsonArray = JsonParser.parseString(content.toString()).getAsJsonArray();
4361

4462
for(JsonElement jsonElement : jsonArray){
4563
JsonObject release = (JsonObject) jsonElement;
@@ -63,6 +81,7 @@ public void run() {
6381
releases.add(new Release(project, id, name, uniqueTag, description, assets));
6482
}
6583
} catch (IOException e) {
84+
e.printStackTrace();
6685
System.out.println("Could not fetch releases for "+project.getName()+" ("+project.getGithubRepository()+")");
6786
}
6887
}

0 commit comments

Comments
 (0)