Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #684 Populating RemoteRefUpdate.Status #685

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}