Skip to content

Commit 5b61e7a

Browse files
authored
GH-9 Refactor updater to gitcheck. Improve API to check update.
1 parent a08d978 commit 5b61e7a

32 files changed

+1150
-303
lines changed

.github/CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Contributing to GitCheck
2+
We welcome contributions to GitCheck! Here are some guidelines to follow:
3+
4+
## Submitting Issues
5+
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.
6+
7+
## Pull Requests
8+
We welcome pull requests!
9+
If you would like to make changes to the code, please fork the repository, create a new branch, and submit a pull request.
10+
Be sure to include a detailed description of the changes you have made, and include any relevant test cases.
11+
Make sure to follow the code style of the project. :)
12+
13+
## License
14+
By contributing to GitCheck, you agree that your contributions will be licensed under the [MIT License](../LICENSE).
15+
16+
Thank you for your interest in contributing to GitCheck! We look forward to reviewing your pull requests and issues.

.github/workflows/build.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Java CI and Test with Gradle
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
name: "Build with JDK${{ matrix.jdk }}"
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
jdk: [ 9, 11, 17 ]
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
20+
- name: Set up JDK ${{ matrix.jdk }}
21+
uses: actions/setup-java@v3
22+
with:
23+
java-version: ${{ matrix.jdk }}
24+
distribution: 'adopt'
25+
cache: gradle
26+
27+
- name: Grant execute permission for gradlew
28+
run: chmod +x ./gradlew
29+
30+
- name: Build with Gradle
31+
run: ./gradlew clean build
32+
33+
- name: Test with Gradle
34+
run: ./gradlew clean test

.github/workflows/buildAndPush.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish package to Maven Repository
2+
3+
on:
4+
release:
5+
types: [ published ]
6+
7+
jobs:
8+
publish:
9+
name: "Publish to Maven Repository"
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
15+
- name: Set up JDK 17
16+
uses: actions/setup-java@v3
17+
with:
18+
distribution: 'temurin'
19+
java-version: 17
20+
cache: 'gradle'
21+
22+
- name: Grant execute permission for gradlew
23+
run: chmod +x ./gradlew
24+
25+
- name: Publish with Gradle
26+
run: ./gradlew clean build publish
27+
env:
28+
ETERNALCODE_REPO_USERNAME: ${{ secrets.ETERNALCODE_REPO_USERNAME }}
29+
ETERNALCODE_REPO_PASSWORD: ${{ secrets.ETERNALCODE_REPO_PASSWORD }}

license.txt renamed to LICENSE

File renamed without changes.

README.md

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,80 @@
1-
# Updater
1+
# GitCheck
2+
GitCheck is a Java library that makes it easy to check for updates to a GitHub repository.
3+
It utilizes the GitHub API to retrieve information about the latest release and compares it to the current version of your application.
4+
With GitCheck, you can ensure that your users are always running the latest version of your software.
25

3-
#### 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.
6+
## Features
7+
- Simple and easy-to-use API
8+
- Lightweight and efficient
9+
- Supports Java 9 and above
10+
- Utilizes the GitHub API for retrieving release information
11+
- You can add your own implementation for another platform
412

5-
### Usage
6-
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.
13+
## Installation
714

8-
The `RemoteInformation` object contains information about the update, such as the availability of a new version, the current version, and the download URI.
15+
To use GitCheck in your project, if you are using Gradle, add the following to your `build.gradle` file:
916

10-
```java
11-
if (remoteInformation.isAvailableNewVersion()) {
12-
System.out.println("A new version is available: " + remoteInformation.getCurrentVersion());
13-
System.out.println("Download URI: " + remoteInformation.getDownloadUri());
14-
} else {
15-
System.out.println("You are already running the latest version.");
16-
}
17+
```kotlin
18+
maven { url = uri("https://repo.eternalcode.pl/releases") }
1719
```
1820

19-
### Example
20-
Here's an example of how to can use the Updater in `Spigot` plugin
21-
22-
```java
23-
24-
import com.eternalcode.updater.Updater;
25-
import com.eternalcode.updater.http.RemoteInformation;
26-
27-
public class MyPlugin {
21+
```kotlin
22+
implementation("com.eternalcode:gitcheck:1.0.0")
23+
```
2824

29-
private Updater updater;
25+
Or, if you are using Maven, add the following to your `pom.xml` file:
3026

31-
public void onEnable() {
32-
updater = new Updater("MyPlugin", "1.0", "MyGithubUsername/MyPlugin");
33-
checkForUpdates();
34-
}
27+
```xml
28+
<repository>
29+
<id>eternalcode-releases</id>
30+
<url>https://repo.eternalcode.pl/releases</url>
31+
</repository>
32+
```
3533

36-
private void checkForUpdates() {
37-
RemoteInformation remoteInformation = updater.checkUpdates();
38-
if (remoteInformation.isAvailableNewVersion()) {
39-
System.out.println("A new version is available: " + remoteInformation.getCurrentVersion());
40-
System.out.println("Download URI: " + remoteInformation.getDownloadUri());
41-
} else {
42-
System.out.println("You are already running the latest version.");
43-
}
44-
}
45-
}
34+
```xml
35+
<dependency>
36+
<groupId>com.eternalcode</groupId>
37+
<artifactId>gitcheck</artifactId>
38+
<version>1.0.0</version>
39+
</dependency>
4640
```
4741

48-
### Maven/Gradle
49-
Get the latest version from [EternalCode Repository](https://repo.eternalcode.pl/#/releases/com/eternalcode/updater)
42+
## API Usage
5043

51-
#### gradle groovy
52-
```groovy
53-
maven { url "https://repo.eternalcode.pl/releases" }
44+
To use GitCheck, you need to create an instance of the `GitCheck` class.
45+
Create `GitRepository` and `GitTag` objects to specify the repository and the current version of your application.
46+
Then, call the `checkRelease` method to check for updates.
5447

55-
implementation "com.eternalcode:updater:{VERSION}"
56-
```
48+
```java
49+
public class MyApplication {
5750

58-
```kotlin
59-
maven { url = uri("https://repo.eternalcode.pl/releases") }
51+
public static void main(String[] args) {
52+
GitCheck gitCheck = new GitCheck();
53+
GitRepository repository = GitRepository.of("Owner", "Project");
6054

61-
implementation("com.eternalcode:updater:{VERSION}")
62-
```
55+
GitCheckResult result = gitCheck.checkRelease(repository, GitTag.of("v1.0.0"));
6356

64-
```xml
65-
<repository>
66-
<id>eternalcode-reposilite-releases</id>
67-
<name>EternalCode Repository</name>
68-
<url>https://repo.eternalcode.pl/releases</url>
69-
</repository>
57+
if (!result.isUpToDate()) {
58+
GitRelease release = result.getLatestRelease();
59+
GitTag tag = release.getTag();
7060

71-
<dependency>
72-
<groupId>com.eternalcode</groupId>
73-
<artifactId>updater</artifactId>
74-
<version>{VERSION}</version>
75-
</dependency>
76-
```
61+
System.out.println("A new version is available: " + tag.getTag());
62+
System.out.println("See release page: " + release.getPageUrl());
63+
System.out.println("Release date: " + release.getPublishedAt());
64+
}
65+
66+
// ...
67+
}
7768

69+
}
70+
```
71+
In this example, `GitCheck` is used to check for updates to the repository `Owner/Project` with the current version `v1.0.0`.
72+
If a new version is available, the details of the release are printed to the console.
7873

74+
## Contributing
75+
We welcome contributions to GitCheck!
76+
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>
77+
See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more information.
7978

79+
## License
80+
GitCheck is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.

build.gradle.kts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
plugins {
22
`java-library`
33
`maven-publish`
4+
id("com.github.johnrengelman.shadow") version "7.1.2"
45
}
56

67
group = "com.eternalcode"
7-
version = System.getenv("E_VERSION")
8+
version = "1.0.0"
9+
val artifactId = "gitcheck"
810

911
java {
1012
withJavadocJar()
1113
withSourcesJar()
14+
15+
sourceCompatibility = JavaVersion.VERSION_1_9
16+
targetCompatibility = JavaVersion.VERSION_1_9
1217
}
1318

1419
repositories {
@@ -17,21 +22,23 @@ repositories {
1722

1823
dependencies {
1924
// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
20-
implementation("com.googlecode.json-simple:json-simple:1.1.1")
25+
api("com.googlecode.json-simple:json-simple:1.1.1") {
26+
exclude(group = "junit")
27+
}
2128

22-
// OkHTTP
23-
implementation("com.squareup.okhttp3:okhttp:4.10.0")
29+
api("org.jetbrains:annotations:23.1.0")
2430

25-
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
26-
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
31+
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
32+
testImplementation("nl.jqno.equalsverifier:equalsverifier:3.12.3")
33+
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
2734
}
2835

2936
publishing {
3037
publications {
3138
create<MavenPublication>("maven") {
32-
groupId = "com.eternalcode"
33-
artifactId = "updater"
34-
version = System.getenv("E_VERSION")
39+
groupId = "$group"
40+
artifactId = artifactId
41+
version = "${project.version}"
3542

3643
from(components["java"])
3744
}
@@ -40,9 +47,10 @@ publishing {
4047
maven {
4148
name = "eternalcode-repository"
4249
url = uri("https://repo.eternalcode.pl/releases")
50+
4351
credentials {
44-
username = System.getenv("E_REPO_USERNAME")
45-
password = System.getenv("E_REPO_PASS")
52+
username = System.getenv("ETERNALCODE_REPO_USERNAME")
53+
password = System.getenv("ETERNALCODE_REPO_PASSWORD")
4654
}
4755
}
4856
}

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = "eternalupdater"
1+
rootProject.name = "gitcheck"
22

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.eternalcode.gitcheck;
2+
3+
import com.eternalcode.gitcheck.git.GitRelease;
4+
import com.eternalcode.gitcheck.git.GitReleaseProvider;
5+
import com.eternalcode.gitcheck.git.GitRepository;
6+
import com.eternalcode.gitcheck.git.GitTag;
7+
import com.eternalcode.gitcheck.github.GitHubReleaseProvider;
8+
import com.eternalcode.gitcheck.shared.Preconditions;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
/**
12+
* Service for checking if the latest release is up to date.
13+
* <p>
14+
* This service uses {@link GitReleaseProvider} to get the latest release and compares it with the current tag.
15+
* The current tag is provided by {@link GitTag#of(String)}
16+
* <br>
17+
*/
18+
public class GitCheck {
19+
20+
private final GitReleaseProvider versionProvider;
21+
22+
/**
23+
* Creates a new instance of {@link GitCheck} with the default {@link GitHubReleaseProvider}.
24+
*/
25+
public GitCheck() {
26+
this(new GitHubReleaseProvider());
27+
}
28+
29+
/**
30+
* Creates a new instance of {@link GitCheck} with the given {@link GitReleaseProvider}.
31+
*
32+
* @param versionProvider the version provider
33+
*/
34+
public GitCheck(@NotNull GitReleaseProvider versionProvider) {
35+
Preconditions.notNull(versionProvider, "release provider");
36+
this.versionProvider = versionProvider;
37+
}
38+
39+
/**
40+
* Gets the latest release for the given repository.
41+
*
42+
* @param repository the repository
43+
* @return the latest release
44+
*/
45+
@NotNull
46+
public GitRelease getLatestRelease(@NotNull GitRepository repository) {
47+
Preconditions.notNull(repository, "repository");
48+
49+
return this.versionProvider.getLatestRelease(repository);
50+
}
51+
52+
/**
53+
* Creates a new instance of {@link GitCheckResult} for the given repository and tag.
54+
* Result contains the latest release and the current tag.
55+
* Use {@link GitCheckResult#isUpToDate()} to check if the latest release is up to date.
56+
*
57+
* @param repository the repository
58+
* @param currentTag the current tag
59+
* @return the result
60+
*/
61+
@NotNull
62+
public GitCheckResult checkRelease(@NotNull GitRepository repository, @NotNull GitTag currentTag) {
63+
Preconditions.notNull(repository, "repository");
64+
Preconditions.notNull(currentTag, "current tag");
65+
66+
GitRelease latestRelease = this.getLatestRelease(repository);
67+
return new GitCheckResult(latestRelease, currentTag);
68+
}
69+
70+
}

0 commit comments

Comments
 (0)