This commit is contained in:
asp_ly 2024-12-26 21:37:35 +08:00
parent beaf761b0f
commit 028137e8a0
8 changed files with 78 additions and 68 deletions

View File

@ -2,8 +2,11 @@ package com.qqchen.deploy.backend.deploy.dto;
import com.fasterxml.jackson.databind.JsonNode;
import com.qqchen.deploy.backend.deploy.enums.BuildTypeEnum;
import com.qqchen.deploy.backend.deploy.enums.DevelopmentLanguageTypeEnum;
import com.qqchen.deploy.backend.framework.dto.BaseDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -16,14 +19,21 @@ import lombok.EqualsAndHashCode;
public class DeployAppConfigDTO extends BaseDTO {
@Schema(description = "环境ID")
@NotBlank(message = "环境ID不能为空")
private Long environmentId;
@Schema(description = "应用ID")
@NotBlank(message = "应用ID不能为空")
private Long applicationId;
@Schema(description = "构建类型")
@NotNull(message = "构建类型不能为空")
private BuildTypeEnum buildType;
@Schema(description = "构建变量")
@NotNull(message = "应用语言不能为空")
private DevelopmentLanguageTypeEnum languageType;
@Schema(description = "构建配置")
@NotBlank(message = "构建配置不能为空")
private JsonNode buildVariables;
}

View File

@ -12,7 +12,8 @@ public class JenkinsBaseBuildVariables {
@SchemaProperty(
title = "分支名称",
description = "Git分支名称",
required = true
required = true,
order = 1
)
private String branch;

View File

@ -13,52 +13,22 @@ public class JenkinsJavaBuildVariables extends JenkinsBaseBuildVariables {
@SchemaProperty(
title = "脚本代码",
description = "脚本代码",
required = true
title = "构建产物路径",
description = "构建产物路径",
order = 2
)
private String artifactPath;
@SchemaProperty(
title = "Pipeline script",
description = "流水线脚本",
required = true,
format = "monaco-editor", // 使用 Monaco Editor
defaultValue = "#!/bin/bash\n\necho \"Hello World\"",
order = 3
)
private String script;
/**
* 脚本语言
*/
@SchemaProperty(
title = "脚本语言",
description = "脚本语言类型",
required = true,
enumValues = {"shell", "python", "javascript", "groovy"},
enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"},
defaultValue = "shell"
)
private String language;
/**
* 解释器路径
*/
@SchemaProperty(
title = "解释器路径",
description = "脚本解释器的路径,例如:/bin/bash, /usr/bin/python3",
required = true
)
private String interpreter;
/**
* 成功退出码
*/
@SchemaProperty(
title = "成功标识",
description = "脚本执行成功时的标识",
required = true
)
private Integer successExitCode;
/**
* 支持的脚本语言列表
*/
@SchemaProperty(
title = "支持的脚本语言",
enumValues = {"shell", "python", "javascript", "groovy"},
enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"}
)
private List<String> supportedLanguages;
}

View File

@ -3,6 +3,7 @@ package com.qqchen.deploy.backend.deploy.entity;
import com.fasterxml.jackson.databind.JsonNode;
import com.qqchen.deploy.backend.deploy.enums.BuildTypeEnum;
import com.qqchen.deploy.backend.deploy.enums.DevelopmentLanguageTypeEnum;
import com.qqchen.deploy.backend.framework.domain.Entity;
import com.vladmihalcea.hibernate.type.json.JsonType;
import jakarta.persistence.Column;
@ -26,10 +27,14 @@ public class DeployAppConfig extends Entity<Long> {
@Column(name = "application_id", nullable = false)
private Long applicationId;
@Column(nullable = false)
@Column(name = "build_type", nullable = false)
@Enumerated(EnumType.STRING)
private BuildTypeEnum buildType;
@Column(name = "language_type", nullable = false)
@Enumerated(EnumType.STRING)
private DevelopmentLanguageTypeEnum languageType;
@Type(JsonType.class)
@Column(name = "build_variables", columnDefinition = "text", nullable = false)
private JsonNode buildVariables;

View File

@ -93,4 +93,9 @@ public @interface SchemaProperty {
* 枚举值显示名称
*/
String[] enumNames() default {};
/**
* 字段排序值越小越靠前
*/
int order() default Integer.MAX_VALUE;
}

View File

@ -12,7 +12,8 @@ public class BaseNodePanelVariables {
@SchemaProperty(
title = "节点编码",
description = "工作流节点的编码",
required = true
required = true,
order = 1
)
private String code;
@ -22,7 +23,8 @@ public class BaseNodePanelVariables {
@SchemaProperty(
title = "节点名称",
description = "工作流节点的显示名称",
required = true
required = true,
order = 2
)
private String name;
@ -31,7 +33,8 @@ public class BaseNodePanelVariables {
*/
@SchemaProperty(
title = "节点描述",
description = "工作流节点的详细描述"
description = "工作流节点的详细描述",
order = 3
)
private String description;
}

View File

@ -14,13 +14,6 @@ import java.util.List;
public class ScriptNodePanelVariables extends BaseNodePanelVariables {
@SchemaProperty(
title = "脚本代码",
description = "脚本代码",
required = true
)
private String script;
/**
* 脚本语言
*/
@ -30,27 +23,33 @@ public class ScriptNodePanelVariables extends BaseNodePanelVariables {
required = true,
enumValues = {"shell", "python", "javascript", "groovy"},
enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"},
defaultValue = "shell"
defaultValue = "shell",
order = 10
)
private String language;
/**
* 解释器路径
*/
@SchemaProperty(
title = "脚本代码",
description = "脚本代码",
required = true,
format = "monaco-editor",
order = 20
)
private String script;
@SchemaProperty(
title = "解释器路径",
description = "脚本解释器的路径,例如:/bin/bash, /usr/bin/python3",
required = true
required = true,
order = 30
)
private String interpreter;
/**
* 成功退出码
*/
@SchemaProperty(
title = "成功标识",
description = "脚本执行成功时的标识",
required = true
required = true,
order = 40
)
private Integer successExitCode;
@ -60,7 +59,8 @@ public class ScriptNodePanelVariables extends BaseNodePanelVariables {
@SchemaProperty(
title = "支持的脚本语言",
enumValues = {"shell", "python", "javascript", "groovy"},
enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"}
enumNames = {"Shell脚本 (已支持)", "Python脚本 (开发中)", "JavaScript脚本 (开发中)", "Groovy脚本 (开发中)"},
order = 50
)
private List<String> supportedLanguages;

View File

@ -27,6 +27,22 @@ public class GenerateSchemaUtils {
// 获取所有字段包括父类的字段
List<Field> allFields = getAllFields(cls);
// 按SchemaProperty的order排序
allFields.sort((a, b) -> {
SchemaProperty annotationA = a.getAnnotation(SchemaProperty.class);
SchemaProperty annotationB = b.getAnnotation(SchemaProperty.class);
if (annotationA == null && annotationB == null) {
return 0;
}
if (annotationA == null) {
return 1;
}
if (annotationB == null) {
return -1;
}
return Integer.compare(annotationA.order(), annotationB.order());
});
// 遍历所有字段
for (Field field : allFields) {
SchemaProperty annotation = field.getAnnotation(SchemaProperty.class);