промежуточный коммит
This commit is contained in:
parent
830ea4d9fa
commit
23201db5ce
|
|
@ -1,10 +1,14 @@
|
|||
package ru.kirillius.pf.sdn;
|
||||
|
||||
import ru.kirillius.pf.sdn.External.API.GitSubscription;
|
||||
import ru.kirillius.pf.sdn.core.Networking.NetworkResourceBundle;
|
||||
import ru.kirillius.pf.sdn.core.Subscription.RepositoryConfig;
|
||||
import ru.kirillius.utils.logging.SystemLogger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class App extends AppContext {
|
||||
|
|
@ -12,6 +16,9 @@ public class App extends AppContext {
|
|||
|
||||
public App(File configFile) {
|
||||
super(configFile);
|
||||
GitSubscription subscription = new GitSubscription(this);
|
||||
RepositoryConfig repositoryConfig = new RepositoryConfig("test", GitSubscription.class, "https://git.kirillius.ru/kirillius/docker-decompose.git");
|
||||
Map<String, NetworkResourceBundle> resources = subscription.getResources(repositoryConfig);
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import ru.kirillius.utils.logging.SystemLogger;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class GitSubscription implements SubscriptionProvider {
|
||||
private final Context context;
|
||||
|
|
@ -32,12 +33,14 @@ public class GitSubscription implements SubscriptionProvider {
|
|||
}
|
||||
}
|
||||
|
||||
var repository = isGitRepository(repoDir) ? openRepository(repoDir) : cloneRepository(config.getSource(), repoDir);
|
||||
var existing = isGitRepository(repoDir);
|
||||
var repository = existing ? openRepository(repoDir) : cloneRepository(config.getSource(), repoDir);
|
||||
if (existing) {
|
||||
SystemLogger.message("Fetching git repository " + config.getName() + " (" + config.getSource() + ")", CTX);
|
||||
checkAndPullUpdates(repository);
|
||||
}
|
||||
|
||||
|
||||
SystemLogger.message("Fetching git repository " + config.getName(), CTX);
|
||||
checkAndPullUpdates(repository);
|
||||
|
||||
repository.close();
|
||||
return Map.of();
|
||||
} catch (Exception e) {
|
||||
|
|
@ -49,41 +52,30 @@ public class GitSubscription implements SubscriptionProvider {
|
|||
private static void checkAndPullUpdates(Git git) throws GitAPIException {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var fetchResult = git.fetch()
|
||||
.setCheckFetchedObjects(true)
|
||||
.call();
|
||||
|
||||
if (fetchResult.getTrackingRefUpdates() != null && !fetchResult.getTrackingRefUpdates().isEmpty()) {
|
||||
|
||||
|
||||
|
||||
SystemLogger.message("Downloading updates...", CTX);
|
||||
|
||||
// Выполняем pull чтобы получить изменения
|
||||
var pullResult = git.pull().call();
|
||||
|
||||
if (pullResult.isSuccessful()) {
|
||||
System.out.println("✅ Обновление успешно завершено!");
|
||||
SystemLogger.message("Git pull is successful", CTX);
|
||||
|
||||
// Проверяем были ли обновлены файлы
|
||||
if (pullResult.getFetchResult() != null &&
|
||||
!pullResult.getFetchResult().getTrackingRefUpdates().isEmpty()) {
|
||||
|
||||
System.out.println("📁 Были обновлены файлы:");
|
||||
pullResult.getFetchResult().getTrackingRefUpdates().forEach(refUpdate -> {
|
||||
System.out.println(" - " + refUpdate.getLocalName() +
|
||||
" : " + refUpdate.getOldObjectId().abbreviate(7).name() +
|
||||
" -> " + refUpdate.getNewObjectId().abbreviate(7).name());
|
||||
});
|
||||
if (pullResult.getFetchResult() != null && !pullResult.getFetchResult().getTrackingRefUpdates().isEmpty()) {
|
||||
var updatedFiles = new StringJoiner("\n");
|
||||
pullResult.getFetchResult().getTrackingRefUpdates().forEach(refUpdate -> updatedFiles.add(" - " + refUpdate.getLocalName() +
|
||||
" : " + refUpdate.getOldObjectId().abbreviate(7).name() +
|
||||
" -> " + refUpdate.getNewObjectId().abbreviate(7).name()));
|
||||
SystemLogger.message("Updated files: " + updatedFiles, CTX);
|
||||
}
|
||||
} else {
|
||||
System.out.println("❌ Ошибка при обновлении репозитория");
|
||||
SystemLogger.error("Download failed", CTX);
|
||||
}
|
||||
} else {
|
||||
System.out.println("✅ Репозиторий уже актуален, обновлений нет");
|
||||
SystemLogger.message("There is no updates", CTX);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package ru.kirillius.pf.sdn.core.Subscription;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
|
@ -7,6 +8,7 @@ import ru.kirillius.json.JSONProperty;
|
|||
import ru.kirillius.json.JSONSerializable;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JSONSerializable
|
||||
public class RepositoryConfig {
|
||||
@Setter
|
||||
|
|
|
|||
Loading…
Reference in New Issue