11package com .lezurex .githubversionchecker ;
22
3+ import com .lezurex .githubversionchecker .exceptions .RepoNotFoundException ;
4+
5+ import javax .net .ssl .HttpsURLConnection ;
6+ import java .io .IOException ;
7+ import java .net .HttpURLConnection ;
8+ import java .net .URL ;
9+
310public class GithubVersionChecker {
411
512 /**
@@ -10,13 +17,27 @@ public class GithubVersionChecker {
1017 * Name of the repository on GitHub
1118 */
1219 private final String repo ;
20+ private final ReleaseVersion currentVersion ;
1321
1422 /**
1523 * @param username Username where the targeted repo is located
1624 * @param repo Name of the repository on GitHub
25+ * @param currentVersion The current version running
1726 */
18- public GithubVersionChecker (String username , String repo ) {
27+ public GithubVersionChecker (String username , String repo , ReleaseVersion currentVersion ) {
1928 this .username = username ;
2029 this .repo = repo ;
30+ this .currentVersion = currentVersion ;
31+
32+ try {
33+ URL url = new URL (String .format ("https://api.github.com/repos/%s/%s" , this .username , this .repo ));
34+ HttpsURLConnection con = (HttpsURLConnection ) url .openConnection ();
35+ con .setRequestMethod ("GET" );
36+ if (con .getResponseCode () != HttpURLConnection .HTTP_OK ) {
37+ throw new RepoNotFoundException (this .username , this .repo );
38+ }
39+ } catch (IOException e ) {
40+ e .printStackTrace ();
41+ }
2142 }
2243}
0 commit comments