1
mirror of https://github.com/CarmJos/GithubReleases4J.git synced 2024-09-19 13:45:45 +00:00

[v1.3.0] [A] Add update checker demo.

This commit is contained in:
Carm Jos 2022-01-22 15:26:44 +08:00
parent 8445ac812d
commit 2cad1116b9
2 changed files with 27 additions and 0 deletions

View File

@ -39,6 +39,7 @@ To provide an easy way to fetch updates and download assets.
- Size
- ...
- Release's Assets Download
- Update check methods. (See demo)
## Dependency Usage

View File

@ -39,4 +39,30 @@ public class GithubDemo {
}
}
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("Outdated! Now behind " + behindVersions + " versions.");
System.out.println("Download latest version at " + GithubReleases4J.getLatestReleaseURL(owner, repository));
} else {
System.out.println("Now is using the latest version.");
}
}
}
}