大声道撒旦

This commit is contained in:
dengqichen 2025-01-08 14:40:40 +08:00
parent 68fe2fedef
commit 39e40969b6
6 changed files with 93 additions and 52 deletions

View File

@ -21,7 +21,7 @@ import java.util.List;
*/ */
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/api/v1/repo-group") @RequestMapping("/api/v1/repository-group")
@Tag(name = "Git仓库组管理", description = "Git仓库组管理相关接口") @Tag(name = "Git仓库组管理", description = "Git仓库组管理相关接口")
public class RepositoryGroupApiController extends BaseController<RepositoryGroup, RepositoryGroupDTO, Long, RepositoryGroupQuery> { public class RepositoryGroupApiController extends BaseController<RepositoryGroup, RepositoryGroupDTO, Long, RepositoryGroupQuery> {

View File

@ -15,9 +15,9 @@ import org.springframework.web.bind.annotation.*;
*/ */
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/api/v1/git-manager") @RequestMapping("/api/v1/repository-manager")
@Tag(name = "Git仓库管理", description = "Git仓库管理相关接口") @Tag(name = "Git仓库管理", description = "Git仓库管理相关接口")
public class GitManagerApiController { public class RepositoryManagerApiController {
@Resource @Resource
private IGitManagerService gitManagerService; private IGitManagerService gitManagerService;

View File

@ -1,5 +1,6 @@
package com.qqchen.deploy.backend.deploy.integration.response; package com.qqchen.deploy.backend.deploy.integration.response;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data; import lombok.Data;
/** /**
@ -18,9 +19,54 @@ public class GitGroupResponse {
private String visibility; private String visibility;
@JsonProperty("parent_id")
private Long parentId; private Long parentId;
@JsonProperty("web_url")
private String webUrl; private String webUrl;
@JsonProperty("avatar_url")
private String avatarUrl; 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;
} }

View File

@ -36,4 +36,11 @@ public interface IRepositoryGroupRepository extends IBaseRepository<RepositoryGr
* @return 仓库组 * @return 仓库组
*/ */
RepositoryGroup findByExternalSystemIdAndGroupId(Long externalSystemId, Long groupId); RepositoryGroup findByExternalSystemIdAndGroupId(Long externalSystemId, Long groupId);
/**
* 根据外部系统ID删除所有仓库组
*
* @param externalSystemId 外部系统ID
*/
void deleteByExternalSystemId(Long externalSystemId);
} }

View File

@ -22,6 +22,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.HashMap;
/** /**
* Git仓库组服务实现 * Git仓库组服务实现
@ -45,59 +47,49 @@ public class RepositoryGroupServiceImpl extends BaseServiceImpl<RepositoryGroup,
@Override @Override
@Transactional @Transactional
public Integer syncGroups(Long externalSystemId) { public Integer syncGroups(Long externalSystemId) {
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. 从Git API获取所有仓库组信息
List<GitGroupResponse> remoteGroups = gitServiceIntegration.groups(externalSystem); List<GitGroupResponse> remoteGroups = gitServiceIntegration.groups(externalSystem);
if (remoteGroups.isEmpty()) { if (remoteGroups.isEmpty()) {
log.info("No groups found in remote git system: {}", externalSystem.getName()); log.info("No groups found in remote git system: {}", externalSystem.getName());
return 0; return 0;
} }
// 3. 获取本地已存在的仓库组 try {
List<RepositoryGroup> existingGroups = repositoryGroupRepository.findByExternalSystemId(externalSystemId); // 3. 清空当前系统中该外部系统的所有仓库组
Map<Long, RepositoryGroup> existingGroupMap = existingGroups.stream() repositoryGroupRepository.deleteByExternalSystemId(externalSystemId);
.collect(Collectors.toMap(RepositoryGroup::getGroupId, Function.identity())); repositoryGroupRepository.flush();
// 4. 更新或创建仓库组 // 4. 批量保存从Git API获取的仓库组到数据库
List<RepositoryGroup> groupsToSave = remoteGroups.stream() List<RepositoryGroup> groupsToSave = remoteGroups.stream()
.map(remoteGroup -> updateOrCreateGroup(externalSystemId, remoteGroup, existingGroupMap)) .map(remoteGroup -> {
.collect(Collectors.toList()); RepositoryGroup group = new RepositoryGroup();
// 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());
// 更新基本信息
group.setExternalSystemId(externalSystemId); group.setExternalSystemId(externalSystemId);
group.setGroupId(remoteGroup.getId()); group.setGroupId(remoteGroup.getId());
group.setName(remoteGroup.getName()); group.setName(remoteGroup.getName());
group.setPath(remoteGroup.getPath()); group.setPath(remoteGroup.getPath());
group.setDescription(remoteGroup.getDescription()); group.setDescription(remoteGroup.getDescription());
group.setVisibility(remoteGroup.getVisibility()); group.setVisibility(remoteGroup.getVisibility());
group.setParentId(remoteGroup.getParentId());
group.setWebUrl(remoteGroup.getWebUrl()); group.setWebUrl(remoteGroup.getWebUrl());
group.setAvatarUrl(remoteGroup.getAvatarUrl()); group.setAvatarUrl(remoteGroup.getAvatarUrl());
group.setParentId(remoteGroup.getParentId());
return group; 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 @Override

View File

@ -304,13 +304,9 @@ CREATE TABLE deploy_repo_group
INDEX idx_external_system_group_id (external_system_id, group_id) COMMENT '外部系统组ID索引', INDEX idx_external_system_group_id (external_system_id, group_id) COMMENT '外部系统组ID索引',
INDEX idx_parent_id (parent_id) COMMENT '父级ID索引', INDEX idx_parent_id (parent_id) COMMENT '父级ID索引',
INDEX idx_path ( PATH) COMMENT '路径索引', 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) CONSTRAINT fk_group_external_system FOREIGN KEY (external_system_id)REFERENCES sys_external_system (id)
REFERENCES deploy_repo_group (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='代码仓库组表'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='代码仓库组表';
-- 代码仓库项目表 -- 代码仓库项目表