diff --git a/pom.xml b/pom.xml
index b9101d8..58f164a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
net.lecigne
deezer-datasync
- 0.4.3
+ 0.5.0-SNAPSHOT
17
diff --git a/src/main/java/net/lecigne/deezerdatasync/model/PlaylistInfo.java b/src/main/java/net/lecigne/deezerdatasync/model/PlaylistInfo.java
index c298345..a499424 100644
--- a/src/main/java/net/lecigne/deezerdatasync/model/PlaylistInfo.java
+++ b/src/main/java/net/lecigne/deezerdatasync/model/PlaylistInfo.java
@@ -1,6 +1,5 @@
package net.lecigne.deezerdatasync.model;
-import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.Duration;
import java.time.Instant;
import lombok.Getter;
diff --git a/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubBackup.java b/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubBackup.java
index bb0f1ac..406ceb2 100644
--- a/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubBackup.java
+++ b/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubBackup.java
@@ -1,10 +1,8 @@
package net.lecigne.deezerdatasync.repository.destinations.github;
import java.util.List;
-import java.util.stream.Stream;
import lombok.Builder;
import lombok.Getter;
-import net.lecigne.deezerdatasync.model.DeezerData;
@Getter
@Builder
diff --git a/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubSyncDestination.java b/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubSyncDestination.java
index ea3fb06..61e4215 100644
--- a/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubSyncDestination.java
+++ b/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubSyncDestination.java
@@ -31,12 +31,17 @@ public void save(DeezerData deezerData) {
String latestCommitSha = getLatestCommitSha(repo);
log.debug("Latest commit SHA: {}", latestCommitSha);
GHTree newTree = createNewTree(repo, deezerData, latestCommitSha);
+ if (isSameTree(newTree, repo.getCommit(latestCommitSha).getTree())) {
+ log.debug("No changes detected, skipping commit.");
+ return;
+ }
GHCommit commit = createCommit(repo, newTree, latestCommitSha);
log.debug("New Commit SHA: {}", commit.getSHA1());
updateBranch(repo, commit);
} catch (IOException e) {
- log.error("Error while saving to GitHub", e);
- throw new RuntimeException(e);
+ var err = "Error while saving to GitHub";
+ log.error(err, e);
+ throw new GitHubSyncException(err, e);
}
}
@@ -61,6 +66,10 @@ private GHTree createNewTree(GHRepository repo, DeezerData deezerData, String la
return treeBuilder.create();
}
+ private boolean isSameTree(GHTree newTree, GHTree oldTree) {
+ return newTree.getSha().equals(oldTree.getSha());
+ }
+
private GHCommit createCommit(GHRepository repo, GHTree newTree, String latestCommitSha) throws IOException {
String commitMessage = String.format("Backup %s", LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
return repo.createCommit()
diff --git a/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubSyncException.java b/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubSyncException.java
new file mode 100644
index 0000000..0b015d5
--- /dev/null
+++ b/src/main/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubSyncException.java
@@ -0,0 +1,7 @@
+package net.lecigne.deezerdatasync.repository.destinations.github;
+
+public class GitHubSyncException extends RuntimeException {
+ public GitHubSyncException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/main/java/net/lecigne/deezerdatasync/utils/Extensions.java b/src/main/java/net/lecigne/deezerdatasync/utils/Extensions.java
index 6e3f8d9..92c4bf6 100644
--- a/src/main/java/net/lecigne/deezerdatasync/utils/Extensions.java
+++ b/src/main/java/net/lecigne/deezerdatasync/utils/Extensions.java
@@ -2,7 +2,10 @@
import java.util.List;
-public class Extensions {
+public final class Extensions {
+
+ private Extensions() {
+ }
public static List ifEmpty(List sourceList, List otherList) {
return sourceList == null || sourceList.isEmpty() ? otherList : sourceList;
diff --git a/src/test/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubMapperPropertyTest.java b/src/test/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubMapperPropertyTest.java
index b7dae6e..fbce42c 100644
--- a/src/test/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubMapperPropertyTest.java
+++ b/src/test/java/net/lecigne/deezerdatasync/repository/destinations/github/GitHubMapperPropertyTest.java
@@ -10,7 +10,6 @@
import net.jqwik.api.constraints.StringLength;
import net.lecigne.deezerdatasync.model.DeezerData;
import net.lecigne.deezerdatasync.model.Playlist;
-import org.junit.jupiter.api.DisplayName;
@Label("The GitHub mapper")
public class GitHubMapperPropertyTest {