-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGithubDemo.java
69 lines (51 loc) · 2.17 KB
/
GithubDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import cc.carm.lib.githubreleases4j.GithubAsset;
import cc.carm.lib.githubreleases4j.GithubRelease;
import cc.carm.lib.githubreleases4j.GithubReleases4J;
import cc.carm.lib.githubreleases4j.GithubUser;
import java.io.IOException;
import java.util.List;
public class GithubDemo {
public void demo() {
List<GithubRelease> releases = GithubReleases4J.listReleases("Owner", "RepoName");
// List a public repository's current existing releases.
GithubRelease latestRelease = GithubReleases4J.getLatestRelease(
"Owner", "RepoName",
"Token" // OAuth token if it is a private repository.
); // Get the latest release of the repository
if (latestRelease != null) {
List<GithubAsset> assets = latestRelease.getAssets();
// Get the Release' assets list
for (GithubAsset asset : assets) {
try {
asset.download(); // Download by the original file name.
} catch (IOException exception) {
exception.printStackTrace();
}
GithubUser uploader = asset.getUploader(); // Get the uploader of this asset.
}
GithubUser author = latestRelease.getAuthor(); // Get the author of this release.
}
}
public void checkUpdate() {
String owner = "Owner";
String repository = "RepoName";
Integer behindVersions = GithubReleases4J.getVersionBehind(
owner, repository,
"Token",// OAuth token if it is a private repository.
"Current Version Tag"
);
if (behindVersions == null) {
System.out.println("Check failed! Please check updates manually.");
System.out.println("Download at " + GithubReleases4J.getReleasesURL(owner, repository));
} else if (behindVersions == 0) {
System.out.println("Check successfully, Now is up-to-date.");
} else if (behindVersions > 0) {
System.out.println("Outdated! Now behind " + behindVersions + " versions.");
System.out.println("Download latest version at " + GithubReleases4J.getLatestReleaseURL(owner, repository));
} else {
System.out.println("Check failed! Current version doesn't exists.");
System.out.println("Please use original version to avoid security issues.");
System.out.println("Download latest version at " + GithubReleases4J.getLatestReleaseURL(owner, repository));
}
}
}