Skip to content
Merged
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
24 changes: 23 additions & 1 deletion src/main/java/io/kestra/plugin/git/AbstractPushTask.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.kestra.plugin.git;

import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.exceptions.KestraRuntimeException;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.RunnableTask;
import io.kestra.core.runners.RunContext;
Expand All @@ -26,6 +27,8 @@
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.slf4j.Logger;

Expand All @@ -41,11 +44,19 @@

import static io.kestra.core.utils.Rethrow.*;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static org.eclipse.jgit.transport.RemoteRefUpdate.Status.*;

@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@Getter
public abstract class AbstractPushTask<O extends AbstractPushTask.Output> extends AbstractCloningTask implements RunnableTask<O> {
private static List<RemoteRefUpdate.Status> REJECTION_STATUS = Arrays.asList(
REJECTED_NONFASTFORWARD,
REJECTED_NODELETE,
REJECTED_REMOTE_CHANGED,
REJECTED_OTHER_REASON
);

protected Property<String> commitMessage;

@Schema(
Expand Down Expand Up @@ -227,7 +238,18 @@ private Output push(Git git, RunContext runContext, GitService gitService) throw
if (head == null) {
git.branchRename().setNewName(renderedBranch).call();
}
authentified(git.push(), runContext).call();
Iterable<PushResult> pushResults = authentified(git.push(), runContext).call();

for (PushResult pushResult : pushResults) {
Optional<RemoteRefUpdate.Status> pushStatus = pushResult.getRemoteUpdates().stream()
.map(RemoteRefUpdate::getStatus)
.filter(status -> REJECTION_STATUS.contains(status))
.findFirst();

if (pushStatus.isPresent()) {
throw new KestraRuntimeException(pushResult.getMessages());
}
}

commitId = commit.getName();
commitURL = buildCommitUrl(httpUrl, renderedBranch, commitId);
Expand Down