大声道撒旦
This commit is contained in:
parent
68fe2fedef
commit
39e40969b6
@ -21,7 +21,7 @@ import java.util.List;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/repo-group")
|
||||
@RequestMapping("/api/v1/repository-group")
|
||||
@Tag(name = "Git仓库组管理", description = "Git仓库组管理相关接口")
|
||||
public class RepositoryGroupApiController extends BaseController<RepositoryGroup, RepositoryGroupDTO, Long, RepositoryGroupQuery> {
|
||||
|
||||
|
||||
@ -15,9 +15,9 @@ import org.springframework.web.bind.annotation.*;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/git-manager")
|
||||
@RequestMapping("/api/v1/repository-manager")
|
||||
@Tag(name = "Git仓库管理", description = "Git仓库管理相关接口")
|
||||
public class GitManagerApiController {
|
||||
public class RepositoryManagerApiController {
|
||||
|
||||
@Resource
|
||||
private IGitManagerService gitManagerService;
|
||||
@ -1,5 +1,6 @@
|
||||
package com.qqchen.deploy.backend.deploy.integration.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@ -18,9 +19,54 @@ public class GitGroupResponse {
|
||||
|
||||
private String visibility;
|
||||
|
||||
@JsonProperty("parent_id")
|
||||
private Long parentId;
|
||||
|
||||
@JsonProperty("web_url")
|
||||
private String webUrl;
|
||||
|
||||
@JsonProperty("avatar_url")
|
||||
private String avatarUrl;
|
||||
|
||||
@JsonProperty("full_name")
|
||||
private String fullName;
|
||||
|
||||
@JsonProperty("full_path")
|
||||
private String fullPath;
|
||||
|
||||
@JsonProperty("project_creation_level")
|
||||
private String projectCreationLevel;
|
||||
|
||||
@JsonProperty("subgroup_creation_level")
|
||||
private String subgroupCreationLevel;
|
||||
|
||||
@JsonProperty("request_access_enabled")
|
||||
private Boolean requestAccessEnabled;
|
||||
|
||||
@JsonProperty("share_with_group_lock")
|
||||
private Boolean shareWithGroupLock;
|
||||
|
||||
@JsonProperty("require_two_factor_authentication")
|
||||
private Boolean requireTwoFactorAuthentication;
|
||||
|
||||
@JsonProperty("two_factor_grace_period")
|
||||
private Integer twoFactorGracePeriod;
|
||||
|
||||
@JsonProperty("auto_devops_enabled")
|
||||
private Boolean autoDevopsEnabled;
|
||||
|
||||
@JsonProperty("emails_disabled")
|
||||
private Boolean emailsDisabled;
|
||||
|
||||
@JsonProperty("mentions_disabled")
|
||||
private Boolean mentionsDisabled;
|
||||
|
||||
@JsonProperty("lfs_enabled")
|
||||
private Boolean lfsEnabled;
|
||||
|
||||
@JsonProperty("default_branch_protection")
|
||||
private Integer defaultBranchProtection;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
private String createdAt;
|
||||
}
|
||||
@ -36,4 +36,11 @@ public interface IRepositoryGroupRepository extends IBaseRepository<RepositoryGr
|
||||
* @return 仓库组
|
||||
*/
|
||||
RepositoryGroup findByExternalSystemIdAndGroupId(Long externalSystemId, Long groupId);
|
||||
|
||||
/**
|
||||
* 根据外部系统ID删除所有仓库组
|
||||
*
|
||||
* @param externalSystemId 外部系统ID
|
||||
*/
|
||||
void deleteByExternalSystemId(Long externalSystemId);
|
||||
}
|
||||
@ -22,6 +22,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Git仓库组服务实现
|
||||
@ -45,59 +47,49 @@ public class RepositoryGroupServiceImpl extends BaseServiceImpl<RepositoryGroup,
|
||||
@Override
|
||||
@Transactional
|
||||
public Integer syncGroups(Long externalSystemId) {
|
||||
try {
|
||||
// 1. 获取外部系统信息
|
||||
ExternalSystem externalSystem = externalSystemRepository.findById(externalSystemId)
|
||||
.orElseThrow(() -> new BusinessException(ResponseCode.EXTERNAL_SYSTEM_NOT_FOUND));
|
||||
|
||||
// 2. 获取远程仓库组信息
|
||||
// 2. 从Git API获取所有仓库组信息
|
||||
List<GitGroupResponse> remoteGroups = gitServiceIntegration.groups(externalSystem);
|
||||
if (remoteGroups.isEmpty()) {
|
||||
log.info("No groups found in remote git system: {}", externalSystem.getName());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 3. 获取本地已存在的仓库组
|
||||
List<RepositoryGroup> existingGroups = repositoryGroupRepository.findByExternalSystemId(externalSystemId);
|
||||
Map<Long, RepositoryGroup> existingGroupMap = existingGroups.stream()
|
||||
.collect(Collectors.toMap(RepositoryGroup::getGroupId, Function.identity()));
|
||||
try {
|
||||
// 3. 清空当前系统中该外部系统的所有仓库组
|
||||
repositoryGroupRepository.deleteByExternalSystemId(externalSystemId);
|
||||
repositoryGroupRepository.flush();
|
||||
|
||||
// 4. 更新或创建仓库组
|
||||
// 4. 批量保存从Git API获取的仓库组到数据库
|
||||
List<RepositoryGroup> groupsToSave = remoteGroups.stream()
|
||||
.map(remoteGroup -> updateOrCreateGroup(externalSystemId, remoteGroup, existingGroupMap))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 5. 保存仓库组
|
||||
repositoryGroupRepository.saveAll(groupsToSave);
|
||||
|
||||
log.info("Successfully synchronized {} groups for external system: {}",
|
||||
groupsToSave.size(), externalSystem.getName());
|
||||
return groupsToSave.size();
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to sync repository groups for external system: {}", externalSystemId, e);
|
||||
throw new BusinessException(ResponseCode.REPOSITORY_SYNC_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
private RepositoryGroup updateOrCreateGroup(
|
||||
Long externalSystemId,
|
||||
GitGroupResponse remoteGroup,
|
||||
Map<Long, RepositoryGroup> existingGroupMap) {
|
||||
|
||||
RepositoryGroup group = existingGroupMap.getOrDefault(remoteGroup.getId(), new RepositoryGroup());
|
||||
|
||||
// 更新基本信息
|
||||
.map(remoteGroup -> {
|
||||
RepositoryGroup group = new RepositoryGroup();
|
||||
group.setExternalSystemId(externalSystemId);
|
||||
group.setGroupId(remoteGroup.getId());
|
||||
group.setName(remoteGroup.getName());
|
||||
group.setPath(remoteGroup.getPath());
|
||||
group.setDescription(remoteGroup.getDescription());
|
||||
group.setVisibility(remoteGroup.getVisibility());
|
||||
group.setParentId(remoteGroup.getParentId());
|
||||
group.setWebUrl(remoteGroup.getWebUrl());
|
||||
group.setAvatarUrl(remoteGroup.getAvatarUrl());
|
||||
|
||||
group.setParentId(remoteGroup.getParentId());
|
||||
return group;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<RepositoryGroup> savedGroups = repositoryGroupRepository.saveAll(groupsToSave);
|
||||
|
||||
log.info("Successfully synchronized {} groups for external system: {}",
|
||||
savedGroups.size(), externalSystem.getName());
|
||||
return savedGroups.size();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to sync repository groups for external system: {}", externalSystemId, e);
|
||||
throw new BusinessException(ResponseCode.REPOSITORY_SYNC_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -304,13 +304,9 @@ CREATE TABLE deploy_repo_group
|
||||
INDEX idx_external_system_group_id (external_system_id, group_id) COMMENT '外部系统组ID索引',
|
||||
INDEX idx_parent_id (parent_id) COMMENT '父级ID索引',
|
||||
INDEX idx_path ( PATH) COMMENT '路径索引',
|
||||
UNIQUE INDEX uk_external_system_group_path (external_system_id, PATH) COMMENT '外部系统下路径唯一',
|
||||
|
||||
-- 外键约束
|
||||
CONSTRAINT fk_group_parent FOREIGN KEY (parent_id)
|
||||
REFERENCES deploy_repo_group (id),
|
||||
CONSTRAINT fk_group_external_system FOREIGN KEY (external_system_id)
|
||||
REFERENCES sys_external_system (id)
|
||||
CONSTRAINT fk_group_external_system FOREIGN KEY (external_system_id)REFERENCES sys_external_system (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='代码仓库组表';
|
||||
|
||||
-- 代码仓库项目表
|
||||
|
||||
Loading…
Reference in New Issue
Block a user