<commit_before>package net.nemerosa.ontrack.extension.git;

import net.nemerosa.ontrack.extension.git.model.BasicGitConfiguration;
import net.nemerosa.ontrack.extension.support.ConfigurationHealthIndicator;
import net.nemerosa.ontrack.extension.support.ConfigurationService;
import net.nemerosa.ontrack.git.GitRepositoryClient;
import net.nemerosa.ontrack.git.GitRepositoryClientFactory;
import net.nemerosa.ontrack.model.security.SecurityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.stereotype.Component;

@Component
public class GitHealthIndicator extends ConfigurationHealthIndicator<BasicGitConfiguration> {

    private static final Logger logger = LoggerFactory.getLogger(GitHealthIndicator.class);

    private final GitRepositoryClientFactory repositoryClientFactory;

    @Autowired
    public GitHealthIndicator(ConfigurationService<BasicGitConfiguration> configurationService, SecurityService securityService, HealthAggregator healthAggregator, GitRepositoryClientFactory repositoryClientFactory) {
        super(configurationService, securityService, healthAggregator);
        this.repositoryClientFactory = repositoryClientFactory;
    }

    @Override
    protected Health getHealth(BasicGitConfiguration config) {
        try {
            GitRepositoryClient client = repositoryClientFactory.getClient(config.getGitRepository());
            // TODO Sync and then...
            client.sync(logger::debug);
            return Health.up().build();
        } catch (Exception ex) {
            return Health.down(ex).build();
        }
    }

}<commit_msg>#377 Git project sync - replacing sync by access to remote branches for the health computation<commit_after>package net.nemerosa.ontrack.extension.git;

import net.nemerosa.ontrack.extension.git.model.BasicGitConfiguration;
import net.nemerosa.ontrack.extension.support.ConfigurationHealthIndicator;
import net.nemerosa.ontrack.extension.support.ConfigurationService;
import net.nemerosa.ontrack.git.GitRepositoryClient;
import net.nemerosa.ontrack.git.GitRepositoryClientFactory;
import net.nemerosa.ontrack.model.security.SecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthAggregator;
import org.springframework.stereotype.Component;

@Component
public class GitHealthIndicator extends ConfigurationHealthIndicator<BasicGitConfiguration> {

    private final GitRepositoryClientFactory repositoryClientFactory;

    @Autowired
    public GitHealthIndicator(ConfigurationService<BasicGitConfiguration> configurationService, SecurityService securityService, HealthAggregator healthAggregator, GitRepositoryClientFactory repositoryClientFactory) {
        super(configurationService, securityService, healthAggregator);
        this.repositoryClientFactory = repositoryClientFactory;
    }

    @Override
    protected Health getHealth(BasicGitConfiguration config) {
        try {
            GitRepositoryClient client = repositoryClientFactory.getClient(config.getGitRepository());
            client.getRemoteBranches();
            return Health.up().build();
        } catch (Exception ex) {
            return Health.down(ex).build();
        }
    }

}
{'fraction_non_alphanumeric': 0.07804459691252144, 'fraction_numerical': 0.001429388221841052, 'mean_word_length': 5.106457242582897, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '684834', 'n_tokens_mistral': 860, 'n_tokens_neox': 859, 'n_words': 156}