大声道撒旦

This commit is contained in:
dengqichen 2025-01-13 15:48:18 +08:00
parent 610fcab26e
commit c705e0eef7
16 changed files with 88 additions and 126 deletions

View File

@ -1,11 +1,9 @@
package com.qqchen.deploy.backend.deploy.dto;
import com.qqchen.deploy.backend.deploy.entity.ProjectGroup;
import com.qqchen.deploy.backend.deploy.enums.DevelopmentLanguageTypeEnum;
import com.qqchen.deploy.backend.framework.dto.BaseDTO;
import com.qqchen.deploy.backend.system.model.ExternalSystemDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -29,27 +27,27 @@ public class ApplicationDTO extends BaseDTO {
@NotNull(message = "三方系统ID不能为空")
private Long externalSystemId;
private ExternalSystemDTO externalSystem;
@NotNull(message = "代码仓库组ID不能为空")
private Long repoGroupId;
private RepositoryGroupDTO repositoryGroup;
@NotNull(message = "代码仓库项目ID不能为空")
private Long repoProjectId;
private RepositoryProjectDTO repositoryProject;
@NotNull(message = "所属项目组ID不能为空")
private Long projectGroupId;
private ProjectGroupDTO projectGroup;
@Schema(description = "是否启用")
private Boolean enabled;
@NotNull(message = "排序号不能为空")
private Integer sort;
private ExternalSystemDTO externalSystem;
private RepositoryGroupDTO repositoryGroup;
private RepositoryProjectDTO repositoryProject;
private ProjectGroupDTO projectGroup;
}

View File

@ -15,10 +15,6 @@ public class RepositoryBranchDTO extends BaseDTO {
private String name;
private Long projectId;
private Long externalSystemId;
private Boolean isDefaultBranch;
private Boolean isProtected;
@ -29,13 +25,17 @@ public class RepositoryBranchDTO extends BaseDTO {
private Boolean developersCanMerge;
private String commitId;
private String lastCommitId;
private String commitMessage;
private String lastCommitMessage;
private String commitAuthor;
private LocalDateTime commitDate;
private String webUrl;
private Long repoProjectId;
private Long externalSystemId;
}

View File

@ -23,11 +23,6 @@ public class RepositoryGroupDTO extends BaseDTO {
*/
private String description;
/**
* 外部系统中的组ID
*/
private Long groupId;
/**
* 父级仓库组ID
*/
@ -38,11 +33,6 @@ public class RepositoryGroupDTO extends BaseDTO {
*/
private String path;
/**
* 外部系统ID
*/
private Long externalSystemId;
/**
* 头像URL
*/
@ -72,4 +62,15 @@ public class RepositoryGroupDTO extends BaseDTO {
private Boolean enabled;
/**
* 外部系统中的组ID
*/
private Long repoGroupId;
/**
* 外部系统ID
*/
private Long externalSystemId;
}

View File

@ -21,8 +21,6 @@ public class RepositoryProjectDTO extends BaseDTO {
private String visibility;
private Long groupId;
private String isDefaultBranch;
private String webUrl;
@ -35,5 +33,7 @@ public class RepositoryProjectDTO extends BaseDTO {
private Long externalSystemId;
private Long projectId;
private Long repoGroupId;
private Long repoProjectId;
}

View File

@ -80,7 +80,7 @@ public class JenkinsBaseBuildVariables {
format = "monaco-editor", // 使用 Monaco Editor
defaultValue = "#!/bin/bash\n\necho \"Hello World\"",
codeEditor = @CodeEditorConfig(
language = "shell",
language = "groovy",
theme = "vs-dark",
minimap = false,
lineNumbers = true,

View File

@ -19,7 +19,6 @@ import org.hibernate.annotations.Type;
@EqualsAndHashCode(callSuper = true)
@jakarta.persistence.Entity
@Table(name = "deploy_app_config")
@LogicDelete
public class DeployAppConfig extends Entity<Long> {

View File

@ -1,24 +0,0 @@
package com.qqchen.deploy.backend.deploy.entity;
import com.qqchen.deploy.backend.framework.domain.Entity;
import jakarta.persistence.Column;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 项目环境关联实体
*/
@Data
@EqualsAndHashCode(callSuper = true)
@jakarta.persistence.Entity
@Table(name = "deploy_project_group_environment")
public class ProjectGroupEnvironment extends Entity<Long> {
@Column(name = "project_group_id")
private Long projectGroupId;
@Column(name = "environment_id")
private Long environmentId;
}

View File

@ -19,8 +19,8 @@ public class RepositoryBranch extends Entity<Long> {
@Column(nullable = false)
private String name;
@Column(name = "commit_id")
private String commitId;
@Column(name = "last_commit_id")
private String lastCommitId;
@Column(name = "commit_message", columnDefinition = "TEXT")
private String commitMessage;
@ -55,8 +55,8 @@ public class RepositoryBranch extends Entity<Long> {
@Column(name = "project_id", nullable = false)
private Long projectId; // 我们数据库的project表的ID
@Column(name = "git_project_id", nullable = false)
private Long gitProjectId; // GitLab的真实project_id
@Column(name = "repo_project_id", nullable = false)
private Long repoProjectId; // GitLab的真实project_id
@Column(name = "external_system_id", nullable = false)
private Long externalSystemId;

View File

@ -42,8 +42,8 @@ public class RepositoryGroup extends Entity<Long> {
@Column(name = "external_system_id")
private Long externalSystemId;
@Column(name = "group_id", nullable = false)
private Long groupId;
@Column(name = "repo_group_id", nullable = false)
private Long repoGroupId;
@Column(name = "full_name")
private String fullName;

View File

@ -26,9 +26,6 @@ public class RepositoryProject extends Entity<Long> {
private String visibility;
@Column(name = "group_id")
private Long groupId;
@Column(name = "default_branch")
private String defaultBranch;
@ -56,6 +53,10 @@ public class RepositoryProject extends Entity<Long> {
@Column(name = "external_system_id")
private Long externalSystemId;
@Column(name = "project_id", nullable = false)
private Long projectId;
}
@Column(name = "repo_group_id")
private Long repoGroupId;
@Column(name = "repo_project_id", nullable = false)
private Long repoProjectId;
}

View File

@ -1,6 +1,5 @@
package com.qqchen.deploy.backend.deploy.repository;
import com.qqchen.deploy.backend.deploy.dto.RepositoryProjectDTO;
import com.qqchen.deploy.backend.framework.repository.IBaseRepository;
import com.qqchen.deploy.backend.deploy.entity.RepositoryProject;
import org.springframework.stereotype.Repository;
@ -17,7 +16,7 @@ public interface IRepositoryProjectRepository extends IBaseRepository<Repository
* @param groupId 仓库组ID
* @return 项目列表
*/
List<RepositoryProject> findByExternalSystemIdAndGroupId(Long externalSystemId, Long groupId);
List<RepositoryProject> findByExternalSystemIdAndRepoGroupId(Long externalSystemId, Long groupId);
/**
* 统计指定外部系统下的项目数量

View File

@ -18,7 +18,6 @@ import com.qqchen.deploy.backend.framework.exception.BusinessException;
import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl;
import com.qqchen.deploy.backend.deploy.dto.RepositorySyncHistoryDTO;
import com.qqchen.deploy.backend.deploy.service.IRepositorySyncHistoryService;
import com.qqchen.deploy.backend.deploy.repository.IRepositorySyncHistoryRepository;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.orm.ObjectOptimisticLockingFailureException;
@ -140,10 +139,10 @@ public class RepositoryBranchServiceImpl extends BaseServiceImpl<RepositoryBranc
for (RepositoryProject project : projects) {
CompletableFuture<List<RepositoryBranch>> future = CompletableFuture.supplyAsync(() -> {
try {
log.info("Syncing branches for project: {} (ID: {}, GitLab ID: {})", project.getName(), project.getId(), project.getProjectId());
log.info("Syncing branches for project: {} (ID: {}, GitLab ID: {})", project.getName(), project.getId(), project.getRepoProjectId());
// 5.1 获取当前项目在GitLab上的所有分支
List<GitBranchResponse> remoteBranches = gitServiceIntegration.branches(externalSystem, project.getProjectId());
List<GitBranchResponse> remoteBranches = gitServiceIntegration.branches(externalSystem, project.getRepoProjectId());
log.info("Found {} remote branches for project: {}", remoteBranches.size(), project.getName());
List<RepositoryBranch> branchesToUpdate = new ArrayList<>();
@ -157,13 +156,13 @@ public class RepositoryBranchServiceImpl extends BaseServiceImpl<RepositoryBranc
// 检查分支是否有更新
if (isBranchChanged(branch, remoteBranch)) {
// 更新分支信息
updateBranchInfo(branch, externalSystemId, project.getId(), project.getProjectId(), remoteBranch);
updateBranchInfo(branch, externalSystemId, project.getId(), project.getRepoProjectId(), remoteBranch);
branchesToUpdate.add(branch);
log.debug("Branch {} has changes, will be updated", remoteBranch.getName());
} else {
log.debug("Branch {} has no changes, skipping update", remoteBranch.getName());
}
processedBranches.add(remoteBranch.getName());
totalSyncedBranches.incrementAndGet();
}
@ -173,7 +172,7 @@ public class RepositoryBranchServiceImpl extends BaseServiceImpl<RepositoryBranc
.flatMap(map -> map.values().stream())
.filter(b -> b.getProjectId().equals(project.getId()))
.collect(Collectors.toMap(RepositoryBranch::getName, Function.identity()));
for (RepositoryBranch branch : projectBranches.values()) {
if (!processedBranches.contains(branch.getName())) {
branch.setDeleted(true);
@ -185,8 +184,7 @@ public class RepositoryBranchServiceImpl extends BaseServiceImpl<RepositoryBranc
log.info("Processed {} branches for project: {}", branchesToUpdate.size(), project.getName());
return branchesToUpdate;
} catch (Exception e) {
log.error("Failed to sync branches for project: {} (ID: {}, GitLab ID: {})",
project.getName(), project.getId(), project.getProjectId(), e);
log.error("Failed to sync branches for project: {} (ID: {}, GitLab ID: {})", project.getName(), project.getId(), project.getRepoProjectId(), e);
throw new RuntimeException(e);
}
}, executor);
@ -243,19 +241,19 @@ public class RepositoryBranchServiceImpl extends BaseServiceImpl<RepositoryBranc
private String generateCompareKey(Object obj) {
StringBuilder key = new StringBuilder();
if (obj instanceof RepositoryBranch branch) {
key.append(branch.getCommitId())
.append(branch.getIsDefaultBranch())
.append(branch.getCanPush())
.append(branch.getDevelopersCanPush())
.append(branch.getDevelopersCanMerge())
.append(branch.getWebUrl());
key.append(branch.getLastCommitId())
.append(branch.getIsDefaultBranch())
.append(branch.getCanPush())
.append(branch.getDevelopersCanPush())
.append(branch.getDevelopersCanMerge())
.append(branch.getWebUrl());
} else if (obj instanceof GitBranchResponse branch) {
key.append(branch.getCommitId())
.append(branch.getIsDefaultBranch())
.append(branch.getCanPush())
.append(branch.getDevelopersCanPush())
.append(branch.getDevelopersCanMerge())
.append(branch.getWebUrl());
.append(branch.getIsDefaultBranch())
.append(branch.getCanPush())
.append(branch.getDevelopersCanPush())
.append(branch.getDevelopersCanMerge())
.append(branch.getWebUrl());
}
return key.toString();
}
@ -263,21 +261,16 @@ public class RepositoryBranchServiceImpl extends BaseServiceImpl<RepositoryBranc
/**
* 更新分支信息
*/
private void updateBranchInfo(
RepositoryBranch branch,
Long externalSystemId,
Long projectId,
Long gitProjectId,
GitBranchResponse remoteBranch) {
private void updateBranchInfo(RepositoryBranch branch, Long externalSystemId, Long projectId, Long gitProjectId, GitBranchResponse remoteBranch) {
branch.setExternalSystemId(externalSystemId);
branch.setProjectId(projectId);
branch.setGitProjectId(gitProjectId);
branch.setRepoProjectId(gitProjectId);
branch.setName(remoteBranch.getName());
branch.setIsDefaultBranch(remoteBranch.getIsDefaultBranch());
branch.setCanPush(remoteBranch.getCanPush());
branch.setDevelopersCanPush(remoteBranch.getDevelopersCanPush());
branch.setDevelopersCanMerge(remoteBranch.getDevelopersCanMerge());
branch.setCommitId(remoteBranch.getCommitId());
branch.setLastCommitId(remoteBranch.getCommitId());
branch.setCommitMessage(remoteBranch.getCommitMessage());
branch.setCommitAuthor(remoteBranch.getCommitAuthor());
branch.setCommitDate(remoteBranch.getCommitDate());

View File

@ -62,7 +62,7 @@ public class RepositoryGroupServiceImpl extends BaseServiceImpl<RepositoryGroup,
// 3. 获取本地已存在的仓库组
List<RepositoryGroup> existingGroups = repositoryGroupRepository.findByExternalSystemIdAndDeletedFalse(externalSystemId);
Map<Long, RepositoryGroup> existingGroupMap = existingGroups.stream()
.collect(Collectors.toMap(RepositoryGroup::getGroupId, Function.identity()));
.collect(Collectors.toMap(RepositoryGroup::getRepoGroupId, Function.identity()));
// 4. 处理每个远程仓库组
List<RepositoryGroup> groupsToSave = new ArrayList<>();
@ -71,7 +71,7 @@ public class RepositoryGroupServiceImpl extends BaseServiceImpl<RepositoryGroup,
// 更新基本信息
group.setExternalSystemId(externalSystemId);
group.setGroupId(remoteGroup.getId());
group.setRepoGroupId(remoteGroup.getId());
group.setName(remoteGroup.getName());
group.setPath(remoteGroup.getPath());
group.setDescription(remoteGroup.getDescription());

View File

@ -113,11 +113,10 @@ public class RepositoryProjectServiceImpl extends BaseServiceImpl<RepositoryProj
.findByExternalSystemId(externalSystemId)
.stream()
.collect(Collectors.toMap(
RepositoryProject::getProjectId,
RepositoryProject::getRepoProjectId,
Function.identity(),
(existing, replacement) -> {
log.warn("Duplicate project found with ID: {}, path: {}",
existing.getProjectId(), existing.getPathWithNamespace());
log.warn("Duplicate project found with ID: {}, path: {}", existing.getRepoProjectId(), existing.getPathWithNamespace());
return existing;
}
))
@ -135,14 +134,12 @@ public class RepositoryProjectServiceImpl extends BaseServiceImpl<RepositoryProj
for (RepositoryGroup group : groups) {
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
try {
List<GitProjectResponse> projectResponses = gitServiceIntegration.projectsByGroup(externalSystem, group.getGroupId());
log.info("Processing group: {} (ID: {}), found {} projects",
group.getName(), group.getGroupId(), projectResponses.size());
List<GitProjectResponse> projectResponses = gitServiceIntegration.projectsByGroup(externalSystem, group.getRepoGroupId());
log.info("Processing group: {} (ID: {}), found {} projects", group.getName(), group.getRepoGroupId(), projectResponses.size());
for (GitProjectResponse projectResponse : projectResponses) {
if (!processedProjectIds.add(projectResponse.getId())) {
log.info("Project already processed: {} (ID: {}) in group: {}",
projectResponse.getPathWithNamespace(), projectResponse.getId(), group.getName());
log.info("Project already processed: {} (ID: {}) in group: {}", projectResponse.getPathWithNamespace(), projectResponse.getId(), group.getName());
continue;
}
@ -150,7 +147,7 @@ public class RepositoryProjectServiceImpl extends BaseServiceImpl<RepositoryProj
if (project == null) {
project = new RepositoryProject();
project.setExternalSystemId(externalSystemId);
project.setProjectId(projectResponse.getId());
project.setRepoProjectId(projectResponse.getId());
log.info("Creating new project: {} (ID: {})",
projectResponse.getPathWithNamespace(), projectResponse.getId());
totalCount.incrementAndGet();
@ -164,7 +161,7 @@ public class RepositoryProjectServiceImpl extends BaseServiceImpl<RepositoryProj
project.setPath(projectResponse.getPath());
project.setDescription(projectResponse.getDescription());
project.setVisibility(projectResponse.getVisibility());
project.setGroupId(group.getId());
project.setRepoGroupId(group.getRepoGroupId());
project.setDefaultBranch(projectResponse.getDefaultBranch());
project.setWebUrl(projectResponse.getWebUrl());
project.setSshUrl(projectResponse.getSshUrlToRepo());

View File

@ -44,7 +44,7 @@ public class DeployNodeLocalVariables extends BaseNodeLocalVariables {
format = "monaco-editor", // 使用 Monaco Editor
defaultValue = "#!/bin/bash\n\necho \"Hello World\"",
codeEditor = @CodeEditorConfig(
language = "shell",
language = "groovy",
theme = "vs-dark",
minimap = false,
lineNumbers = true,

View File

@ -282,7 +282,6 @@ CREATE TABLE deploy_repo_group
-- 基础字段
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
-- 业务字段
group_id BIGINT NOT NULL COMMENT 'Git系统中的组ID',
name VARCHAR(100) NOT NULL COMMENT '仓库组名',
description VARCHAR(500) NULL COMMENT '仓库组描述',
parent_id BIGINT NULL COMMENT '父级仓库组ID',
@ -294,6 +293,7 @@ CREATE TABLE deploy_repo_group
web_url VARCHAR(255) NULL COMMENT '网页URL',
visibility ENUM('private', 'internal', 'public') NOT NULL DEFAULT 'private' COMMENT '可见性private-私有internal-内部public-公开',
sort INT DEFAULT 0 COMMENT '排序号',
repo_group_id BIGINT NOT NULL COMMENT 'Git系统中的组ID',
create_by VARCHAR(100) NULL COMMENT '创建人',
create_time DATETIME(6) NULL COMMENT '创建时间',
@ -308,18 +308,11 @@ CREATE TABLE deploy_repo_group
CREATE TABLE deploy_repo_project
(
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
create_by VARCHAR(255) NULL COMMENT '创建人',
create_time DATETIME(6) NULL COMMENT '创建时间',
deleted BIT NOT NULL DEFAULT 0 COMMENT '是否删除0未删除1已删除',
update_by VARCHAR(255) NULL COMMENT '更新人',
update_time DATETIME(6) NULL COMMENT '更新时间',
version INT NOT NULL DEFAULT 0 COMMENT '乐观锁版本号',
name VARCHAR(255) NOT NULL COMMENT '项目名称',
path VARCHAR(255) NOT NULL COMMENT '项目路径',
description TEXT NULL COMMENT '项目描述',
visibility VARCHAR(50) NULL COMMENT '可见性',
group_id BIGINT NULL COMMENT '所属组ID',
default_branch VARCHAR(100) NULL COMMENT '默认分支',
web_url VARCHAR(500) NULL COMMENT 'Web URL',
ssh_url VARCHAR(500) NULL COMMENT 'SSH URL',
@ -328,11 +321,18 @@ CREATE TABLE deploy_repo_project
name_with_namespace VARCHAR(500) NULL COMMENT '带命名空间的名称',
path_with_namespace VARCHAR(500) NULL COMMENT '带命名空间的路径',
created_at DATETIME(6) NULL COMMENT '创建时间',
external_system_id BIGINT NOT NULL COMMENT '外部系统ID',
project_id BIGINT NOT NULL COMMENT '项目ID',
CONSTRAINT UK_repo_project_external_system_id_project_id UNIQUE (external_system_id, project_id),
CONSTRAINT FK_repo_project_group FOREIGN KEY (group_id) REFERENCES deploy_repo_group (id),
external_system_id BIGINT NOT NULL COMMENT '外部系统ID',
repo_group_id BIGINT NOT NULL COMMENT '项目ID',
repo_project_id BIGINT NOT NULL COMMENT '项目ID',
create_by VARCHAR(255) NULL COMMENT '创建人',
create_time DATETIME(6) NULL COMMENT '创建时间',
deleted BIT NOT NULL DEFAULT 0 COMMENT '是否删除0未删除1已删除',
update_by VARCHAR(255) NULL COMMENT '更新人',
update_time DATETIME(6) NULL COMMENT '更新时间',
version INT NOT NULL DEFAULT 0 COMMENT '乐观锁版本号',
CONSTRAINT FK_repo_project_external_system FOREIGN KEY (external_system_id) REFERENCES sys_external_system (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Git仓库项目表';
@ -347,7 +347,7 @@ CREATE TABLE deploy_repo_branch
can_push BIT DEFAULT 1 COMMENT '是否可推送0-否1-是',
developers_can_push BIT DEFAULT 1 COMMENT '开发者是否可推送0-否1-是',
developers_can_merge BIT DEFAULT 1 COMMENT '开发者是否可合并0-否1-是',
commit_id VARCHAR(64) NULL COMMENT '最新提交ID',
last_commit_id VARCHAR(64) NULL COMMENT '最新提交ID',
commit_message TEXT NULL COMMENT '最新提交信息',
commit_author VARCHAR(100) NULL COMMENT '最新提交作者',
commit_date DATETIME(6) NULL COMMENT '最新提交时间',
@ -356,7 +356,7 @@ CREATE TABLE deploy_repo_branch
web_url VARCHAR(255) NULL COMMENT '网页URL',
project_id BIGINT NOT NULL COMMENT '所属项目ID',
external_system_id BIGINT NOT NULL COMMENT '外部系统ID',
git_project_id BIGINT NOT NULL COMMENT 'GitLab的真实project_id',
repo_project_id BIGINT NOT NULL COMMENT 'GitLab的真实project_id',
create_by VARCHAR(100) NULL COMMENT '创建人',
create_time DATETIME(6) NULL COMMENT '创建时间',
@ -365,9 +365,7 @@ CREATE TABLE deploy_repo_branch
version INT NOT NULL DEFAULT 1 COMMENT '版本号',
deleted BIT NOT NULL DEFAULT 0 COMMENT '是否删除0-未删除1-已删除'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='代码仓库分支表';
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT ='代码仓库分支表';
-- --------------------------------------------------------------------------------------
-- 工作流相关表