大声道撒旦
This commit is contained in:
parent
b49c21942a
commit
25ec1b4a5e
@ -33,4 +33,6 @@ public interface IRepositoryBranchRepository extends IBaseRepository<RepositoryB
|
|||||||
* @return 分支数量
|
* @return 分支数量
|
||||||
*/
|
*/
|
||||||
Long countByProjectId(Long projectId);
|
Long countByProjectId(Long projectId);
|
||||||
|
|
||||||
|
List<RepositoryBranch> findByExternalSystemIdAndProjectIdAndDeletedFalse(Long externalSystemId, Long id);
|
||||||
}
|
}
|
||||||
@ -30,4 +30,6 @@ public interface IRepositoryProjectRepository extends IBaseRepository<Repository
|
|||||||
List<RepositoryProject> findByExternalSystemId(Long externalSystemId);
|
List<RepositoryProject> findByExternalSystemId(Long externalSystemId);
|
||||||
|
|
||||||
void deleteByExternalSystemId(Long externalSystemId);
|
void deleteByExternalSystemId(Long externalSystemId);
|
||||||
|
|
||||||
|
List<RepositoryProject> findByExternalSystemIdAndDeletedFalse(Long externalSystemId);
|
||||||
}
|
}
|
||||||
@ -47,43 +47,58 @@ public class RepositoryBranchServiceImpl extends BaseServiceImpl<RepositoryBranc
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer syncBranches(Long externalSystemId) {
|
public Integer syncBranches(Long externalSystemId) {
|
||||||
// try {
|
try {
|
||||||
// // 1. 获取外部系统信息
|
// 1. 获取外部系统信息
|
||||||
// ExternalSystem externalSystem = externalSystemRepository.findById(externalSystemId)
|
ExternalSystem externalSystem = externalSystemRepository.findById(externalSystemId)
|
||||||
// .orElseThrow(() -> new BusinessException(ResponseCode.EXTERNAL_SYSTEM_NOT_FOUND));
|
.orElseThrow(() -> new BusinessException(ResponseCode.EXTERNAL_SYSTEM_NOT_FOUND));
|
||||||
//
|
|
||||||
// // 2. 获取项目信息
|
// 2. 获取所有项目
|
||||||
// RepositoryProject project = repositoryProjectRepository.findById(projectId)
|
List<RepositoryProject> projects = repositoryProjectRepository.findByExternalSystemIdAndDeletedFalse(externalSystemId);
|
||||||
// .orElseThrow(() -> new BusinessException(ResponseCode.REPOSITORY_PROJECT_NOT_FOUND));
|
if (projects.isEmpty()) {
|
||||||
//
|
log.info("No projects found for external system: {}", externalSystem.getName());
|
||||||
// // 3. 获取远程仓库分支信息
|
return 0;
|
||||||
// List<GitBranchResponse> remoteBranches = gitServiceIntegration.branches(externalSystem, project.getProjectId());
|
}
|
||||||
// if (remoteBranches.isEmpty()) {
|
|
||||||
// log.info("No branches found in remote git system: {}, project: {}", externalSystem.getName(), project.getName());
|
int totalSyncedBranches = 0;
|
||||||
// return 0;
|
// 3. 同步每个项目的分支
|
||||||
// }
|
for (RepositoryProject project : projects) {
|
||||||
//
|
try {
|
||||||
// // 4. 获取本地已存在的仓库分支
|
// 3.1 获取远程分支信息
|
||||||
// List<RepositoryBranch> existingBranches = repositoryBranchRepository.findByExternalSystemIdAndProjectId(externalSystemId, projectId);
|
List<GitBranchResponse> remoteBranches = gitServiceIntegration.branches(externalSystem, project.getProjectId());
|
||||||
// Map<String, RepositoryBranch> existingBranchMap = existingBranches.stream()
|
if (remoteBranches.isEmpty()) {
|
||||||
// .collect(Collectors.toMap(RepositoryBranch::getName, Function.identity()));
|
log.info("No branches found for project: {}", project.getName());
|
||||||
//
|
continue;
|
||||||
// // 5. 更新或创建仓库分支
|
}
|
||||||
// List<RepositoryBranch> branchesToSave = remoteBranches.stream()
|
|
||||||
// .map(remoteBranch -> updateOrCreateBranch(externalSystemId, projectId, remoteBranch, existingBranchMap))
|
// 3.2 获取本地已存在的分支
|
||||||
// .collect(Collectors.toList());
|
List<RepositoryBranch> existingBranches = repositoryBranchRepository.findByExternalSystemIdAndProjectIdAndDeletedFalse(
|
||||||
//
|
externalSystemId, project.getId());
|
||||||
// // 6. 保存仓库分支
|
Map<String, RepositoryBranch> existingBranchMap = existingBranches.stream()
|
||||||
// repositoryBranchRepository.saveAll(branchesToSave);
|
.collect(Collectors.toMap(RepositoryBranch::getName, Function.identity()));
|
||||||
//
|
|
||||||
// log.info("Successfully synchronized {} branches for external system: {}, project: {}",
|
// 3.3 更新或创建分支
|
||||||
// branchesToSave.size(), externalSystem.getName(), project.getName());
|
List<RepositoryBranch> branchesToSave = remoteBranches.stream()
|
||||||
// return branchesToSave.size();
|
.map(remoteBranch -> updateOrCreateBranch(externalSystemId, project.getId(), remoteBranch, existingBranchMap))
|
||||||
// } catch (Exception e) {
|
.collect(Collectors.toList());
|
||||||
// log.error("Failed to sync repository branches for external system: {}, project: {}", externalSystemId, projectId, e);
|
|
||||||
// throw new BusinessException(ResponseCode.REPOSITORY_SYNC_FAILED);
|
// 3.4 保存分支
|
||||||
// }
|
repositoryBranchRepository.saveAll(branchesToSave);
|
||||||
return null;
|
totalSyncedBranches += branchesToSave.size();
|
||||||
|
|
||||||
|
log.info("Successfully synchronized {} branches for project: {}",
|
||||||
|
branchesToSave.size(), project.getName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to sync branches for project: {}", project.getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Successfully synchronized total {} branches for external system: {}",
|
||||||
|
totalSyncedBranches, externalSystem.getName());
|
||||||
|
return totalSyncedBranches;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to sync branches for external system: {}", externalSystemId, e);
|
||||||
|
throw new BusinessException(ResponseCode.REPOSITORY_BRANCH_SYNC_FAILED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RepositoryBranch updateOrCreateBranch(
|
private RepositoryBranch updateOrCreateBranch(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user