-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-9 Refactor updater to gitcheck. Improve API to check update.
- Loading branch information
Showing
32 changed files
with
1,150 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Contributing to GitCheck | ||
We welcome contributions to GitCheck! Here are some guidelines to follow: | ||
|
||
## Submitting Issues | ||
If you find a bug or have a feature request, please submit an issue on GitHub. Be sure to include as much information as possible, such as the version of GitCheck you are using, and steps to reproduce the issue. | ||
|
||
## Pull Requests | ||
We welcome pull requests! | ||
If you would like to make changes to the code, please fork the repository, create a new branch, and submit a pull request. | ||
Be sure to include a detailed description of the changes you have made, and include any relevant test cases. | ||
Make sure to follow the code style of the project. :) | ||
|
||
## License | ||
By contributing to GitCheck, you agree that your contributions will be licensed under the [MIT License](../LICENSE). | ||
|
||
Thank you for your interest in contributing to GitCheck! We look forward to reviewing your pull requests and issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Java CI and Test with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
name: "Build with JDK${{ matrix.jdk }}" | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
jdk: [ 9, 11, 17 ] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK ${{ matrix.jdk }} | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: ${{ matrix.jdk }} | ||
distribution: 'adopt' | ||
cache: gradle | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew clean build | ||
|
||
- name: Test with Gradle | ||
run: ./gradlew clean test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Publish package to Maven Repository | ||
|
||
on: | ||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
publish: | ||
name: "Publish to Maven Repository" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: 17 | ||
cache: 'gradle' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
|
||
- name: Publish with Gradle | ||
run: ./gradlew clean build publish | ||
env: | ||
ETERNALCODE_REPO_USERNAME: ${{ secrets.ETERNALCODE_REPO_USERNAME }} | ||
ETERNALCODE_REPO_PASSWORD: ${{ secrets.ETERNALCODE_REPO_PASSWORD }} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,80 @@ | ||
# Updater | ||
# GitCheck | ||
GitCheck is a Java library that makes it easy to check for updates to a GitHub repository. | ||
It utilizes the GitHub API to retrieve information about the latest release and compares it to the current version of your application. | ||
With GitCheck, you can ensure that your users are always running the latest version of your software. | ||
|
||
#### Updater is a library for checking for updates for your plugin on GitHub. It uses the GitHub API to get information about the latest release of your plugin and compare it to the current version of your plugin. | ||
## Features | ||
- Simple and easy-to-use API | ||
- Lightweight and efficient | ||
- Supports Java 9 and above | ||
- Utilizes the GitHub API for retrieving release information | ||
- You can add your own implementation for another platform | ||
|
||
### Usage | ||
First, you need to create an instance of the `Updater` class by passing the plugin name, current version, and Github repository name as arguments. Then, you can call the `checkUpdates()` method to check for updates and get the `RemoteInformation` object. | ||
## Installation | ||
|
||
The `RemoteInformation` object contains information about the update, such as the availability of a new version, the current version, and the download URI. | ||
To use GitCheck in your project, if you are using Gradle, add the following to your `build.gradle` file: | ||
|
||
```java | ||
if (remoteInformation.isAvailableNewVersion()) { | ||
System.out.println("A new version is available: " + remoteInformation.getCurrentVersion()); | ||
System.out.println("Download URI: " + remoteInformation.getDownloadUri()); | ||
} else { | ||
System.out.println("You are already running the latest version."); | ||
} | ||
```kotlin | ||
maven { url = uri("https://repo.eternalcode.pl/releases") } | ||
``` | ||
|
||
### Example | ||
Here's an example of how to can use the Updater in `Spigot` plugin | ||
|
||
```java | ||
|
||
import com.eternalcode.updater.Updater; | ||
import com.eternalcode.updater.http.RemoteInformation; | ||
|
||
public class MyPlugin { | ||
```kotlin | ||
implementation("com.eternalcode:gitcheck:1.0.0") | ||
``` | ||
|
||
private Updater updater; | ||
Or, if you are using Maven, add the following to your `pom.xml` file: | ||
|
||
public void onEnable() { | ||
updater = new Updater("MyPlugin", "1.0", "MyGithubUsername/MyPlugin"); | ||
checkForUpdates(); | ||
} | ||
```xml | ||
<repository> | ||
<id>eternalcode-releases</id> | ||
<url>https://repo.eternalcode.pl/releases</url> | ||
</repository> | ||
``` | ||
|
||
private void checkForUpdates() { | ||
RemoteInformation remoteInformation = updater.checkUpdates(); | ||
if (remoteInformation.isAvailableNewVersion()) { | ||
System.out.println("A new version is available: " + remoteInformation.getCurrentVersion()); | ||
System.out.println("Download URI: " + remoteInformation.getDownloadUri()); | ||
} else { | ||
System.out.println("You are already running the latest version."); | ||
} | ||
} | ||
} | ||
```xml | ||
<dependency> | ||
<groupId>com.eternalcode</groupId> | ||
<artifactId>gitcheck</artifactId> | ||
<version>1.0.0</version> | ||
</dependency> | ||
``` | ||
|
||
### Maven/Gradle | ||
Get the latest version from [EternalCode Repository](https://repo.eternalcode.pl/#/releases/com/eternalcode/updater) | ||
## API Usage | ||
|
||
#### gradle groovy | ||
```groovy | ||
maven { url "https://repo.eternalcode.pl/releases" } | ||
To use GitCheck, you need to create an instance of the `GitCheck` class. | ||
Create `GitRepository` and `GitTag` objects to specify the repository and the current version of your application. | ||
Then, call the `checkRelease` method to check for updates. | ||
|
||
implementation "com.eternalcode:updater:{VERSION}" | ||
``` | ||
```java | ||
public class MyApplication { | ||
|
||
```kotlin | ||
maven { url = uri("https://repo.eternalcode.pl/releases") } | ||
public static void main(String[] args) { | ||
GitCheck gitCheck = new GitCheck(); | ||
GitRepository repository = GitRepository.of("Owner", "Project"); | ||
|
||
implementation("com.eternalcode:updater:{VERSION}") | ||
``` | ||
GitCheckResult result = gitCheck.checkRelease(repository, GitTag.of("v1.0.0")); | ||
|
||
```xml | ||
<repository> | ||
<id>eternalcode-reposilite-releases</id> | ||
<name>EternalCode Repository</name> | ||
<url>https://repo.eternalcode.pl/releases</url> | ||
</repository> | ||
if (!result.isUpToDate()) { | ||
GitRelease release = result.getLatestRelease(); | ||
GitTag tag = release.getTag(); | ||
|
||
<dependency> | ||
<groupId>com.eternalcode</groupId> | ||
<artifactId>updater</artifactId> | ||
<version>{VERSION}</version> | ||
</dependency> | ||
``` | ||
System.out.println("A new version is available: " + tag.getTag()); | ||
System.out.println("See release page: " + release.getPageUrl()); | ||
System.out.println("Release date: " + release.getPublishedAt()); | ||
} | ||
|
||
// ... | ||
} | ||
|
||
} | ||
``` | ||
In this example, `GitCheck` is used to check for updates to the repository `Owner/Project` with the current version `v1.0.0`. | ||
If a new version is available, the details of the release are printed to the console. | ||
|
||
## Contributing | ||
We welcome contributions to GitCheck! | ||
If you have an idea for a new feature or have found a bug that needs to be fixed, you can [open an issue](https://github.com/EternalCodeTeam/GitCheck/issues/new) or [submit a pull request](https://github.com/EternalCodeTeam/GitCheck/compare) with your changes.<br> | ||
See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more information. | ||
|
||
## License | ||
GitCheck is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
rootProject.name = "eternalupdater" | ||
rootProject.name = "gitcheck" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.eternalcode.gitcheck; | ||
|
||
import com.eternalcode.gitcheck.git.GitRelease; | ||
import com.eternalcode.gitcheck.git.GitReleaseProvider; | ||
import com.eternalcode.gitcheck.git.GitRepository; | ||
import com.eternalcode.gitcheck.git.GitTag; | ||
import com.eternalcode.gitcheck.github.GitHubReleaseProvider; | ||
import com.eternalcode.gitcheck.shared.Preconditions; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Service for checking if the latest release is up to date. | ||
* <p> | ||
* This service uses {@link GitReleaseProvider} to get the latest release and compares it with the current tag. | ||
* The current tag is provided by {@link GitTag#of(String)} | ||
* <br> | ||
*/ | ||
public class GitCheck { | ||
|
||
private final GitReleaseProvider versionProvider; | ||
|
||
/** | ||
* Creates a new instance of {@link GitCheck} with the default {@link GitHubReleaseProvider}. | ||
*/ | ||
public GitCheck() { | ||
this(new GitHubReleaseProvider()); | ||
} | ||
|
||
/** | ||
* Creates a new instance of {@link GitCheck} with the given {@link GitReleaseProvider}. | ||
* | ||
* @param versionProvider the version provider | ||
*/ | ||
public GitCheck(@NotNull GitReleaseProvider versionProvider) { | ||
Preconditions.notNull(versionProvider, "release provider"); | ||
this.versionProvider = versionProvider; | ||
} | ||
|
||
/** | ||
* Gets the latest release for the given repository. | ||
* | ||
* @param repository the repository | ||
* @return the latest release | ||
*/ | ||
@NotNull | ||
public GitRelease getLatestRelease(@NotNull GitRepository repository) { | ||
Preconditions.notNull(repository, "repository"); | ||
|
||
return this.versionProvider.getLatestRelease(repository); | ||
} | ||
|
||
/** | ||
* Creates a new instance of {@link GitCheckResult} for the given repository and tag. | ||
* Result contains the latest release and the current tag. | ||
* Use {@link GitCheckResult#isUpToDate()} to check if the latest release is up to date. | ||
* | ||
* @param repository the repository | ||
* @param currentTag the current tag | ||
* @return the result | ||
*/ | ||
@NotNull | ||
public GitCheckResult checkRelease(@NotNull GitRepository repository, @NotNull GitTag currentTag) { | ||
Preconditions.notNull(repository, "repository"); | ||
Preconditions.notNull(currentTag, "current tag"); | ||
|
||
GitRelease latestRelease = this.getLatestRelease(repository); | ||
return new GitCheckResult(latestRelease, currentTag); | ||
} | ||
|
||
} |
Oops, something went wrong.