All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.build.axion.release.domain.scm.ScmService Maven / Gradle / Ivy

The newest version!
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;

import java.util.List;
import java.util.Optional;
import java.util.Set;

public class ScmService {
    private static final Logger logger = Logging.getLogger(ScmService.class);

    private final LocalOnlyResolver localOnlyResolver;
    private final ScmProperties scmProperties;
    private ScmRepository repository;

    public ScmService(LocalOnlyResolver localOnlyResolver, ScmProperties scmProperties, ScmRepository repository) {
        this.localOnlyResolver = localOnlyResolver;
        this.scmProperties = scmProperties;
        this.repository = repository;
    }

    public void tag(String tagName) {
        repository.tag(tagName);
    }

    public void dropTag(String tagName) {
        try {
            repository.dropTag(tagName);
        } catch (ScmException e) {
            logger.quiet("Exception occurred during removing the tag: " + e.getMessage());
            throw e;
        }
    }

    public ScmPushResult push() {
        if (localOnlyResolver.localOnly(this.remoteAttached())) {
            logger.quiet("Changes made to local repository only");
            return new ScmPushResult(ScmPushResultOutcome.SUCCESS, Optional.of(RemoteRefUpdate.Status.NOT_ATTEMPTED), Optional.empty());
        }

        try {
            logger.quiet("Pushing all to remote: " + scmProperties.getRemote());
            return repository.push(scmProperties.getIdentity(), scmProperties.pushOptions());
        } catch (ScmException e) {
            logger.quiet("Exception occurred during push: " + e.getMessage());
            throw e;
        }

    }

    public ScmPosition position() {
        return repository.currentPosition();
    }

    public void commit(List patterns, String message) {
        repository.commit(patterns, message);
    }

    public boolean remoteAttached() {
        return repository.remoteAttached(scmProperties.getRemote());
    }

    public List lastLogMessages(int messageCount) {
        return repository.lastLogMessages(messageCount);
    }

    public boolean isLegacyDefTagnameRepo() {
        return repository.isLegacyDefTagnameRepo();
    }

    public Set getReleaseBranchNames() {
        return scmProperties.getReleaseBranchNames();
    }

    public boolean isReleaseOnlyOnReleaseBranches(){
        return scmProperties.isReleaseOnlyOnReleaseBranches();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy