From 9eee1c85dbc7b5ba051bf346394a4ce5132afe41 Mon Sep 17 00:00:00 2001 From: VicenteJankowski <116435856+VicenteJankowski@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:38:41 +0100 Subject: [PATCH] Populating RemoteRefUpdate.Status if it is not equal OK or UP_TO_DATE, to ScmPushResult and including this status in logger.error (#684) (#685) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MichaƂ Jankowski --- .../build/axion/release/ReleaseTask.groovy | 4 +++- .../infrastructure/DummyRepository.groovy | 2 +- .../infrastructure/NoOpRepository.groovy | 2 +- .../release/domain/scm/ScmPushResult.java | 12 +++++++++++- .../axion/release/domain/scm/ScmService.java | 3 ++- .../infrastructure/git/GitRepository.java | 18 ++++++++++++------ 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy index 5a4158ff..b00f20d4 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy @@ -14,9 +14,11 @@ abstract class ReleaseTask extends BaseAxionTask { ScmPushResult result = releaser.releaseAndPush(context.rules()) if(!result.success) { + def status = result.failureStatus.orElse("Unknown status of push") def message = result.remoteMessage.orElse("Unknown error during push") + logger.error("remote status: ${status}") logger.error("remote message: ${message}") - throw new ReleaseFailedException(message) + throw new ReleaseFailedException("Status: ${status}\nMessage: ${message}") } } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DummyRepository.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DummyRepository.groovy index a2255330..adea2592 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DummyRepository.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/DummyRepository.groovy @@ -40,7 +40,7 @@ class DummyRepository implements ScmRepository { @Override ScmPushResult push(ScmIdentity identity, ScmPushOptions pushOptions) { log('push') - return new ScmPushResult(true, Optional.empty()) + return new ScmPushResult(true, Optional.empty(), Optional.empty()) } @Override diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/NoOpRepository.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/NoOpRepository.groovy index 410d6b80..74f713e6 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/NoOpRepository.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/infrastructure/NoOpRepository.groovy @@ -35,7 +35,7 @@ class NoOpRepository implements ScmRepository { @Override ScmPushResult push(ScmIdentity identity, ScmPushOptions pushOptions) { log("pushing to remote: ${pushOptions.remote}") - return new ScmPushResult(true, Optional.empty()) + return new ScmPushResult(true, Optional.empty(), Optional.empty()) } @Override diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmPushResult.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmPushResult.java index 2017bd50..a6d490d9 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmPushResult.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmPushResult.java @@ -1,14 +1,20 @@ package pl.allegro.tech.build.axion.release.domain.scm; +import org.eclipse.jgit.transport.RemoteRefUpdate; + import java.util.Optional; public class ScmPushResult { private final boolean success; + + private final Optional failureCause; + private final Optional remoteMessage; - public ScmPushResult(boolean success, Optional remoteMessage) { + public ScmPushResult(boolean success, Optional failureCause, Optional remoteMessage) { this.success = success; + this.failureCause = failureCause; this.remoteMessage = remoteMessage; } @@ -16,6 +22,10 @@ public boolean isSuccess() { return success; } + public Optional getFailureStatus() { + return failureCause; + } + public Optional getRemoteMessage() { return remoteMessage; } diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java index 497d0db5..9669af09 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/scm/ScmService.java @@ -1,5 +1,6 @@ package pl.allegro.tech.build.axion.release.domain.scm; +import org.eclipse.jgit.transport.RemoteRefUpdate; import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; import pl.allegro.tech.build.axion.release.domain.LocalOnlyResolver; @@ -36,7 +37,7 @@ public void dropTag(String tagName) { public ScmPushResult push() { if (localOnlyResolver.localOnly(this.remoteAttached())) { logger.quiet("Changes made to local repository only"); - return new ScmPushResult(true, Optional.empty()); + return new ScmPushResult(true, Optional.of(RemoteRefUpdate.Status.NOT_ATTEMPTED), Optional.empty()); } try { diff --git a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.java b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.java index a1c7778d..3d2d3452 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/infrastructure/git/GitRepository.java @@ -194,11 +194,16 @@ private ScmPushResult verifyPushResults(Iterable pushResults) { Optional failedRefUpdate = pushResult.getRemoteUpdates().stream().filter(ref -> !ref.getStatus().equals(RemoteRefUpdate.Status.OK) - && !ref.getStatus().equals(RemoteRefUpdate.Status.UP_TO_DATE) + && !ref.getStatus().equals(RemoteRefUpdate.Status.UP_TO_DATE) ).findFirst(); + boolean isSuccess = !failedRefUpdate.isPresent(); + Optional failureCause = isSuccess ? + Optional.empty() : Optional.of(failedRefUpdate.get().getStatus()); + return new ScmPushResult( - !failedRefUpdate.isPresent(), + isSuccess, + failureCause, Optional.ofNullable(pushResult.getMessages()) ); } @@ -271,7 +276,7 @@ public ScmPosition positionOfLastChangeIn(String path, List excludeSubFo String unixStylePath = asUnixPath(path); assertPathExists(unixStylePath); logCommand = jgitRepository.log().setMaxCount(1).addPath(unixStylePath); - for (String dep: dependenciesFolders) { + for (String dep : dependenciesFolders) { logCommand.addPath(asUnixPath(dep)); } } @@ -536,9 +541,9 @@ public Status listChanges() { public boolean isLegacyDefTagnameRepo() { try { List call = jgitRepository.tagList().call(); - if(call.isEmpty()) return false; + if (call.isEmpty()) return false; - return call.stream().allMatch(ref-> ref.getName().startsWith("refs/tags/"+fullLegacyPrefix())); + return call.stream().allMatch(ref -> ref.getName().startsWith("refs/tags/" + fullLegacyPrefix())); } catch (GitAPIException e) { throw new ScmException(e); } @@ -554,7 +559,8 @@ public List lastLogMessages(int messageCount) { throw new ScmException(e); } } - public Git getJgitRepository(){ + + public Git getJgitRepository() { return jgitRepository; } }