|
|
|
@ -15,6 +15,7 @@ import org.eclipse.jgit.treewalk.TreeWalk;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -29,6 +30,7 @@ import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
|
|
|
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
|
|
|
|
import ru.ulstu.extractor.heuristic.model.ResourceUnit;
|
|
|
|
|
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
|
|
|
|
import ru.ulstu.extractor.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
@ -55,7 +57,11 @@ import static org.apache.logging.log4j.util.Strings.isBlank;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class GitRepositoryService {
|
|
|
|
|
private final static Logger LOG = LoggerFactory.getLogger(GitRepositoryService.class);
|
|
|
|
|
private final Map<String, Class<? extends GitApi>> gitApiServiceHolder = Map.of(
|
|
|
|
|
"git.athene.tech", GitAtheneApi.class,
|
|
|
|
|
"github.com", GithubApi.class,
|
|
|
|
|
"gitlab.com", GitlabApi.class);
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GitRepositoryService.class);
|
|
|
|
|
private static final String BRANCH_PREFIX = "refs/remotes/origin/";
|
|
|
|
|
@Value("${extractor.custom-projects-dir}")
|
|
|
|
|
private String customProjectsDir;
|
|
|
|
@ -63,11 +69,14 @@ public class GitRepositoryService {
|
|
|
|
|
private final ExecutorService executorServiceCommits = Executors.newFixedThreadPool(8);
|
|
|
|
|
private final StructuralUnitService structuralUnitService;
|
|
|
|
|
private final GitRepositoryRepository gitRepositoryRepository;
|
|
|
|
|
private final ApplicationContext applicationContext;
|
|
|
|
|
|
|
|
|
|
public GitRepositoryService(StructuralUnitService structuralUnitService,
|
|
|
|
|
GitRepositoryRepository gitRepositoryRepository) {
|
|
|
|
|
GitRepositoryRepository gitRepositoryRepository,
|
|
|
|
|
ApplicationContext applicationContext) {
|
|
|
|
|
this.structuralUnitService = structuralUnitService;
|
|
|
|
|
this.gitRepositoryRepository = gitRepositoryRepository;
|
|
|
|
|
this.applicationContext = applicationContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Branch> getRemoteBranches(String url) throws GitAPIException, IOException {
|
|
|
|
@ -430,8 +439,18 @@ public class GitRepositoryService {
|
|
|
|
|
|
|
|
|
|
public GitRepository findByUrlOrCreate(String gitRepositoryUrl) {
|
|
|
|
|
GitRepository gitRepository = gitRepositoryRepository.findByUrl(gitRepositoryUrl);
|
|
|
|
|
|
|
|
|
|
return gitRepository == null
|
|
|
|
|
? gitRepositoryRepository.save(new GitRepository(gitRepositoryUrl))
|
|
|
|
|
? gitRepositoryRepository.save(new GitRepository(gitRepositoryUrl,
|
|
|
|
|
applicationContext.getBean(getGitApiServiceClass(gitRepositoryUrl)).getRepositoryId(gitRepositoryUrl)))
|
|
|
|
|
: gitRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Class<? extends GitApi> getGitApiServiceClass(Branch branch) {
|
|
|
|
|
return getGitApiServiceClass(branch.getGitRepository().getUrl());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Class<? extends GitApi> getGitApiServiceClass(String url) {
|
|
|
|
|
return gitApiServiceHolder.get(StringUtils.getServerDomain(url));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|