Skip to content

Commit

Permalink
Populating RemoteRefUpdate.Status if it is not equal OK or UP_TO_DATE…
Browse files Browse the repository at this point in the history
…, to ScmPushResult and including this status in logger.error (#684) (#685)

Co-authored-by: Michał Jankowski <[email protected]>
  • Loading branch information
VicenteJankowski and Michał Jankowski authored Nov 30, 2023
1 parent d60d084 commit 9eee1c8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
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<RemoteRefUpdate.Status> failureCause;

private final Optional<String> remoteMessage;

public ScmPushResult(boolean success, Optional<String> remoteMessage) {
public ScmPushResult(boolean success, Optional<RemoteRefUpdate.Status> failureCause, Optional<String> remoteMessage) {
this.success = success;
this.failureCause = failureCause;
this.remoteMessage = remoteMessage;
}

public boolean isSuccess() {
return success;
}

public Optional<RemoteRefUpdate.Status> getFailureStatus() {
return failureCause;
}

public Optional<String> getRemoteMessage() {
return remoteMessage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,16 @@ private ScmPushResult verifyPushResults(Iterable<PushResult> pushResults) {

Optional<RemoteRefUpdate> 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<RemoteRefUpdate.Status> failureCause = isSuccess ?
Optional.empty() : Optional.of(failedRefUpdate.get().getStatus());

return new ScmPushResult(
!failedRefUpdate.isPresent(),
isSuccess,
failureCause,
Optional.ofNullable(pushResult.getMessages())
);
}
Expand Down Expand Up @@ -271,7 +276,7 @@ public ScmPosition positionOfLastChangeIn(String path, List<String> 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));
}
}
Expand Down Expand Up @@ -536,9 +541,9 @@ public Status listChanges() {
public boolean isLegacyDefTagnameRepo() {
try {
List<Ref> 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);
}
Expand All @@ -554,7 +559,8 @@ public List<String> lastLogMessages(int messageCount) {
throw new ScmException(e);
}
}
public Git getJgitRepository(){

public Git getJgitRepository() {
return jgitRepository;
}
}

0 comments on commit 9eee1c8

Please sign in to comment.