5/5 ljc
补充trigger代码块; 新增util/variable/version/wehHook模块; task模块代码初步提交,包含子模块artifact/build/code/codescan; 调整部分service和impl位置,进行统一包路径管理,对service和impl相互关系做代码补充以及编译调试(可能影响部分原先包目录结构); 新增部分工具类/注解以及系统字段
This commit is contained in:
parent
2572798cc9
commit
9feee4fd45
@ -23,6 +23,10 @@
|
||||
<groupId>cd.casic.boot</groupId>
|
||||
<artifactId>module-system-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,26 @@
|
||||
package cd.casic.ci.commons.bean.commons;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName Pagination
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 21:32
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class Pagination<T> implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 5016662499561189494L;
|
||||
private int pageSize = 10;
|
||||
private int currentPage = 1;
|
||||
private int totalRecord;
|
||||
private int totalPage;
|
||||
private int beginIndex;
|
||||
private int endIndex;
|
||||
private List<T> dataList;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package cd.casic.ci.commons.bean.jdbc;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* @ClassName JdbcTemplate
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 21:29
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
|
||||
private static Logger logger = LoggerFactory.getLogger(JdbcTemplate.class);
|
||||
|
||||
public JdbcTemplate(DataSource dataSource) {
|
||||
super(dataSource);
|
||||
}
|
||||
|
||||
public JdbcTemplate(DataSource dataSource, boolean lazyInit) {
|
||||
super(dataSource, lazyInit);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package cd.casic.ci.commons.join.annototion;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @ClassName Join
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 18:38
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Join {
|
||||
Class model() default Object.class;
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cd.casic.module.process.core.context;
|
||||
|
||||
/**
|
||||
* @ClassName AppHomeContext
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 18:25
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class AppHomeContext {
|
||||
private static String appHome;
|
||||
|
||||
public AppHomeContext() {
|
||||
}
|
||||
|
||||
public static String getAppHome() {
|
||||
return appHome;
|
||||
}
|
||||
|
||||
public static void setAppHome(String appHome) {
|
||||
AppHomeContext.appHome = appHome;
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import cd.casic.ci.commons.bean.engine.execute.PipelineDetails;
|
||||
import cd.casic.ci.commons.bean.engine.execute.PipelineRunMsg;
|
||||
import cd.casic.ci.commons.bean.engine.postprocess.Postprocess;
|
||||
import cd.casic.ci.commons.bean.process.definition.Pipeline;
|
||||
import cd.casic.ci.commons.bean.process.definition.Variable;
|
||||
import cd.casic.module.process.support.variable.model.Variable;
|
||||
import cd.casic.ci.commons.bean.process.instance.PipelineInstance;
|
||||
import cd.casic.ci.commons.bean.process.instance.PipelineInstanceQuery;
|
||||
import cd.casic.ci.commons.bean.process.setting.Scm;
|
||||
@ -19,7 +19,7 @@ import cd.casic.module.process.support.postprocess.service.PostprocessExecServic
|
||||
import cd.casic.module.process.engine.task.TasksExecService;
|
||||
import cd.casic.module.process.pipeline.instance.service.PipelineInstanceServiceImpl;
|
||||
import cd.casic.module.process.process.definition.PipelineService;
|
||||
import cd.casic.module.process.process.definition.VariableService;
|
||||
import cd.casic.module.process.support.variable.service.VariableService;
|
||||
import cd.casic.module.process.process.instance.PipelineInstanceService;
|
||||
import cd.casic.module.process.process.setting.ResourcesService;
|
||||
import cd.casic.module.process.process.setting.ScmService;
|
||||
@ -27,7 +27,7 @@ import cd.casic.module.process.process.stage.StageExecService;
|
||||
import cd.casic.module.process.process.stage.StageService;
|
||||
import cd.casic.module.process.support.agent.service.AgentService;
|
||||
import cd.casic.module.process.support.disk.service.DiskService;
|
||||
import cd.casic.module.process.support.home.PipelineVersionService;
|
||||
import cd.casic.module.process.support.version.service.PipelineVersionService;
|
||||
import cd.casic.module.process.support.util.PipelineUtilService;
|
||||
import cd.casic.module.process.support.util.util.PipelineFinal;
|
||||
import cd.casic.module.process.toolkit.join.JoinTemplate;
|
||||
|
@ -5,7 +5,6 @@ import cd.casic.ci.commons.bean.process.definition.*;
|
||||
import cd.casic.ci.commons.bean.process.instance.PipelineInstance;
|
||||
import cd.casic.ci.commons.bean.utils.PipelineFileUtil;
|
||||
import cd.casic.ci.commons.bean.utils.PipelineUtil;
|
||||
import cd.casic.framework.commons.exception.ErrorCode;
|
||||
import cd.casic.framework.commons.exception.ServiceException;
|
||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
@ -19,7 +18,7 @@ import cd.casic.module.process.pipeline.definition.PipelineOpenService;
|
||||
import cd.casic.module.process.pipeline.definition.PipelineService;
|
||||
import cd.casic.module.process.pipeline.definition.entity.PipelineEntity;
|
||||
|
||||
import cd.casic.module.process.process.definition.VariableService;
|
||||
import cd.casic.module.process.support.variable.service.VariableService;
|
||||
import cd.casic.module.process.process.definition.dao.PipelineDao;
|
||||
import cd.casic.module.process.process.instance.PipelineInstanceService;
|
||||
import cd.casic.module.process.process.stage.StageService;
|
||||
@ -31,14 +30,10 @@ import cd.casic.module.process.support.util.PipelineUtilService;
|
||||
import cd.casic.module.process.support.util.util.PipelineFinal;
|
||||
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||
import cd.casic.module.process.toolkit.join.JoinTemplate;
|
||||
import cd.casic.module.process.user.user.User;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.security.auth.login.LoginContext;
|
||||
import java.io.File;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
@ -6,7 +6,7 @@ import cd.casic.ci.commons.bean.engine.execute.PipelineRunMsg;
|
||||
import cd.casic.ci.commons.bean.engine.postprocess.Postprocess;
|
||||
import cd.casic.ci.commons.bean.exception.SystemException;
|
||||
import cd.casic.ci.commons.bean.process.definition.Pipeline;
|
||||
import cd.casic.ci.commons.bean.process.definition.Variable;
|
||||
import cd.casic.module.process.support.variable.model.Variable;
|
||||
import cd.casic.ci.commons.bean.process.instance.PipelineInstance;
|
||||
import cd.casic.ci.commons.bean.process.instance.PipelineInstanceQuery;
|
||||
import cd.casic.ci.commons.bean.process.setting.Scm;
|
||||
@ -19,7 +19,7 @@ import cd.casic.module.process.engine.task.TasksExecService;
|
||||
import cd.casic.module.process.pipeline.definition.PipelineService;
|
||||
import cd.casic.module.process.pipeline.execute.service.PipelineExecService;
|
||||
import cd.casic.module.process.pipeline.instance.service.PipelineInstanceServiceImpl;
|
||||
import cd.casic.module.process.process.definition.VariableService;
|
||||
import cd.casic.module.process.support.variable.service.VariableService;
|
||||
import cd.casic.module.process.process.instance.PipelineInstanceService;
|
||||
import cd.casic.module.process.setting.service.ResourcesService;
|
||||
import cd.casic.module.process.setting.service.ScmService;
|
||||
@ -27,7 +27,7 @@ import cd.casic.module.process.stages.service.StageExecService;
|
||||
import cd.casic.module.process.stages.service.StageService;
|
||||
import cd.casic.module.process.support.agent.service.AgentService;
|
||||
import cd.casic.module.process.support.disk.service.DiskService;
|
||||
import cd.casic.module.process.support.home.PipelineVersionService;
|
||||
import cd.casic.module.process.support.version.service.PipelineVersionService;
|
||||
import cd.casic.module.process.support.postprocess.service.PostprocessExecService;
|
||||
import cd.casic.module.process.support.util.PipelineUtilService;
|
||||
import cd.casic.module.process.support.util.util.PipelineFinal;
|
||||
|
@ -4,16 +4,12 @@ package cd.casic.module.process.process.setting.impl;
|
||||
import cd.casic.ci.commons.bean.process.setting.Cache;
|
||||
import cd.casic.module.process.process.setting.CacheService;
|
||||
import cd.casic.module.process.process.setting.dao.CacheDao;
|
||||
import cd.casic.module.process.support.home.PipelineVersionService;
|
||||
import cd.casic.module.process.support.version.service.PipelineVersionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cd.casic.ci.commons.bean.commons.PipelineConstants.DEFAULT_CLEAN_CACHE_DAY;
|
||||
|
||||
|
||||
@Service
|
||||
|
@ -0,0 +1,15 @@
|
||||
package cd.casic.module.process.support.util;
|
||||
|
||||
/**
|
||||
* @ClassName PipelineDataService
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 18:27
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface PipelineDataService {
|
||||
|
||||
/**
|
||||
* 清理消息数据
|
||||
*/
|
||||
void cleanMessageData();
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package cd.casic.module.process.support.util.impl;
|
||||
|
||||
import cd.casic.ci.commons.bean.process.definition.Pipeline;
|
||||
import cd.casic.module.process.message.message.MessageDmNoticeService;
|
||||
import cd.casic.module.process.message.message.model.MessageDmNotice;
|
||||
import cd.casic.module.process.message.message.model.MessageDmNoticeQuery;
|
||||
import cd.casic.module.process.message.message.model.MessageNoticePatch;
|
||||
import cd.casic.module.process.pipeline.definition.PipelineService;
|
||||
import cd.casic.module.process.support.util.PipelineDataService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName PipelineDataServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 18:27
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class PipelineDataServiceImpl implements PipelineDataService {
|
||||
|
||||
@Resource
|
||||
PipelineService pipelineService;
|
||||
|
||||
@Resource
|
||||
MessageDmNoticeService messageDmNoticeService;
|
||||
|
||||
|
||||
@Override
|
||||
public void cleanMessageData(){
|
||||
|
||||
List<Pipeline> allPipeline = pipelineService.findAllPipelineNoQuery();
|
||||
|
||||
for (Pipeline pipeline : allPipeline) {
|
||||
String domainId = pipeline.getId();
|
||||
|
||||
MessageDmNoticeQuery messageDmNoticeQuery = new MessageDmNoticeQuery();
|
||||
messageDmNoticeQuery.setDomainId(domainId);
|
||||
List<MessageDmNotice> messageDmNoticeList =
|
||||
messageDmNoticeService.findMessageDmNoticeList(messageDmNoticeQuery);
|
||||
|
||||
if (!messageDmNoticeList.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
|
||||
// 克隆消息模版
|
||||
MessageNoticePatch messageNoticePatch = new MessageNoticePatch();
|
||||
messageNoticePatch.setDomainId(domainId);
|
||||
messageNoticePatch.setUserList(List.of(String.valueOf(pipeline.getAdminUserRespDTO().getId())));
|
||||
messageDmNoticeService.initMessageDmNotice(messageNoticePatch);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
package cd.casic.module.process.support.util.impl;
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.utils.PipelineFileUtil;
|
||||
import cd.casic.ci.commons.bean.utils.PipelineUtil;
|
||||
import cd.casic.module.process.core.context.AppHomeContext;
|
||||
import cd.casic.module.process.support.util.PipelineUtilService;
|
||||
import cd.casic.module.process.support.util.util.PipelineFinal;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @ClassName PipelineUtilServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 18:22
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class PipelineUtilServiceImpl implements PipelineUtilService{
|
||||
@Value("${DATA_HOME:null}")
|
||||
String dataHome;
|
||||
|
||||
@Value("${jdk.address:null}")
|
||||
String jdkPath;
|
||||
|
||||
@Override
|
||||
public String instanceAddress(int type) {
|
||||
if (Objects.isNull(dataHome) || "null".equals(dataHome)){
|
||||
dataHome = "/opt/tiklab/tiklab-arbess";
|
||||
}
|
||||
|
||||
return switch (type) {
|
||||
case 0 -> dataHome + PipelineFinal.MATFLOW_INSTABCE;
|
||||
case 1 -> dataHome + PipelineFinal.MATFLOW_WORKSPACE;
|
||||
default -> dataHome + PipelineFinal.MATFLOW_LOGS;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String findPipelineDefaultAddress(String pipelineId, int type) {
|
||||
String path = instanceAddress(type);
|
||||
int systemType = PipelineUtil.findSystemType();
|
||||
if (systemType == 1){
|
||||
if (!PipelineUtil.isNoNull(pipelineId)){
|
||||
return path + "\\";
|
||||
}else {
|
||||
return path + "\\" + pipelineId + "\\";
|
||||
}
|
||||
}else {
|
||||
if (!PipelineUtil.isNoNull(pipelineId)){
|
||||
return path + "/";
|
||||
}else {
|
||||
return path + "/" + pipelineId + "/" ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String findFile(String pipelineId,String fileDir, String regex) {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
File file3 = new File(fileDir);
|
||||
if (file3.exists() && file3.isFile()){
|
||||
return fileDir;
|
||||
}
|
||||
|
||||
File file2 = new File(fileDir + "/" + regex);
|
||||
if (file2.exists() && file2.isFile()){
|
||||
return file2.getAbsolutePath();
|
||||
}
|
||||
|
||||
List<String> filePath = PipelineFileUtil.getFilePath(new File(fileDir),new ArrayList<>());
|
||||
for (String s : filePath) {
|
||||
File file = new File(s);
|
||||
|
||||
//拼装正则匹配
|
||||
boolean matches = file.getName().matches("^(.*" + regex + ".*)");
|
||||
|
||||
//正则匹配
|
||||
boolean matches1 = file.getName().matches(regex);
|
||||
|
||||
File file1 = new File(s + "/" + regex);
|
||||
if (file1.exists()){
|
||||
return file1.getAbsolutePath();
|
||||
}
|
||||
|
||||
if (matches || matches1){
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 1){
|
||||
StringBuilder s = new StringBuilder("匹配到多个文件,请重新输入文件信息。");
|
||||
for (String s1 : list) {
|
||||
s.append("\n").append(s1);
|
||||
}
|
||||
throw new ApplicationException(s.toString());
|
||||
}
|
||||
|
||||
if (list.size()== 1){
|
||||
return list.get(0);
|
||||
}
|
||||
throw new ApplicationException("没有匹配到文件。");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String findJavaPath(){
|
||||
|
||||
if (!"null".equals(jdkPath)){
|
||||
return jdkPath;
|
||||
}
|
||||
|
||||
String appHome = AppHomeContext.getAppHome();
|
||||
String applyRootDir = new File(appHome).getParentFile().getParent();
|
||||
|
||||
return appHome+"/embbed/jdk-16.0.2";
|
||||
|
||||
}
|
||||
}
|
@ -19,6 +19,8 @@ public class PipelineFinal {
|
||||
|
||||
public static final String MATFLOW_LOGS = "/artifact";
|
||||
|
||||
public static final String MATFLOW_INSTABCE = "/instance";
|
||||
|
||||
|
||||
/**
|
||||
* 流水线运行状态
|
||||
@ -208,6 +210,13 @@ public class PipelineFinal {
|
||||
public static final Integer DEFAULT_CLEAN_CACHE_DAY = 7;
|
||||
|
||||
|
||||
// 上传类型
|
||||
public static final String TASK_TYPE_UPLOAD = "upload";
|
||||
public static final String TASK_UPLOAD_HADESS = "upload_hadess";
|
||||
public static final String TASK_UPLOAD_SSH = "upload_ssh";
|
||||
public static final String TASK_UPLOAD_NEXUS = "upload_nexus";
|
||||
public static final String TASK_UPLOAD_DOCKER = "upload_docker";
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,222 @@
|
||||
package cd.casic.module.process.support.util.util;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/5 06:04
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.exception.SystemException;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.ResourceAccessException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
public class PipelineRequestUtil {
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
PipelineRequestUtil requestUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 发起Post请求
|
||||
* @param headers 请求头
|
||||
* @param requestUrl 请求地址
|
||||
* @param param 请求参数
|
||||
* @param tClass 返回类型
|
||||
* @return 请求结果
|
||||
* @throws ApplicationException 请求失败
|
||||
*/
|
||||
public <T> T requestPost(HttpHeaders headers, String requestUrl, Object param, Class<T> tClass){
|
||||
|
||||
// 创建带有头部和请求体的 HttpEntity
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(param, headers);
|
||||
ResponseEntity<JSONObject> response;
|
||||
try {
|
||||
response = restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, JSONObject.class);
|
||||
}catch (ResourceAccessException e){
|
||||
boolean timedOut = Objects.requireNonNull(e.getMessage()).contains("Read timed out");
|
||||
boolean connectOut = Objects.requireNonNull(e.getMessage()).contains("Connect timed out");
|
||||
if (timedOut || connectOut){
|
||||
throw new ApplicationException(50001,"请求超时!");
|
||||
}
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
|
||||
JSONObject jsonObject = response.getBody();
|
||||
return findBody(jsonObject,tClass);
|
||||
}
|
||||
|
||||
public <T> List<T> requestPostList(HttpHeaders headers, String requestUrl, Object param, Class<T> tClass){
|
||||
|
||||
// 创建带有头部和请求体的 HttpEntity
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(param, headers);
|
||||
|
||||
ResponseEntity<JSONObject> response;
|
||||
try {
|
||||
response = restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, JSONObject.class);
|
||||
}catch (ResourceAccessException e){
|
||||
boolean timedOut = Objects.requireNonNull(e.getMessage()).contains("Read timed out");
|
||||
boolean connectOut = Objects.requireNonNull(e.getMessage()).contains("Connect timed out");
|
||||
if (timedOut || connectOut){
|
||||
throw new ApplicationException(50001,"请求超时!");
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
JSONObject jsonObject = response.getBody();
|
||||
return findBodyList(jsonObject,tClass);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发起Get请求
|
||||
* @param headers 请求头
|
||||
* @param requestUrl 请求地址
|
||||
* @param tClass 返回类型
|
||||
* @return 请求结果
|
||||
* @throws ApplicationException 请求失败
|
||||
*/
|
||||
public <T> T requestGet(HttpHeaders headers, String requestUrl, Object param, Class<T> tClass){
|
||||
|
||||
// 创建带有头部和请求体的 HttpEntity
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(param, headers);
|
||||
|
||||
ResponseEntity<JSONObject> response;
|
||||
try {
|
||||
response = restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, JSONObject.class);
|
||||
}catch (ResourceAccessException e){
|
||||
boolean timedOut = Objects.requireNonNull(e.getMessage()).contains("Read timed out");
|
||||
boolean connectOut = Objects.requireNonNull(e.getMessage()).contains("Connect timed out");
|
||||
if (timedOut || connectOut){
|
||||
throw new ApplicationException(50001,"请求超时!");
|
||||
}
|
||||
throw new RuntimeException();
|
||||
}
|
||||
JSONObject jsonObject = response.getBody();
|
||||
|
||||
return findBody(jsonObject,tClass);
|
||||
}
|
||||
|
||||
public <T> List<T> requestGetList(HttpHeaders headers, String requestUrl, Object param, Class<T> tClass){
|
||||
|
||||
// 创建带有头部和请求体的 HttpEntity
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(param, headers);
|
||||
|
||||
ResponseEntity<JSONObject> response;
|
||||
try {
|
||||
response = restTemplate.exchange(requestUrl, HttpMethod.GET, requestEntity, JSONObject.class);
|
||||
}catch (ResourceAccessException e){
|
||||
boolean timedOut = Objects.requireNonNull(e.getMessage()).contains("Read timed out");
|
||||
boolean connectOut = Objects.requireNonNull(e.getMessage()).contains("Connect timed out");
|
||||
if (timedOut || connectOut){
|
||||
throw new ApplicationException(50001,"请求超时!");
|
||||
}
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
JSONObject jsonObject = response.getBody();
|
||||
return findBodyList(jsonObject,tClass);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 转换接口请求内容
|
||||
* @param jsonObject 接口返回数据
|
||||
* @param tClass 转换模型
|
||||
* @return 转换后对象
|
||||
* @param <T> 对象类型
|
||||
*/
|
||||
public <T> T findBody(JSONObject jsonObject,Class<T> tClass){
|
||||
if (Objects.isNull(jsonObject)){
|
||||
throw new ApplicationException(50001,"获取接口返回数据为空!");
|
||||
}
|
||||
Integer code = jsonObject.getInteger("code");
|
||||
if (code != 0){
|
||||
String msg = jsonObject.getString("msg");
|
||||
throw new SystemException("错误!,Message:" + msg);
|
||||
}
|
||||
|
||||
if (tClass.isAssignableFrom(String.class)){
|
||||
String data = jsonObject.getString("data");
|
||||
return (T)data;
|
||||
}
|
||||
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
if (Objects.isNull(data)){
|
||||
return null;
|
||||
}
|
||||
|
||||
return JSONObject.parseObject(data.toJSONString(), tClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换接口请求内容
|
||||
* @param jsonObject 接口返回数据
|
||||
* @param tClass 转换模型
|
||||
* @return 转换后对象
|
||||
* @param <T> 对象类型
|
||||
*/
|
||||
public <T> List<T> findBodyList(JSONObject jsonObject,Class<T> tClass){
|
||||
|
||||
if (Objects.isNull( jsonObject)){
|
||||
throw new SystemException("获取返回值为空!");
|
||||
}
|
||||
Integer code = jsonObject.getInteger("code");
|
||||
if (code != 0){
|
||||
String msg = jsonObject.getString("msg");
|
||||
throw new ApplicationException("错误!,Message:"+msg);
|
||||
}
|
||||
if(Objects.isNull(tClass)){
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
if (Objects.isNull(data)){
|
||||
return null;
|
||||
}
|
||||
return data.toJavaList(tClass);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mediaType 请求类型 MediaType.MULTIPART_FORM_DATA --formdata MediaType.APPLICATION_JSON --json
|
||||
* @param headerMap 其他请求头
|
||||
* @return 请求头
|
||||
*/
|
||||
public HttpHeaders initHeaders(MediaType mediaType, Map<String,String> headerMap){
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(mediaType));
|
||||
if (Objects.isNull(headerMap)){
|
||||
return headers;
|
||||
}
|
||||
for (Map.Entry<String, String> header : headerMap.entrySet()) {
|
||||
String key = header.getKey();
|
||||
String value = header.getValue();
|
||||
headers.set(key,value);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
package cd.casic.module.process.service.support.variable.dao;
|
||||
package cd.casic.module.process.support.variable.dao;
|
||||
|
||||
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cd.casic.module.process.service.support.variable.dataobject.VariableDo;
|
||||
import cd.casic.module.process.support.variable.dataobject.VariableDo;
|
||||
import cd.casic.module.process.support.variable.model.Variable;
|
||||
import cd.casic.module.process.support.variable.model.VariableQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author by mianbin
|
||||
* @Classname VariableDao
|
||||
@ -12,4 +16,15 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
*/
|
||||
@Mapper
|
||||
public interface VariableDao extends BaseMapperX<VariableDo> {
|
||||
String createVariable(Variable variable);
|
||||
|
||||
void deleteVariable(String varId);
|
||||
|
||||
void updateVariable(Variable variable);
|
||||
|
||||
Variable findOneVariable(String varId);
|
||||
|
||||
List<Variable> findAllVariable();
|
||||
|
||||
List<VariableDo> findVariableList(VariableQuery query);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cd.casic.module.process.service.support.variable.dataobject;
|
||||
package cd.casic.module.process.support.variable.dataobject;
|
||||
|
||||
import cd.casic.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cd.casic.ci.commons.bean.process.definition;
|
||||
package cd.casic.module.process.support.variable.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
@ -1,4 +1,4 @@
|
||||
package cd.casic.ci.commons.bean.process.definition;
|
||||
package cd.casic.module.process.support.variable.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
@ -1,7 +1,6 @@
|
||||
package cd.casic.ci.commons.bean.process.definition;
|
||||
package cd.casic.module.process.support.variable.model;
|
||||
|
||||
import cd.casic.framework.commons.pojo.PageParam;
|
||||
import cn.hutool.db.Page;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
@ -1,7 +1,7 @@
|
||||
package cd.casic.module.process.process.definition;
|
||||
package cd.casic.module.process.support.variable.service;
|
||||
|
||||
|
||||
import cd.casic.ci.commons.bean.process.definition.ExecVariable;
|
||||
import cd.casic.module.process.support.variable.model.ExecVariable;
|
||||
|
||||
/**
|
||||
* 执行变量服务接口
|
@ -1,7 +1,7 @@
|
||||
package cd.casic.module.process.process.definition;
|
||||
package cd.casic.module.process.support.variable.service;
|
||||
|
||||
import cd.casic.ci.commons.bean.process.definition.Variable;
|
||||
import cd.casic.ci.commons.bean.process.definition.VariableQuery;
|
||||
import cd.casic.module.process.support.variable.model.Variable;
|
||||
import cd.casic.module.process.support.variable.model.VariableQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -0,0 +1,10 @@
|
||||
package cd.casic.module.process.support.variable.service.impl;
|
||||
|
||||
/**
|
||||
* @ClassName ExecVariableServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 18:47
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class ExecVariableServiceImpl implements ExecVariableService {
|
||||
}
|
@ -0,0 +1,173 @@
|
||||
package cd.casic.module.process.support.variable.service.impl;
|
||||
|
||||
import cd.casic.ci.commons.bean.utils.PipelineUtil;
|
||||
import cd.casic.module.process.support.variable.dao.VariableDao;
|
||||
import cd.casic.module.process.support.variable.dataobject.VariableDo;
|
||||
import cd.casic.module.process.support.variable.model.Variable;
|
||||
import cd.casic.module.process.support.variable.model.VariableQuery;
|
||||
import cd.casic.module.process.support.variable.service.VariableService;
|
||||
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName VariableServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 18:49
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class VariableServiceImpl implements VariableService {
|
||||
|
||||
@Resource
|
||||
private VariableDao variableDao;
|
||||
|
||||
|
||||
public String replaceVariable(String pipelineId,String taskId,String order){
|
||||
Map<String , String > map = new HashMap<>();
|
||||
//替换全局变量
|
||||
List<Variable> allVariable = findAllVariable(pipelineId);
|
||||
if (!allVariable.isEmpty()){
|
||||
for (Variable variable : allVariable) {
|
||||
String varKey = variable.getVarKey();
|
||||
String varValue = variable.getVarValue();
|
||||
map.put(varKey,varValue);
|
||||
}
|
||||
}
|
||||
//替换局部变量
|
||||
List<Variable> variableList = findAllVariable(taskId);
|
||||
if (!variableList.isEmpty()){
|
||||
for (Variable variable : variableList) {
|
||||
String varValue = variable.getVarValue();
|
||||
String varKey = variable.getVarKey();
|
||||
map.put(varKey,varValue);
|
||||
}
|
||||
}
|
||||
|
||||
StrSubstitutor substitutor = new StrSubstitutor(map);
|
||||
return substitutor.replace(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createVariable(Variable variable) {
|
||||
String taskType = variable.getVarType();
|
||||
variable.setCreateTime(PipelineUtil.date(1));
|
||||
if (taskType.equals("single")){
|
||||
String values = updateValues(variable.getValueList());
|
||||
variable.setVarValues(values);
|
||||
}
|
||||
return variableDao.createVariable(variable);
|
||||
}
|
||||
|
||||
private String updateValues(List<String> list ){
|
||||
StringBuilder values = new StringBuilder();
|
||||
for (String s : list) {
|
||||
if (!PipelineUtil.isNoNull(values.toString())){
|
||||
values = new StringBuilder(s);
|
||||
}else {
|
||||
values.append(",").append(s);
|
||||
}
|
||||
}
|
||||
return values.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除变量
|
||||
* @param varId 变量id
|
||||
*/
|
||||
@Override
|
||||
public void deleteVariable(String varId) {
|
||||
variableDao.deleteVariable(varId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新变量
|
||||
* @param variable 变量信息
|
||||
*/
|
||||
@Override
|
||||
public void updateVariable(Variable variable) {
|
||||
String taskType = variable.getVarType();
|
||||
if (taskType.equals("single")){
|
||||
String values = updateValues(variable.getValueList());
|
||||
variable.setVarValues(values);
|
||||
}
|
||||
variableDao.updateVariable(variable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个变量
|
||||
* @param varId 变量id
|
||||
* @return 变量信息
|
||||
*/
|
||||
@Override
|
||||
public Variable findOneVariable(String varId) {
|
||||
return variableDao.findOneVariable(varId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有变量
|
||||
* @return 变量集合
|
||||
*/
|
||||
public List<Variable> findAllVariable() {
|
||||
List<Variable> allVariable = variableDao.findAllVariable();
|
||||
if (allVariable == null || allVariable.isEmpty()){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return allVariable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流水线所有变量
|
||||
* @param taskId 流水线id
|
||||
* @return 变量
|
||||
*/
|
||||
@Override
|
||||
public List<Variable> findAllVariable(String taskId) {
|
||||
List<Variable> allVariable = findAllVariable();
|
||||
if (allVariable.isEmpty()){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Variable> list = new ArrayList<>();
|
||||
for (Variable variable : allVariable) {
|
||||
String id = variable.getTaskId();
|
||||
if (id == null ||!id.equals(taskId)){
|
||||
continue;
|
||||
}
|
||||
if (variable.getVarType().equals("single")){
|
||||
String values = variable.getVarValues();
|
||||
String[] split = values.split(",");
|
||||
List<String> stringList = new ArrayList<>(List.of(split));
|
||||
variable.setValueList(stringList);
|
||||
}
|
||||
list.add(variable);
|
||||
}
|
||||
list.sort(Comparator.comparing(Variable::getCreateTime).reversed());
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Variable> findVariableList(VariableQuery query){
|
||||
List<VariableDo> variableList = variableDao.findVariableList(query);
|
||||
if (variableList == null || variableList.isEmpty()){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return BeanMapper.mapList(variableList, Variable.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cloneVariable(String id,String cloneId){
|
||||
VariableQuery variableQuery = new VariableQuery();
|
||||
variableQuery.setTaskId(id);
|
||||
List<Variable> variableList = findVariableList(variableQuery);
|
||||
for (Variable variable : variableList) {
|
||||
variable.setTaskId(cloneId);
|
||||
createVariable(variable);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cd.casic.module.process.support.home;
|
||||
package cd.casic.module.process.support.version.service;
|
||||
|
||||
public interface PipelineVersionService {
|
||||
|
@ -0,0 +1,31 @@
|
||||
package cd.casic.module.process.support.version.service.impl;
|
||||
|
||||
import cd.casic.module.process.licence.licence.model.Version;
|
||||
import cd.casic.module.process.licence.licence.service.VersionService;
|
||||
import cd.casic.module.process.support.version.service.PipelineVersionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @ClassName PipelineVersionServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 18:58
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class PipelineVersionServiceImpl implements PipelineVersionService {
|
||||
|
||||
@Autowired
|
||||
VersionService versionServer;
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean isVip() {
|
||||
Version version = versionServer.getVersion();
|
||||
|
||||
Boolean expired = version.getExpired();
|
||||
// Integer release = version.getRelease();
|
||||
return !expired;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package cd.casic.module.process.support.webHook.model;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName PipelineVersionServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:00
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* 流水线webhook模型
|
||||
*/
|
||||
public class WebHook {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 流水线ID
|
||||
*/
|
||||
private String pipelineId;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
private String parameters;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package cd.casic.module.process.task.artifact.dao;
|
||||
|
||||
import cd.casic.module.process.task.artifact.dataobject.TaskArtifactDo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactDao
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:08
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
@Repository
|
||||
public class TaskArtifactDao {
|
||||
public String createProduct(TaskArtifactDo taskArtifactEntity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void deleteProduct(String productId) {
|
||||
}
|
||||
|
||||
public void updateProduct(TaskArtifactDo productEntity) {
|
||||
|
||||
}
|
||||
|
||||
public TaskArtifactDo findOneProduct(String artifactId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<TaskArtifactDo> findAllProduct() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<TaskArtifactDo> findAllProductList(List<String> idList) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package cd.casic.module.process.task.artifact.dataobject;
|
||||
|
||||
import cd.casic.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactDo
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:10
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "pip_task_artifact", autoResultMap = true)
|
||||
public class TaskArtifactDo extends BaseDO {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = -5333368911605592175L;
|
||||
|
||||
@TableId
|
||||
private String taskId;
|
||||
|
||||
private String artifactType;
|
||||
|
||||
private String version;
|
||||
|
||||
private String fileAddress;
|
||||
|
||||
private String putAddress;
|
||||
|
||||
private String authId;
|
||||
|
||||
private String rule;
|
||||
|
||||
private String dockerImage;
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package cd.casic.module.process.task.artifact.service;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactService
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:02
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.join.annototion.FindAll;
|
||||
import cd.casic.ci.commons.join.annototion.FindList;
|
||||
import cd.casic.ci.commons.join.annototion.FindOne;
|
||||
import cd.casic.ci.commons.join.annototion.JoinProvider;
|
||||
import cd.casic.module.process.task.artifact.model.TaskArtifact;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务推送制品服务接口
|
||||
*/
|
||||
@JoinProvider(model = TaskArtifact.class)
|
||||
public interface TaskArtifactService {
|
||||
|
||||
/**
|
||||
* 创建流水线推送制品
|
||||
* @param taskArtifact 流水线推送制品
|
||||
* @return 流水线推送制品id
|
||||
*/
|
||||
String createProduct(TaskArtifact taskArtifact);
|
||||
|
||||
/**
|
||||
* 删除流水线推送制品
|
||||
* @param productId 流水线推送制品id
|
||||
*/
|
||||
void deleteProduct(String productId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据配置id查询任务
|
||||
* @param taskId 配置id
|
||||
* @return 任务
|
||||
*/
|
||||
TaskArtifact findOneArtifactByAuth(String taskId);
|
||||
|
||||
|
||||
/**
|
||||
* 更新推送制品信息
|
||||
* @param taskArtifact 信息
|
||||
*/
|
||||
void updateProduct(TaskArtifact taskArtifact);
|
||||
|
||||
/**
|
||||
* 查询推送制品信息
|
||||
* @param artifactId id
|
||||
* @return 信息
|
||||
*/
|
||||
@FindOne
|
||||
TaskArtifact findOneProduct(String artifactId);
|
||||
|
||||
/**
|
||||
* 查询所有流水线推送制品
|
||||
* @return 流水线推送制品列表
|
||||
*/
|
||||
@FindAll
|
||||
List<TaskArtifact> findAllProduct();
|
||||
|
||||
|
||||
/**
|
||||
* 根据ID列表查询流水线推送制品
|
||||
* @param idList ID列表
|
||||
* @return 流水线推送制品列表
|
||||
*/
|
||||
@FindList
|
||||
List<TaskArtifact> findAllProductList(List<String> idList);
|
||||
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package cd.casic.module.process.task.artifact.service.impl;
|
||||
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthHost;
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.ci.commons.rpc.annototion.Exporter;
|
||||
import cd.casic.module.process.process.setting.AuthHostService;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.support.util.util.PipelineFinal;
|
||||
import cd.casic.module.process.task.artifact.dao.TaskArtifactDao;
|
||||
import cd.casic.module.process.task.artifact.dataobject.TaskArtifactDo;
|
||||
import cd.casic.module.process.task.artifact.model.TaskArtifact;
|
||||
import cd.casic.module.process.task.artifact.service.TaskArtifactService;
|
||||
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:34
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
@Service
|
||||
@Exporter
|
||||
public class TaskArtifactServiceImpl implements TaskArtifactService {
|
||||
|
||||
@Resource
|
||||
private TaskArtifactDao productDao;
|
||||
|
||||
@Resource
|
||||
private AuthThirdService thirdServer;
|
||||
|
||||
@Resource
|
||||
private AuthHostService hostServer;
|
||||
|
||||
/**
|
||||
* 创建流水线推送制品
|
||||
* @param taskArtifact 流水线推送制品
|
||||
* @return 流水线推送制品id
|
||||
*/
|
||||
@Override
|
||||
public String createProduct(TaskArtifact taskArtifact) {
|
||||
TaskArtifactDo taskArtifactEntity = BeanMapper.map(taskArtifact, TaskArtifactDo.class);
|
||||
return productDao.createProduct(taskArtifactEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置id查询任务
|
||||
* @return 任务
|
||||
*/
|
||||
@Override
|
||||
public TaskArtifact findOneArtifactByAuth(String taskId){
|
||||
|
||||
TaskArtifact artifact = findOneProduct(taskId);
|
||||
if (Objects.isNull(artifact)){
|
||||
return null;
|
||||
}
|
||||
String authId = artifact.getAuthId();
|
||||
if (Objects.isNull(authId)){
|
||||
return artifact;
|
||||
}
|
||||
String artifactType = artifact.getArtifactType();
|
||||
AuthThird authServer = thirdServer.findOneAuthServer(authId);
|
||||
artifact.setAuth(authServer);
|
||||
|
||||
if (artifactType.equals(PipelineFinal.TASK_UPLOAD_SSH)){
|
||||
AuthHost oneAuthHost = hostServer.findOneAuthHost(authId);
|
||||
artifact.setAuth(oneAuthHost);
|
||||
}
|
||||
return artifact;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流水线推送制品
|
||||
* @param ProductId 流水线推送制品id
|
||||
*/
|
||||
@Override
|
||||
public void deleteProduct(String ProductId) {
|
||||
productDao.deleteProduct(ProductId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新推送制品信息
|
||||
* @param taskArtifact 信息
|
||||
*/
|
||||
@Override
|
||||
public void updateProduct(TaskArtifact taskArtifact) {
|
||||
TaskArtifactDo productEntity = BeanMapper.map(taskArtifact, TaskArtifactDo.class);
|
||||
productDao.updateProduct(productEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询推送制品信息
|
||||
* @param artifactId id
|
||||
* @return 信息集合
|
||||
*/
|
||||
@Override
|
||||
public TaskArtifact findOneProduct(String artifactId) {
|
||||
TaskArtifactDo oneProduct = productDao.findOneProduct(artifactId);
|
||||
return BeanMapper.map(oneProduct, TaskArtifact.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有流水线推送制品
|
||||
* @return 流水线推送制品列表
|
||||
*/
|
||||
@Override
|
||||
public List<TaskArtifact> findAllProduct() {
|
||||
List<TaskArtifactDo> allProduct = productDao.findAllProduct();
|
||||
return BeanMapper.mapList(allProduct, TaskArtifact.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskArtifact> findAllProductList(List<String> idList) {
|
||||
List<TaskArtifactDo> allProductList = productDao.findAllProductList(idList);
|
||||
return BeanMapper.mapList(allProductList, TaskArtifact.class);
|
||||
}
|
||||
|
||||
private Object findAuth(String id){
|
||||
AuthThird oneAuthServer = thirdServer.findOneAuthServer(id);
|
||||
if (oneAuthServer != null){
|
||||
return oneAuthServer;
|
||||
}
|
||||
return hostServer.findOneAuthHost(id);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package cd.casic.module.process.task.artifact.service.impl;
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.support.util.util.PipelineRequestUtil;
|
||||
import cd.casic.module.process.task.artifact.model.XpackRepository;
|
||||
import cd.casic.module.process.task.artifact.model.XpackRepositoryQuery;
|
||||
import cd.casic.module.process.task.artifact.service.TaskArtifactXpackService;
|
||||
import cd.casic.module.process.task.code.service.impl.TaskCodeGittokServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:19
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class TaskArtifactXpackServiceImpl implements TaskArtifactXpackService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TaskCodeGittokServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
AuthThirdService authThirdService;
|
||||
|
||||
@Resource
|
||||
PipelineRequestUtil requestUtil;
|
||||
|
||||
|
||||
@Override
|
||||
public List<XpackRepository> findAllRepository(String authId){
|
||||
AuthThird authServer = authThirdService.findOneAuthServer(authId);
|
||||
|
||||
if (Objects.isNull(authServer)){
|
||||
return null;
|
||||
}
|
||||
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
XpackRepositoryQuery repositoryQuery = new XpackRepositoryQuery();
|
||||
repositoryQuery.setRepositoryType("local");
|
||||
try {
|
||||
HttpHeaders headers = requestUtil.initHeaders(MediaType.APPLICATION_JSON, new HashMap<>());
|
||||
String requestUrl = serverAddress+"/api/xpackRepository/findRepositoryList";
|
||||
return requestUtil.requestPostList(headers, requestUrl, repositoryQuery, XpackRepository.class);
|
||||
|
||||
} catch (Throwable throwable){
|
||||
String message = throwable.getMessage();
|
||||
logger.error(message);
|
||||
if (message.contains("未订阅")){
|
||||
throw new ApplicationException("当前企业未订阅GitPuk!");
|
||||
}
|
||||
if (throwable instanceof ApplicationException){
|
||||
throw new ApplicationException(message);
|
||||
}
|
||||
throw new ApplicationException("无法连接到:"+serverAddress);
|
||||
}
|
||||
}
|
||||
|
||||
public XpackRepository findRepository(String authId,String rpyId){
|
||||
AuthThird authServer = authThirdService.findOneAuthServer(authId);
|
||||
if (Objects.isNull(authServer) || Objects.isNull(rpyId)){
|
||||
return null;
|
||||
}
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
|
||||
try {
|
||||
HttpHeaders headers = requestUtil.initHeaders(MediaType.APPLICATION_JSON, new HashMap<>());
|
||||
String requestUrl = serverAddress+"/api/xpackRepository/findRepository";
|
||||
MultiValueMap<String, String> multiValueMap = new LinkedMultiValueMap<>();
|
||||
multiValueMap.add("id",rpyId);
|
||||
return requestUtil.requestPost(headers, requestUrl, multiValueMap, XpackRepository.class);
|
||||
|
||||
} catch (Throwable throwable){
|
||||
String message = throwable.getMessage();
|
||||
logger.error(message);
|
||||
if (throwable instanceof ApplicationException){
|
||||
throw new ApplicationException(message);
|
||||
}
|
||||
if (message.contains("未订阅")){
|
||||
throw new ApplicationException("当前企业未订阅GitPuk!");
|
||||
}
|
||||
throw new ApplicationException("无法连接到:"+serverAddress);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package cd.casic.module.process.task.build.dao;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:26
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.module.process.task.code.jpa.JpaTemplate;
|
||||
import cd.casic.module.process.task.build.dataobject.TaskBuildDo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class TaskBuildDao {
|
||||
|
||||
@Autowired
|
||||
JpaTemplate jpaTemplate;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param taskBuildDo build信息
|
||||
* @return buildId
|
||||
*/
|
||||
public String createBuild(TaskBuildDo taskBuildDo){
|
||||
return jpaTemplate.save(taskBuildDo,String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param buildId buildId
|
||||
*/
|
||||
public void deleteBuild(String buildId){
|
||||
jpaTemplate.delete(TaskBuildDo.class,buildId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新build
|
||||
* @param taskBuildDo 更新信息
|
||||
*/
|
||||
public void updateBuild(TaskBuildDo taskBuildDo){
|
||||
jpaTemplate.update(taskBuildDo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个build信息
|
||||
* @param buildId buildId
|
||||
* @return build信息
|
||||
*/
|
||||
public TaskBuildDo findOneBuild(String buildId){
|
||||
return jpaTemplate.findOne(TaskBuildDo.class,buildId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有build信息
|
||||
* @return build信息集合
|
||||
*/
|
||||
public List<TaskBuildDo> findAllBuild(){
|
||||
return jpaTemplate.findAll(TaskBuildDo.class);
|
||||
}
|
||||
|
||||
|
||||
public List<TaskBuildDo> findAllCodeList(List<String> idList){
|
||||
return jpaTemplate.findList(TaskBuildDo.class,idList);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package cd.casic.module.process.task.build.dao;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:46
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
import cd.casic.module.process.task.build.dataobject.TaskBuildProductDo;
|
||||
import cd.casic.module.process.task.build.model.TaskBuildProductQuery;
|
||||
import cd.casic.module.process.task.code.jpa.JpaTemplate;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class TaskBuildProductDao {
|
||||
|
||||
@Autowired
|
||||
JpaTemplate jpaTemplate;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param taskBuildProductEntity build信息
|
||||
* @return buildId
|
||||
*/
|
||||
public String createBuildProduct(TaskBuildProductDo taskBuildProductEntity){
|
||||
return jpaTemplate.save(taskBuildProductEntity,String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param buildId buildId
|
||||
*/
|
||||
public void deleteBuildProduct(String buildId){
|
||||
jpaTemplate.delete(TaskBuildProductDo.class,buildId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新build
|
||||
* @param taskBuildProductDo 更新信息
|
||||
*/
|
||||
public void updateBuildProduct(TaskBuildProductDo taskBuildProductDo){
|
||||
jpaTemplate.update(taskBuildProductDo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个build信息
|
||||
* @param buildId buildId
|
||||
* @return build信息
|
||||
*/
|
||||
public TaskBuildProductDo findOneBuildProduct(String buildId){
|
||||
return jpaTemplate.findOne(TaskBuildProductDo.class,buildId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有build信息
|
||||
* @return build信息集合
|
||||
*/
|
||||
public List<TaskBuildProductDo> findAllBuildProduct(){
|
||||
return jpaTemplate.findAll(TaskBuildProductDo.class);
|
||||
}
|
||||
|
||||
public List<TaskBuildProductDo> findBuildProductList(TaskBuildProductQuery taskBuildProductQuery){
|
||||
// QueryCondition queryCondition = QueryWrapper.createQuery(TaskBuildProductDo.class)
|
||||
// .eq("instanceId", taskBuildProductQuery.getInstanceId())
|
||||
// .eq("type", taskBuildProductQuery.getType())
|
||||
// .eq("key", taskBuildProductQuery.getKey())
|
||||
// .get();
|
||||
return jpaTemplate.findList(null, TaskBuildProductDo.class);
|
||||
}
|
||||
|
||||
public List<TaskBuildProductDo> findAllBuildProductList(List<String> idList){
|
||||
return jpaTemplate.findList(TaskBuildProductDo.class,idList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package cd.casic.module.process.task.build.dataobject;
|
||||
|
||||
import cd.casic.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:23
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "pip_task_build", autoResultMap = true)
|
||||
public class TaskBuildDo extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private String taskId;
|
||||
|
||||
//地址
|
||||
private String buildAddress;
|
||||
|
||||
//分支
|
||||
private String buildOrder;
|
||||
|
||||
private String productRule;
|
||||
|
||||
private String dockerName;
|
||||
|
||||
private String dockerVersion;
|
||||
|
||||
private String dockerFile;
|
||||
|
||||
private String dockerOrder;
|
||||
|
||||
// jdk版本
|
||||
private String toolJdk;
|
||||
|
||||
// maven版本
|
||||
private String toolMaven;
|
||||
|
||||
// npm版本
|
||||
private String toolNodejs;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package cd.casic.module.process.task.build.dataobject;
|
||||
|
||||
import cd.casic.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:24
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "pip_task_build_product", autoResultMap = true)
|
||||
public class TaskBuildProductDo extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
|
||||
private String instanceId;
|
||||
|
||||
//地址
|
||||
private String type;
|
||||
|
||||
|
||||
private String key;
|
||||
|
||||
private String value;
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package cd.casic.module.process.task.build.service;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:30
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import cd.casic.ci.commons.join.annototion.FindAll;
|
||||
import cd.casic.ci.commons.join.annototion.FindList;
|
||||
import cd.casic.ci.commons.join.annototion.FindOne;
|
||||
import cd.casic.ci.commons.join.annototion.JoinProvider;
|
||||
import cd.casic.module.process.task.build.model.TaskBuild;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 任务构建服务接口
|
||||
*/
|
||||
@JoinProvider(model = TaskBuild.class)
|
||||
public interface TaskBuildService {
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param TaskBuild build信息
|
||||
* @return buildId
|
||||
*/
|
||||
String createBuild(TaskBuild TaskBuild);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param buildId buildId
|
||||
*/
|
||||
void deleteBuild(String buildId);
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @param TaskBuild 更新信息
|
||||
*/
|
||||
void updateBuild(TaskBuild TaskBuild);
|
||||
|
||||
/**
|
||||
* 验证
|
||||
* @param taskType taskType
|
||||
* @param taskBuild object
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean buildValid(String taskType,TaskBuild taskBuild);
|
||||
|
||||
|
||||
/**
|
||||
* 根据配置id查询任务
|
||||
* @param configId 配置id
|
||||
* @return 任务
|
||||
*/
|
||||
TaskBuild findBuildByAuth(String configId);
|
||||
|
||||
|
||||
/**
|
||||
* 查询单个信息
|
||||
* @param buildId buildId
|
||||
* @return build信息
|
||||
*/
|
||||
@FindOne
|
||||
TaskBuild findOneBuild(String buildId);
|
||||
|
||||
/**
|
||||
* 查询所有信息
|
||||
* @return build信息集合
|
||||
*/
|
||||
@FindAll
|
||||
List<TaskBuild> findAllBuild();
|
||||
|
||||
/**
|
||||
* 根据ID列表查询构建
|
||||
* @param idList ID列表
|
||||
* @return 构建列表
|
||||
*/
|
||||
@FindList
|
||||
List<TaskBuild> findAllBuildList(List<String> idList);
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package cd.casic.module.process.task.build.service.impl;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:35
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.rpc.annototion.Exporter;
|
||||
import cd.casic.module.process.task.build.dao.TaskBuildProductDao;
|
||||
import cd.casic.module.process.task.build.dataobject.TaskBuildProductDo;
|
||||
import cd.casic.module.process.task.build.model.TaskBuildProduct;
|
||||
import cd.casic.module.process.task.build.model.TaskBuildProductQuery;
|
||||
import cd.casic.module.process.task.build.service.TaskBuildProductService;
|
||||
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Exporter
|
||||
public class TaskBuildProductServiceImpl implements TaskBuildProductService {
|
||||
|
||||
@Resource
|
||||
TaskBuildProductDao taskBuildProductDao;
|
||||
|
||||
|
||||
@Override
|
||||
public String createBuildProduct(TaskBuildProduct taskBuildProduct) {
|
||||
TaskBuildProductDo taskBuildProductDo = BeanMapper.map(taskBuildProduct, TaskBuildProductDo.class);
|
||||
return taskBuildProductDao.createBuildProduct(taskBuildProductDo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBuildProduct(TaskBuildProduct taskBuildProduct) {
|
||||
TaskBuildProductDo taskBuildProductDo = BeanMapper.map(taskBuildProduct, TaskBuildProductDo.class);
|
||||
taskBuildProductDao.updateBuildProduct(taskBuildProductDo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBuildProduct(String id) {
|
||||
taskBuildProductDao.deleteBuildProduct(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskBuildProduct findOneBuildProduct(String id) {
|
||||
TaskBuildProductDo buildProductEntity = taskBuildProductDao.findOneBuildProduct(id);
|
||||
return BeanMapper.map(buildProductEntity, TaskBuildProduct.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskBuildProduct> findAllBuildProduct() {
|
||||
List<TaskBuildProductDo> allBuildProduct = taskBuildProductDao.findAllBuildProduct();
|
||||
if (allBuildProduct == null || allBuildProduct.isEmpty()){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return BeanMapper.mapList(allBuildProduct, TaskBuildProduct.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskBuildProduct> findBuildProductList(TaskBuildProductQuery taskBuildProductQuery) {
|
||||
List<TaskBuildProductDo> allBuildProduct = taskBuildProductDao.findBuildProductList(taskBuildProductQuery);
|
||||
if (allBuildProduct == null || allBuildProduct.isEmpty()){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return BeanMapper.mapList(allBuildProduct, TaskBuildProduct.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String replace(String instanceId,String strings){
|
||||
TaskBuildProductQuery taskBuildProductQuery = new TaskBuildProductQuery();
|
||||
taskBuildProductQuery.setInstanceId(instanceId);
|
||||
List<TaskBuildProduct> buildProductList = findBuildProductList(taskBuildProductQuery);
|
||||
|
||||
if (buildProductList.isEmpty()){
|
||||
return strings;
|
||||
}
|
||||
|
||||
for (TaskBuildProduct taskBuildProduct : buildProductList) {
|
||||
|
||||
LinkedHashMap<String,Object> linkedHashMap = JSONObject.parseObject(taskBuildProduct.getValue(), LinkedHashMap.class);
|
||||
for (Map.Entry<String, Object> entry : linkedHashMap.entrySet()) {
|
||||
String value = (String)entry.getValue();
|
||||
String key = entry.getKey();
|
||||
strings = strings.replaceAll("\\$\\{" + key + "}",value);
|
||||
strings = strings.replaceAll(key,value);
|
||||
}
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package cd.casic.module.process.task.build.service.impl;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:40
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.rpc.annototion.Exporter;
|
||||
import cd.casic.module.process.support.util.util.PipelineFinal;
|
||||
import cd.casic.module.process.task.build.dao.TaskBuildDao;
|
||||
import cd.casic.module.process.task.build.dataobject.TaskBuildDo;
|
||||
import cd.casic.module.process.task.build.model.TaskBuild;
|
||||
import cd.casic.module.process.task.build.service.TaskBuildService;
|
||||
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@Service
|
||||
@Exporter
|
||||
public class TaskBuildServiceImpl implements TaskBuildService {
|
||||
|
||||
@Resource
|
||||
TaskBuildDao taskBuildDao;
|
||||
|
||||
//创建
|
||||
@Override
|
||||
public String createBuild(TaskBuild taskBuild) {
|
||||
return taskBuildDao.createBuild(BeanMapper.map(taskBuild, TaskBuildDo.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean buildValid(String taskType,TaskBuild build){
|
||||
if (taskType.equals(PipelineFinal.TASK_BUILD_DOCKER)){
|
||||
return !StringUtils.isEmpty(build.getDockerFile());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置id查询任务
|
||||
* @param authId 配置id
|
||||
* @return 任务
|
||||
*/
|
||||
@Override
|
||||
public TaskBuild findBuildByAuth(String authId){
|
||||
|
||||
TaskBuild build = findOneBuild(authId);
|
||||
if (Objects.isNull(build.getDockerVersion())){
|
||||
build.setDockerVersion("latest");
|
||||
}
|
||||
return build;
|
||||
}
|
||||
|
||||
//删除
|
||||
@Override
|
||||
public void deleteBuild(String buildId) {
|
||||
taskBuildDao.deleteBuild(buildId);
|
||||
}
|
||||
|
||||
//修改
|
||||
@Override
|
||||
public void updateBuild(TaskBuild taskBuild) {
|
||||
taskBuildDao.updateBuild(BeanMapper.map(taskBuild, TaskBuildDo.class));
|
||||
}
|
||||
|
||||
//查询单个
|
||||
@Override
|
||||
public TaskBuild findOneBuild(String buildId) {
|
||||
return BeanMapper.map(taskBuildDao.findOneBuild(buildId), TaskBuild.class);
|
||||
}
|
||||
|
||||
//查询所有
|
||||
@Override
|
||||
public List<TaskBuild> findAllBuild() {
|
||||
return BeanMapper.mapList(taskBuildDao.findAllBuild(), TaskBuild.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskBuild> findAllBuildList(List<String> idList) {
|
||||
return BeanMapper.mapList(taskBuildDao.findAllCodeList(idList), TaskBuild.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package cd.casic.module.process.task.code.controller;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:25
|
||||
* @Version 1.0
|
||||
*/
|
||||
import cd.casic.ci.commons.bean.utils.Result;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGitHubService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @pi.protocol: http
|
||||
* @pi.groupName: 流水线集成github控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/code/third/github")
|
||||
public class PipelineCodeGitHubController {
|
||||
|
||||
@Resource
|
||||
TaskCodeGitHubService gitHubService;
|
||||
|
||||
/**
|
||||
* @pi.name:获取xcode所有仓库
|
||||
* @pi.url:/code/third/github/findStoreHouseList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
*/
|
||||
@RequestMapping(path="/findStoreHouseList",method = RequestMethod.POST)
|
||||
public Result< List<ThirdHouse>> findAllRepository(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdHouse> allRepository = gitHubService.findStoreHouseList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @pi.name:获取仓库分支信息
|
||||
* @pi.url:/code/third/github/findHouseBranchList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
* @pi.param: name=rpyId;dataType=string;value=rpyId;
|
||||
*/
|
||||
@RequestMapping(path="/findHouseBranchList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdBranch>> findHouseBranchList(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdBranch> allRepository = gitHubService.findStoreBranchList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package cd.casic.module.process.task.code.controller;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:25
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.utils.Result;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGitLabService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @pi.protocol: http
|
||||
* @pi.groupName: 流水线集成gitlab控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/code/third/gitlab")
|
||||
public class PipelineCodeGitLabController {
|
||||
|
||||
@Resource
|
||||
TaskCodeGitLabService gitLabService;
|
||||
|
||||
/**
|
||||
* @pi.name:获取xcode所有仓库
|
||||
* @pi.url:/code/third/gitlab/findStoreHouseList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
*/
|
||||
@RequestMapping(path="/findStoreHouseList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdHouse>> findStoreHouseList(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdHouse> allRepository = gitLabService.findStoreHouseList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @pi.name:获取仓库分支信息
|
||||
* @pi.url:/code/third/gitlab/findHouseBranchList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
* @pi.param: name=rpyId;dataType=string;value=rpyId;
|
||||
*/
|
||||
@RequestMapping(path="/findHouseBranchList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdBranch>> findHouseBranchList(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdBranch> allRepository = gitLabService.findStoreBranchList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package cd.casic.module.process.task.code.controller;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:25
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.utils.Result;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGiteeService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @pi.protocol: http
|
||||
* @pi.groupName: 流水线集成gitee控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/code/third/gitee")
|
||||
public class PipelineCodeGiteeController {
|
||||
|
||||
@Resource
|
||||
TaskCodeGiteeService giteeService;
|
||||
|
||||
/**
|
||||
* @pi.name:获取xcode所有仓库
|
||||
* @pi.url:/code/third/gitee/findStoreHouseList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
*/
|
||||
@RequestMapping(path="/findStoreHouseList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdHouse>> findAllRepository(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdHouse> allRepository = giteeService.findStoreHouseList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @pi.name:获取仓库分支信息
|
||||
* @pi.url:/code/third/gitee/findHouseBranchList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
* @pi.param: name=rpyId;dataType=string;value=rpyId;
|
||||
*/
|
||||
@RequestMapping(path="/findHouseBranchList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdBranch>> findHouseBranchList(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdBranch> allRepository = giteeService.findStoreBranchList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package cd.casic.module.process.task.code.controller;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:25
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.utils.Result;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGittokService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @pi.protocol: http
|
||||
* @pi.groupName: 流水线集成Xcode控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/code/third/gittok")
|
||||
public class PipelineCodeGittokController {
|
||||
|
||||
@Resource
|
||||
TaskCodeGittokService gittokService;
|
||||
|
||||
/**
|
||||
* @pi.name:获取xcode所有仓库
|
||||
* @pi.url:/xcodeAuthorize/findAllRepository
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
*/
|
||||
@RequestMapping(path="/findStoreHouseList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdHouse>> findStoreHouseList(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdHouse> allRepository = gittokService.findStoreHouseList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @pi.name:获取仓库分支信息
|
||||
* @pi.url:/xcodeAuthorize/findAllBranch
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
* @pi.param: name=rpyId;dataType=string;value=rpyId;
|
||||
*/
|
||||
@RequestMapping(path="/findHouseBranchList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdBranch>> findHouseBranchList(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdBranch> allRepository = gittokService.findHouseBranchList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package cd.casic.module.process.task.code.controller;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:25
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.utils.Result;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.service.TaskCodePriGitLabService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @pi.protocol: http
|
||||
* @pi.groupName: 流水线集成gitlab控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/code/third/pri/v4/gitlab")
|
||||
public class PipelineCodePriGitLabController {
|
||||
|
||||
@Resource
|
||||
TaskCodePriGitLabService priGitLabService;
|
||||
|
||||
/**
|
||||
* @pi.name:获取自建GitLab所有仓库
|
||||
* @pi.url:/code/third/gitlab/findStoreHouseList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
*/
|
||||
@RequestMapping(path="/findStoreHouseList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdHouse>> findStoreHouseList(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdHouse> allRepository = priGitLabService.findStoreHouseList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @pi.name:获取仓库分支信息
|
||||
* @pi.url:/code/third/gitlab/findHouseBranchList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=authId;dataType=string;value=authId;
|
||||
* @pi.param: name=rpyId;dataType=string;value=rpyId;
|
||||
*/
|
||||
@RequestMapping(path="/findHouseBranchList",method = RequestMethod.POST)
|
||||
public Result<List<ThirdBranch>> findHouseBranchList(@RequestBody @Valid @NotNull ThirdQuery thirdQuery){
|
||||
|
||||
List<ThirdBranch> allRepository = priGitLabService.findStoreBranchList(thirdQuery);
|
||||
|
||||
return Result.ok(allRepository);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package cd.casic.module.process.task.code.dao;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:25
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.module.process.task.code.jpa.JpaTemplate;
|
||||
import cd.casic.module.process.task.code.dataobject.TaskCodeDo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class TaskCodeDao {
|
||||
|
||||
@Resource
|
||||
JpaTemplate jpaTemplate;
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param taskCodeDo code信息
|
||||
* @return codeId
|
||||
*/
|
||||
public String createCode(TaskCodeDo taskCodeDo){
|
||||
return jpaTemplate.save(taskCodeDo,String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除code
|
||||
* @param codeId codeId
|
||||
*/
|
||||
public void deleteCode(String codeId){
|
||||
jpaTemplate.delete(TaskCodeDo.class,codeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新code
|
||||
* @param taskCodeDo 更新信息
|
||||
*/
|
||||
public void updateCode(TaskCodeDo taskCodeDo){
|
||||
jpaTemplate.update(taskCodeDo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个code信息
|
||||
* @param codeId codeId
|
||||
* @return code信息
|
||||
*/
|
||||
public TaskCodeDo findOneCode(String codeId){
|
||||
return jpaTemplate.findOne(TaskCodeDo.class,codeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有code信息
|
||||
* @return code信息集合
|
||||
*/
|
||||
public List<TaskCodeDo> findAllCode(){
|
||||
return jpaTemplate.findAll(TaskCodeDo.class);
|
||||
}
|
||||
|
||||
public List<TaskCodeDo> findAllCodeList(List<String> idList){
|
||||
return jpaTemplate.findList(TaskCodeDo.class,idList);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package cd.casic.module.process.task.code.dataobject;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:25
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "pip_task_code", autoResultMap = true)
|
||||
public class TaskCodeDo extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private String taskId;
|
||||
|
||||
//地址名
|
||||
private String codeName;
|
||||
|
||||
//地址
|
||||
private String codeAddress;
|
||||
|
||||
//分支
|
||||
private String codeBranch;
|
||||
|
||||
//凭证信息
|
||||
private String authId;
|
||||
|
||||
private String svnFile;
|
||||
|
||||
private String xcodeId;
|
||||
|
||||
private String branchId;
|
||||
|
||||
private String houseId;
|
||||
|
||||
private String toolGit;
|
||||
|
||||
private String toolSvn;
|
||||
|
||||
// 认证类型
|
||||
private String authType;
|
||||
|
||||
// 用户名
|
||||
private String username;
|
||||
|
||||
// 密码
|
||||
private String password;
|
||||
|
||||
// 私钥
|
||||
private String priKey;
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package cd.casic.module.process.task.code.jpa;
|
||||
|
||||
/**
|
||||
* @ClassName JpaOperation
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 21:28
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface JpaOperation {
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package cd.casic.module.process.task.code.jpa;
|
||||
|
||||
import cd.casic.ci.commons.bean.commons.Pagination;
|
||||
import cd.casic.ci.commons.bean.jdbc.JdbcTemplate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName JpaTemplate
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 21:27
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class JpaTemplate implements JpaOperation {
|
||||
private static Logger logger = LoggerFactory.getLogger(JpaTemplate.class);
|
||||
private DataSource dataSource;
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
public JpaTemplate() {
|
||||
}
|
||||
|
||||
public JpaTemplate(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
public JdbcTemplate getJdbcTemplate() {
|
||||
return this.jdbcTemplate;
|
||||
}
|
||||
|
||||
public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
|
||||
return this.namedParameterJdbcTemplate;
|
||||
}
|
||||
|
||||
|
||||
public <T, ID> ID save(T entity, Class<ID> idClass) throws DataAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> void update(T entity) throws DataAccessException {
|
||||
}
|
||||
|
||||
|
||||
public <T, ID> void delete(Class<T> entityClass, ID id) throws DataAccessException {
|
||||
}
|
||||
|
||||
public <T> List<T> findAll(Class<T> entityClass) throws DataAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T, ID> T findOne(Class<T> entityClass, ID id) throws DataAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T, ID> List<T> findList(Class<T> entityClass, List<ID> idList) throws DataAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> List<T> findList(Object queryObject, Class<T> resultType) throws DataAccessException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T> Pagination<T> findPage(Object queryObject, Class<T> resultType) throws DataAccessException {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cd.casic.module.process.task.code.model;
|
||||
|
||||
|
||||
import cd.casic.ci.commons.bean.process.setting.Scm;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@ -49,4 +50,23 @@ public class TaskCode {
|
||||
|
||||
private String instanceId;
|
||||
|
||||
// Git版本
|
||||
private Scm toolGit;
|
||||
|
||||
// svn版本
|
||||
private Scm toolSvn;
|
||||
|
||||
|
||||
// 认证类型
|
||||
private String authType;
|
||||
|
||||
// 用户名
|
||||
private String username;
|
||||
|
||||
// 密码
|
||||
private String password;
|
||||
|
||||
// 私钥
|
||||
private String priKey;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package cd.casic.module.process.task.code.service;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.model.ThirdUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TaskCodeGitHubService {
|
||||
|
||||
/**
|
||||
* 获取AccessToken的授权用户信息
|
||||
* @param thirdQuery 凭证
|
||||
* @return 授权用户信息
|
||||
*/
|
||||
ThirdUser findAuthUser(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取凭证认证的仓库列表
|
||||
* @param thirdQuery 凭证
|
||||
* @return 仓库列表
|
||||
*/
|
||||
List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取指定仓库信息
|
||||
* @param thirdQuery 仓库
|
||||
* @return 仓库信息
|
||||
*/
|
||||
ThirdHouse findStoreHouse(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取凭证认证的仓库分支列表
|
||||
* @param thirdQuery 凭证
|
||||
* @return 分支列表
|
||||
*/
|
||||
List<ThirdBranch> findStoreBranchList(ThirdQuery thirdQuery);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package cd.casic.module.process.task.code.service;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.model.ThirdUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TaskCodeGitLabService {
|
||||
|
||||
/**
|
||||
* 获取AccessToken的授权用户信息
|
||||
* @param thirdQuery 凭证
|
||||
* @return 授权用户信息
|
||||
*/
|
||||
ThirdUser findAuthUser(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取凭证认证的仓库列表
|
||||
* @param thirdQuery 凭证
|
||||
* @return 仓库列表
|
||||
*/
|
||||
List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取指定仓库信息
|
||||
* @param thirdQuery 仓库
|
||||
* @return 仓库信息
|
||||
*/
|
||||
ThirdHouse findStoreHouse(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取凭证认证的仓库分支列表
|
||||
* @param thirdQuery 凭证
|
||||
* @return 分支列表
|
||||
*/
|
||||
List<ThirdBranch> findStoreBranchList(ThirdQuery thirdQuery);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package cd.casic.module.process.task.code.service;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.model.ThirdUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TaskCodeGiteeService {
|
||||
|
||||
/**
|
||||
* 获取AccessToken的授权用户信息
|
||||
* @param thirdQuery 凭证
|
||||
* @return 授权用户信息
|
||||
*/
|
||||
ThirdUser findAuthUser(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取凭证认证的仓库列表
|
||||
* @param thirdQuery 凭证
|
||||
* @return 仓库列表
|
||||
*/
|
||||
List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery);
|
||||
|
||||
|
||||
/**
|
||||
* 获取指定仓库信息
|
||||
* @param thirdQuery 仓库
|
||||
* @return 仓库信息
|
||||
*/
|
||||
ThirdHouse findStoreHouse(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取凭证认证的仓库分支列表
|
||||
* @param thirdQuery 凭证
|
||||
* @return 分支列表
|
||||
*/
|
||||
List<ThirdBranch> findStoreBranchList(ThirdQuery thirdQuery);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package cd.casic.module.process.task.code.service;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.model.ThirdUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TaskCodePriGitLabService {
|
||||
|
||||
/**
|
||||
* 获取AccessToken的授权用户信息
|
||||
* @param thirdQuery 凭证
|
||||
* @return 授权用户信息
|
||||
*/
|
||||
ThirdUser findAuthUser(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取凭证认证的仓库列表
|
||||
* @param thirdQuery 凭证
|
||||
* @return 仓库列表
|
||||
*/
|
||||
List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取指定仓库信息
|
||||
* @param thirdQuery 仓库
|
||||
* @return 仓库信息
|
||||
*/
|
||||
ThirdHouse findStoreHouse(ThirdQuery thirdQuery);
|
||||
|
||||
/**
|
||||
* 获取凭证认证的仓库分支列表
|
||||
* @param thirdQuery 凭证
|
||||
* @return 分支列表
|
||||
*/
|
||||
List<ThirdBranch> findStoreBranchList(ThirdQuery thirdQuery);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package cd.casic.module.process.task.code.service;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.join.annototion.FindAll;
|
||||
import cd.casic.ci.commons.join.annototion.FindList;
|
||||
import cd.casic.ci.commons.join.annototion.FindOne;
|
||||
import cd.casic.ci.commons.join.annototion.JoinProvider;
|
||||
import cd.casic.module.process.task.code.model.TaskCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 源码服务接口
|
||||
*/
|
||||
@JoinProvider(model = TaskCode.class)
|
||||
public interface TaskCodeService {
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param taskCode code信息
|
||||
* @return codeId
|
||||
*/
|
||||
String createCode(TaskCode taskCode);
|
||||
|
||||
/**
|
||||
* 根据配置id查询任务
|
||||
* @param taskId 配置id
|
||||
* @return 任务
|
||||
*/
|
||||
TaskCode findCodeByAuth(String taskId);
|
||||
|
||||
|
||||
/**
|
||||
* 验证
|
||||
* @param taskType 任务类型
|
||||
* @param code object
|
||||
* @return 是否验证通过
|
||||
*/
|
||||
Boolean codeValid(String taskType,TaskCode code);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param codeId codeId
|
||||
*/
|
||||
void deleteCode(String codeId);
|
||||
|
||||
/**
|
||||
* 更新
|
||||
* @param taskCode 更新信息
|
||||
*/
|
||||
void updateCode(TaskCode taskCode);
|
||||
|
||||
|
||||
void updateOneCode(TaskCode taskCode);
|
||||
|
||||
/**
|
||||
* 查询单个信息
|
||||
* @param codeId codeId
|
||||
* @return code信息
|
||||
*/
|
||||
@FindOne
|
||||
TaskCode findOneCode(String codeId);
|
||||
|
||||
/**
|
||||
* 查询所有信息
|
||||
* @return code信息集合
|
||||
*/
|
||||
@FindAll
|
||||
List<TaskCode> findAllCode();
|
||||
|
||||
|
||||
@FindList
|
||||
List<TaskCode> findAllCodeList(List<String> idList);
|
||||
|
||||
}
|
@ -0,0 +1,258 @@
|
||||
package cd.casic.module.process.task.code.service.impl;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:12
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.exception.SystemException;
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.model.ThirdUser;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGitHubService;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class TaskCodeGitHubServiceImpl implements TaskCodeGitHubService {
|
||||
|
||||
|
||||
@Resource
|
||||
AuthThirdService authThirdService;
|
||||
|
||||
/**
|
||||
* 获取accessToken
|
||||
* @param authId 认证ID
|
||||
* @return 凭证
|
||||
*/
|
||||
private String findAccessToken(String authId){
|
||||
AuthThird authServer = authThirdService.findOneAuthServer(authId);
|
||||
if (Objects.isNull(authServer)){
|
||||
throw new ApplicationException("没有查询到当前凭证授权码!");
|
||||
}
|
||||
return authServer.getAccessToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery){
|
||||
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
List<ThirdHouse> houseList = new ArrayList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = String.format("https://api.github.com/user/repos?page=%s&per_page=%s",
|
||||
thirdQuery.getPage(), thirdQuery.getPageNumber());
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", "application/vnd.github.v3+json");
|
||||
headers.set("Authorization", "token"+" "+ accessToken);
|
||||
headers.set("X-GitHub-Api-Version", "2022-11-28");
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取仓库信息失败,获取信息为空!");
|
||||
}
|
||||
JSONArray projectList = JSONObject.parseArray(body);
|
||||
for (Object o : projectList) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(o));
|
||||
String id = jsonObject.getString("id");
|
||||
String name = jsonObject.getString("name");
|
||||
String nameSpace = jsonObject.getString("full_name");
|
||||
String sshUrl = jsonObject.getString("ssh_url_to_repo");
|
||||
String webUrl = jsonObject.getString("clone_url");
|
||||
String defaultBranch = jsonObject.getString("default_branch");
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(name);
|
||||
thirdHouse.setNameWithSpace(nameSpace);
|
||||
thirdHouse.setPathWithSpace(nameSpace);
|
||||
thirdHouse.setHouseSshUrl(sshUrl);
|
||||
thirdHouse.setHouseWebUrl(webUrl);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
houseList.add(thirdHouse);
|
||||
}
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
return houseList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdHouse findStoreHouse(ThirdQuery thirdQuery) {
|
||||
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
String[] split = thirdQuery.getHouseId().split("/");
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = String.format("https://api.github.com/repos/%s/%s", split[0],split[1]);
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", "application/vnd.github.v3+json");
|
||||
headers.set("Authorization", "token"+" "+ accessToken);
|
||||
headers.set("X-GitHub-Api-Version", "2022-11-28");
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取仓库信息失败,获取信息为空!");
|
||||
}
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
String id = jsonObject.getString("id");
|
||||
String name = jsonObject.getString("name");
|
||||
String nameSpace = jsonObject.getString("full_name");
|
||||
String sshUrl = jsonObject.getString("ssh_url_to_repo");
|
||||
String webUrl = jsonObject.getString("clone_url");
|
||||
String defaultBranch = jsonObject.getString("default_branch");
|
||||
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(name);
|
||||
thirdHouse.setNameWithSpace(nameSpace);
|
||||
thirdHouse.setPathWithSpace(nameSpace);
|
||||
thirdHouse.setHouseSshUrl(sshUrl);
|
||||
thirdHouse.setHouseWebUrl(webUrl);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
|
||||
return thirdHouse;
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdUser findAuthUser(ThirdQuery thirdQuery){
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = "https://api.github.com/user";
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", "application/vnd.github.v3+json");
|
||||
headers.set("Authorization", "token"+" "+ accessToken);
|
||||
headers.set("X-GitHub-Api-Version", "2022-11-28");
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
String id = jsonObject.getString("id");
|
||||
String login = jsonObject.getString("login");
|
||||
String name = jsonObject.getString("name");
|
||||
String avatar = jsonObject.getString("avatar_url");
|
||||
ThirdUser thirdUser = new ThirdUser();
|
||||
thirdUser.setId(id);
|
||||
thirdUser.setName(name);
|
||||
thirdUser.setPath(login);
|
||||
thirdUser.setHead(avatar);
|
||||
return thirdUser;
|
||||
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdBranch> findStoreBranchList(ThirdQuery thirdQuery){
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
String[] split = thirdQuery.getHouseId().split("/");
|
||||
List<ThirdBranch> branchList= new ArrayList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = String.format("https://api.github.com/repos/%s/%s/branches?page=%s&per_page=%s",
|
||||
split[0],split[1], thirdQuery.getPage(), thirdQuery.getPageNumber());
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", "application/vnd.github.v3+json");
|
||||
headers.set("Authorization", "token"+" "+ accessToken);
|
||||
headers.set("X-GitHub-Api-Version", "2022-11-28");
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取分支信息失败,获取信息为空!");
|
||||
}
|
||||
JSONArray projectList = JSONObject.parseArray(body);
|
||||
for (Object o : projectList) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(o));
|
||||
String name = jsonObject.getString("name");
|
||||
Boolean idProtected = jsonObject.getBoolean("protected");
|
||||
ThirdBranch thirdBranch = new ThirdBranch();
|
||||
thirdBranch.setId(name);
|
||||
thirdBranch.setName(name);
|
||||
thirdBranch.setIsProtected(idProtected);
|
||||
thirdBranch.setIsProtected(false);
|
||||
branchList.add(thirdBranch);
|
||||
}
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
return branchList;
|
||||
}
|
||||
|
||||
private void findGitlabErrorRequest(int code){
|
||||
switch (code){
|
||||
case 401 -> { throw new ApplicationException("令牌无效或已过期 !");}
|
||||
case 403 -> { throw new ApplicationException("令牌权限不足!");}
|
||||
case 404 -> { throw new ApplicationException("请求失败,接口不存在!");}
|
||||
case 405 -> { throw new ApplicationException("不支持该请求!");}
|
||||
case 429 -> { throw new ApplicationException("请求次数过多!");}
|
||||
case 503 -> { throw new ApplicationException("服务器暂时超载,无法处理该请求!");}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,257 @@
|
||||
package cd.casic.module.process.task.code.service.impl;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:13
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.exception.SystemException;
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.model.ThirdUser;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGitLabService;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class TaskCodeGitLabServiceImpl implements TaskCodeGitLabService {
|
||||
|
||||
@Resource
|
||||
AuthThirdService authThirdService;
|
||||
|
||||
/**
|
||||
* 获取accessToken
|
||||
* @param authId 认证ID
|
||||
* @return 凭证
|
||||
*/
|
||||
private String findAccessToken(String authId){
|
||||
AuthThird authServer = authThirdService.findOneAuthServer(authId);
|
||||
if (Objects.isNull(authServer)){
|
||||
throw new ApplicationException("没有查询到当前凭证授权码!");
|
||||
}
|
||||
return authServer.getAccessToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery){
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
List<ThirdHouse> houseList = new ArrayList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = String.format("https://gitlab.com/api/v4/projects?min_access_level=10&simple=true&page=%s&per_page=%s",
|
||||
thirdQuery.getPage(),thirdQuery.getPageNumber());
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", "Bearer"+" "+accessToken);
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取分支信息失败,获取信息为空!");
|
||||
}
|
||||
JSONArray projectList = JSONObject.parseArray(body);
|
||||
for (Object o : projectList) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(o));
|
||||
String id = jsonObject.getString("id");
|
||||
String name = jsonObject.getString("name");
|
||||
String path = jsonObject.getString("path");
|
||||
String nameSpace = jsonObject.getString("name_with_namespace");
|
||||
String pathSpace = jsonObject.getString("path_with_namespace");
|
||||
String sshUrl = jsonObject.getString("ssh_url_to_repo");
|
||||
String webUrl = jsonObject.getString("http_url_to_repo");
|
||||
String defaultBranch = jsonObject.getString("default_branch");
|
||||
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(name);
|
||||
thirdHouse.setNameWithSpace(nameSpace);
|
||||
thirdHouse.setPathWithSpace(nameSpace);
|
||||
thirdHouse.setHouseSshUrl(sshUrl);
|
||||
thirdHouse.setHouseWebUrl(webUrl);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
houseList.add(thirdHouse);
|
||||
}
|
||||
}catch (HttpClientErrorException e) {
|
||||
// if (Objects.requireNonNull(e.getMessage()).contains("Token is expired")){
|
||||
// throw new SystemException("令牌已过期!");
|
||||
// }
|
||||
// if (e.getMessage().contains("Unauthorized")){
|
||||
// throw new SystemException("令牌认证失败!");
|
||||
// }
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
return houseList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdHouse findStoreHouse(ThirdQuery thirdQuery) {
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = String.format("https://gitlab.com/api/v4/projects/%s",thirdQuery.getHouseId());
|
||||
ResponseEntity<String> forEntity;
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", "Bearer"+" "+accessToken);
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取仓库信息失败,获取信息为空!");
|
||||
}
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
String id = jsonObject.getString("id");
|
||||
String name = jsonObject.getString("name");
|
||||
String path = jsonObject.getString("path");
|
||||
String nameSpace = jsonObject.getString("name_with_namespace");
|
||||
String pathSpace = jsonObject.getString("path_with_namespace");
|
||||
String sshUrl = jsonObject.getString("ssh_url_to_repo");
|
||||
String webUrl = jsonObject.getString("http_url_to_repo");
|
||||
String defaultBranch = jsonObject.getString("default_branch");
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(name);
|
||||
thirdHouse.setNameWithSpace(nameSpace);
|
||||
thirdHouse.setPathWithSpace(nameSpace);
|
||||
thirdHouse.setHouseSshUrl(sshUrl);
|
||||
thirdHouse.setHouseWebUrl(webUrl);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
return thirdHouse;
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdUser findAuthUser(ThirdQuery thirdQuery){
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = "https://gitlab.com/api/v4/user";
|
||||
ResponseEntity<String> forEntity;
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", "Bearer"+" "+accessToken);
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
String id = jsonObject.getString("id");
|
||||
String login = jsonObject.getString("username");
|
||||
String name = jsonObject.getString("name");
|
||||
String avatar = jsonObject.getString("avatar_url");
|
||||
ThirdUser thirdUser = new ThirdUser();
|
||||
thirdUser.setId(id);
|
||||
thirdUser.setName(name);
|
||||
thirdUser.setPath(login);
|
||||
thirdUser.setHead(avatar);
|
||||
return thirdUser;
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdBranch> findStoreBranchList(ThirdQuery thirdQuery){
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
List<ThirdBranch> branchList= new ArrayList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = String.format("https://gitlab.com/api/v4/projects/%s/repository/branches",thirdQuery.getHouseId());
|
||||
ResponseEntity<String> forEntity;
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", "Bearer"+" "+accessToken);
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取分支信息失败,获取信息为空!");
|
||||
}
|
||||
JSONArray projectList = JSONObject.parseArray(body);
|
||||
for (Object o : projectList) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(o));
|
||||
String id = jsonObject.getString("commit");
|
||||
String name = jsonObject.getString("name");
|
||||
Boolean isDefault = jsonObject.getBoolean("default");
|
||||
Boolean idProtected = jsonObject.getBoolean("protected");
|
||||
ThirdBranch thirdBranch = new ThirdBranch();
|
||||
thirdBranch.setId(name);
|
||||
thirdBranch.setName(name);
|
||||
thirdBranch.setIsProtected(idProtected);
|
||||
thirdBranch.setIsProtected(false);
|
||||
branchList.add(thirdBranch);
|
||||
}
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
return branchList;
|
||||
}
|
||||
|
||||
private void findGitlabErrorRequest(int code){
|
||||
switch (code){
|
||||
case 401 -> { throw new ApplicationException("令牌无效或已过期 !");}
|
||||
case 403 -> { throw new ApplicationException("令牌权限不足!");}
|
||||
case 404 -> { throw new ApplicationException("请求失败,接口不存在!");}
|
||||
case 405 -> { throw new ApplicationException("不支持该请求!");}
|
||||
case 429 -> { throw new ApplicationException("请求次数过多!");}
|
||||
case 503 -> { throw new ApplicationException("服务器暂时超载,无法处理该请求!");}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,260 @@
|
||||
package cd.casic.module.process.task.code.service.impl;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:10
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.exception.SystemException;
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.model.ThirdUser;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGiteeService;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class TaskCodeGiteeServiceImpl implements TaskCodeGiteeService {
|
||||
|
||||
@Resource
|
||||
AuthThirdService authThirdService;
|
||||
|
||||
/**
|
||||
* 获取accessToken
|
||||
* @param authId 认证ID
|
||||
* @return 凭证
|
||||
*/
|
||||
private String findAccessToken(String authId){
|
||||
AuthThird authServer = authThirdService.findOneAuthServer(authId);
|
||||
if (Objects.isNull(authServer)){
|
||||
throw new ApplicationException("没有查询到当前凭证授权码!");
|
||||
}
|
||||
return authServer.getAccessToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery){
|
||||
List<ThirdHouse> houseList = new ArrayList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
String url;
|
||||
if (StringUtils.isEmpty(thirdQuery.getQuery())){
|
||||
url = String.format("https://gitee.com/api/v5/user/repos?access_token=%s&sort=full_name&page=%s&per_page=%s",
|
||||
accessToken,thirdQuery.getPage(),thirdQuery.getPageNumber());
|
||||
}else {
|
||||
url = String.format("https://gitee.com/api/v5/user/repos?access_token=%s&sort=full_name&q=%s&page=%s&per_page=%s",
|
||||
accessToken,thirdQuery.getQuery(),thirdQuery.getPage(),thirdQuery.getPageNumber());
|
||||
}
|
||||
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取分支信息失败,获取信息为空!");
|
||||
}
|
||||
JSONArray projectList = JSONObject.parseArray(body);
|
||||
for (Object o : projectList) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(o));
|
||||
String id = jsonObject.getString("full_name");
|
||||
String name = jsonObject.getString("name");
|
||||
String path = jsonObject.getString("path");
|
||||
String nameSpace = jsonObject.getString("full_name");
|
||||
String pathSpace = jsonObject.getString("human_name");
|
||||
String sshUrl = jsonObject.getString("ssh_url");
|
||||
String webUrl = jsonObject.getString("html_url");
|
||||
String defaultBranch = jsonObject.getString("default_branch");
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(path);
|
||||
thirdHouse.setNameWithSpace(nameSpace);
|
||||
thirdHouse.setPathWithSpace(pathSpace);
|
||||
thirdHouse.setHouseSshUrl(sshUrl);
|
||||
thirdHouse.setHouseWebUrl(webUrl);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
houseList.add(thirdHouse);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
if (e instanceof HttpClientErrorException){
|
||||
int rawStatusCode = ((HttpClientErrorException) e).getRawStatusCode();
|
||||
if (rawStatusCode == 401){
|
||||
throw new ApplicationException("授权信息认证失败!");
|
||||
}
|
||||
}
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
return houseList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdHouse findStoreHouse(ThirdQuery thirdQuery){
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
String[] split = thirdQuery.getHouseId().split("/");
|
||||
String url = String.format("https://gitee.com/api/v5/repos/%s/%s?access_token=%s",
|
||||
split[0],split[1],accessToken);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取仓库信息失败,获取信息为空!");
|
||||
}
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
String id = jsonObject.getString("full_name");
|
||||
String name = jsonObject.getString("name");
|
||||
String path = jsonObject.getString("path");
|
||||
String nameSpace = jsonObject.getString("full_name");
|
||||
String pathSpace = jsonObject.getString("human_name");
|
||||
String sshUrl = jsonObject.getString("ssh_url");
|
||||
String webUrl = jsonObject.getString("html_url");
|
||||
String defaultBranch = jsonObject.getString("default_branch");
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(path);
|
||||
thirdHouse.setNameWithSpace(nameSpace);
|
||||
thirdHouse.setPathWithSpace(pathSpace);
|
||||
thirdHouse.setHouseSshUrl(sshUrl);
|
||||
thirdHouse.setHouseWebUrl(webUrl);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
return thirdHouse;
|
||||
} catch (Exception e) {
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdUser findAuthUser(ThirdQuery thirdQuery){
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
String url = String.format("https://gitee.com/api/v5/user?access_token=%s",accessToken);
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
String id = jsonObject.getString("id");
|
||||
String login = jsonObject.getString("login");
|
||||
String name = jsonObject.getString("name");
|
||||
String avatar = jsonObject.getString("avatar_url");
|
||||
|
||||
ThirdUser thirdUser = new ThirdUser();
|
||||
thirdUser.setId(id);
|
||||
thirdUser.setName(name);
|
||||
thirdUser.setPath(login);
|
||||
thirdUser.setHead(avatar);
|
||||
return thirdUser;
|
||||
}catch (Exception e) {
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdBranch> findStoreBranchList(ThirdQuery thirdQuery){
|
||||
List<ThirdBranch> branchList= new ArrayList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String[] split = thirdQuery.getHouseId().split("/");
|
||||
String accessToken = findAccessToken(thirdQuery.getAuthId());
|
||||
String url = String.format("https://gitee.com/api/v5/repos/%s/%s/branches?access_token=%s&sort=name&direction=asc&page=%s&per_page=%s",
|
||||
split[0],split[1],accessToken,thirdQuery.getPage(),thirdQuery.getPageNumber());
|
||||
ResponseEntity<String> forEntity;
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取分支信息失败,获取信息为空!");
|
||||
}
|
||||
JSONArray projectList = JSONObject.parseArray(body);
|
||||
if (projectList.isEmpty()){
|
||||
throw new SystemException("获取分支信息失败,当前仓库为空仓库!");
|
||||
}
|
||||
for (Object o : projectList) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(o));
|
||||
String name = jsonObject.getString("name");
|
||||
Boolean isProtected = jsonObject.getBoolean("protected");
|
||||
ThirdBranch thirdBranch = new ThirdBranch();
|
||||
thirdBranch.setId(name);
|
||||
thirdBranch.setName(name);
|
||||
thirdBranch.setIsProtected(isProtected);
|
||||
thirdBranch.setIsDefault(false);
|
||||
branchList.add(thirdBranch);
|
||||
}
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
return branchList;
|
||||
}
|
||||
|
||||
private void findGitlabErrorRequest(int code){
|
||||
switch (code){
|
||||
case 401 -> { throw new ApplicationException("AccessToken无效或已过期 !");}
|
||||
case 403 -> { throw new ApplicationException("AccessToken权限不足!");}
|
||||
case 404 -> { throw new ApplicationException("请求失败,接口不存在!");}
|
||||
case 405 -> { throw new ApplicationException("不支持该请求!");}
|
||||
case 429 -> { throw new ApplicationException("请求次数过多!");}
|
||||
case 503 -> { throw new ApplicationException("服务器暂时超载,无法处理该请求!");}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,282 @@
|
||||
package cd.casic.module.process.task.code.service.impl;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:13
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.exception.SystemException;
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.support.util.util.PipelineRequestUtil;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGittokService;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class TaskCodeGittokServiceImpl implements TaskCodeGittokService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TaskCodeGittokServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
AuthThirdService serverServer;
|
||||
|
||||
@Resource
|
||||
PipelineRequestUtil requestUtil;
|
||||
|
||||
|
||||
@Override
|
||||
public List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery){
|
||||
String authId = thirdQuery.getAuthId();
|
||||
AuthThird authServer = serverServer.findOneAuthServer(authId);
|
||||
|
||||
if (Objects.isNull(authServer)){
|
||||
return null;
|
||||
}
|
||||
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
try {
|
||||
|
||||
String username = authServer.getUsername();
|
||||
String password = authServer.getPassword();
|
||||
|
||||
HttpHeaders headers = requestUtil.initHeaders(MediaType.APPLICATION_JSON, new HashMap<>());
|
||||
MultiValueMap<String, Object> valueMap = new LinkedMultiValueMap<>();
|
||||
valueMap.add("account",username);
|
||||
valueMap.add("password",password);
|
||||
valueMap.add("dirId","1");
|
||||
String requestUrl = serverAddress+"/api/rpy/findRepositoryByUser";
|
||||
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(valueMap, headers);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<JSONObject> response = restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, JSONObject.class);
|
||||
JSONObject jsonObject = response.getBody();
|
||||
JSONArray jsonArray = validBody(jsonObject, JSONArray.class);
|
||||
|
||||
List<ThirdHouse> houseList = new ArrayList<>();
|
||||
|
||||
for (Object o : jsonArray) {
|
||||
JSONObject parseObject = JSONObject.parseObject(String.valueOf(o));
|
||||
ThirdHouse thirdHouse = bindHouse(parseObject);
|
||||
houseList.add(thirdHouse);
|
||||
}
|
||||
return houseList;
|
||||
}catch (Throwable throwable){
|
||||
String message = throwable.getMessage();
|
||||
logger.error(" 连接异常:{}", message);
|
||||
if (message.contains("timed out") ){
|
||||
throw new ApplicationException(58001,"请求超时!");
|
||||
}
|
||||
if (message.contains("未订阅")){
|
||||
throw new ApplicationException("当前企业未订阅gittok");
|
||||
}
|
||||
if (throwable instanceof ApplicationException){
|
||||
throw new ApplicationException(message);
|
||||
}
|
||||
throw new ApplicationException("无法连接到:" + serverAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdBranch> findHouseBranchList(ThirdQuery thirdQuery){
|
||||
String authId = thirdQuery.getAuthId();
|
||||
String houseId = thirdQuery.getHouseId();
|
||||
AuthThird authServer = serverServer.findOneAuthServer(authId);
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
try {
|
||||
HttpHeaders headers = requestUtil.initHeaders(MediaType.APPLICATION_JSON, new HashMap<>());
|
||||
MultiValueMap<String, Object> valueMap = new LinkedMultiValueMap<>();
|
||||
valueMap.add("rpyId",houseId);
|
||||
String requestUrl = serverAddress+"/api/branch/findAllBranch";
|
||||
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(valueMap, headers);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<JSONObject> response = restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, JSONObject.class);
|
||||
JSONObject jsonObject = response.getBody();
|
||||
List<ThirdBranch> branchList = new ArrayList<>();
|
||||
JSONArray jsonArray = validBody(jsonObject, JSONArray.class);
|
||||
for (Object o : jsonArray) {
|
||||
JSONObject parseObject = JSONObject.parseObject(String.valueOf(o));
|
||||
ThirdBranch thirdBranch = bindBranch(parseObject);
|
||||
branchList.add(thirdBranch);
|
||||
}
|
||||
return branchList;
|
||||
|
||||
// return requestUtil.requestPostList(headers, requestUrl, valueMap, XcodeBranch.class);
|
||||
}catch (Throwable throwable){
|
||||
String message = throwable.getMessage();
|
||||
logger.error(message);
|
||||
if (message.contains("未订阅")){
|
||||
throw new ApplicationException("当前企业未订阅Xcode");
|
||||
}
|
||||
if (throwable instanceof ApplicationException){
|
||||
throw new ApplicationException(message);
|
||||
}
|
||||
throw new ApplicationException("无法连接到:"+serverAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdBranch findOneBranch(String authId,String rpyId,String branchId){
|
||||
if (Objects.isNull(authId) || Objects.isNull(branchId)){
|
||||
return null;
|
||||
}
|
||||
|
||||
AuthThird authServer = serverServer.findOneAuthServer(authId);
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
|
||||
HttpHeaders headers = requestUtil.initHeaders(MediaType.APPLICATION_JSON, new HashMap<>());
|
||||
MultiValueMap<String, Object> valueMap = new LinkedMultiValueMap<>();
|
||||
valueMap.add("rpyId",rpyId);
|
||||
valueMap.add("commitId",branchId);
|
||||
String requestUrl = serverAddress+"/api/branch/findBranch";
|
||||
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(valueMap, headers);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<JSONObject> response = restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, JSONObject.class);
|
||||
JSONObject object = validBody(response.getBody(), JSONObject.class);
|
||||
ThirdBranch thirdBranch = bindBranch(object);
|
||||
if (Objects.isNull(thirdBranch)){
|
||||
throw new ApplicationException("找不到"+ rpyId +"仓库!");
|
||||
}
|
||||
return thirdBranch;
|
||||
|
||||
// return requestUtil.requestPost(headers, requestUrl, valueMap, XcodeBranch.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdHouse findStoreHouse(ThirdQuery thirdQuery){
|
||||
String authId = thirdQuery.getAuthId();
|
||||
String houseId = thirdQuery.getHouseId();
|
||||
if (Objects.isNull(authId) || Objects.isNull(houseId)){
|
||||
return null;
|
||||
}
|
||||
AuthThird authServer = serverServer.findOneAuthServer(authId);
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
try {
|
||||
HttpHeaders headers = requestUtil.initHeaders(MediaType.APPLICATION_JSON, new HashMap<>());
|
||||
MultiValueMap<String, Object> valueMap = new LinkedMultiValueMap<>();
|
||||
valueMap.add("id",houseId);
|
||||
String requestUrl = serverAddress+"/api/rpy/findRepository";
|
||||
|
||||
HttpEntity<Object> requestEntity = new HttpEntity<>(valueMap, headers);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<JSONObject> response = restTemplate.exchange(requestUrl, HttpMethod.POST, requestEntity, JSONObject.class);
|
||||
JSONObject object = validBody(response.getBody(), JSONObject.class);
|
||||
ThirdHouse thirdHouse = bindHouse(object);
|
||||
if (Objects.isNull(thirdHouse)){
|
||||
throw new ApplicationException("找不到"+ houseId +"仓库!");
|
||||
}
|
||||
return thirdHouse;
|
||||
}catch (Throwable throwable){
|
||||
String message = throwable.getMessage();
|
||||
logger.error(message);
|
||||
if (message.contains("未订阅")){
|
||||
throw new ApplicationException("当前企业未订阅Xcode");
|
||||
}
|
||||
if (throwable instanceof ApplicationException){
|
||||
throw new ApplicationException(message);
|
||||
}
|
||||
throw new ApplicationException("无法连接到:"+serverAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private <T> T validBody(JSONObject jsonObject,Class<T> tClass){
|
||||
if (Objects.isNull( jsonObject)){
|
||||
throw new SystemException("获取返回值为空!");
|
||||
}
|
||||
Integer code = jsonObject.getInteger("code");
|
||||
if (code != 0){
|
||||
String msg = jsonObject.getString("msg");
|
||||
if (code == 5000){
|
||||
throw new ApplicationException("用户效验失败!");
|
||||
}
|
||||
throw new ApplicationException("获取仓库列表失败!,Message:"+msg);
|
||||
}
|
||||
return jsonObject.getObject("data",tClass);
|
||||
}
|
||||
|
||||
|
||||
private ThirdHouse bindHouse(JSONObject jsonObject){
|
||||
if (Objects.isNull(jsonObject)){
|
||||
return null;
|
||||
}
|
||||
String id = jsonObject.getString("rpyId");
|
||||
String fullPath = jsonObject.getString("fullPath");
|
||||
String path = jsonObject.getString("address");
|
||||
String defaultBranch = jsonObject.getString("defaultBranch");
|
||||
String name = jsonObject.getString("name");
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(path);
|
||||
thirdHouse.setNameWithSpace(name);
|
||||
thirdHouse.setPathWithSpace(path);
|
||||
thirdHouse.setHouseSshUrl(fullPath);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
return thirdHouse;
|
||||
}
|
||||
|
||||
private ThirdBranch bindBranch(JSONObject jsonObject){
|
||||
if (Objects.isNull(jsonObject)){
|
||||
return null;
|
||||
}
|
||||
String id = jsonObject.getString("branchId");
|
||||
Boolean defaultBranch = jsonObject.getBoolean("defaultBranch");
|
||||
String branchName = jsonObject.getString("branchName");
|
||||
|
||||
ThirdBranch thirdBranch = new ThirdBranch();
|
||||
thirdBranch.setId(branchName);
|
||||
thirdBranch.setName(branchName);
|
||||
thirdBranch.setIsDefault(defaultBranch);
|
||||
return thirdBranch;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,262 @@
|
||||
package cd.casic.module.process.task.code.service.impl;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:13
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.exception.SystemException;
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.task.code.model.ThirdBranch;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.model.ThirdUser;
|
||||
import cd.casic.module.process.task.code.service.TaskCodePriGitLabService;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class TaskCodePriGitLabServiceImpl implements TaskCodePriGitLabService {
|
||||
|
||||
@Autowired
|
||||
AuthThirdService authThirdService;
|
||||
|
||||
/**
|
||||
* 获取accessToken
|
||||
* @param authId 认证ID
|
||||
* @return 凭证
|
||||
*/
|
||||
private AuthThird findAccessToken(String authId){
|
||||
AuthThird authServer = authThirdService.findOneAuthServer(authId);
|
||||
if (Objects.isNull(authServer)){
|
||||
throw new ApplicationException("没有查询到当前凭证授权码!");
|
||||
}
|
||||
return authServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdHouse> findStoreHouseList(ThirdQuery thirdQuery){
|
||||
AuthThird authServer = findAccessToken(thirdQuery.getAuthId());
|
||||
String accessToken = authServer.getAccessToken();
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
List<ThirdHouse> houseList = new ArrayList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
String url = String.format("%s/api/v4/projects?min_access_level=10&simple=true&page=%s&per_page=%s",
|
||||
serverAddress,thirdQuery.getPage(),thirdQuery.getPageNumber());
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", "Bearer"+" "+accessToken);
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
ResponseEntity<String> forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取分支信息失败,获取信息为空!");
|
||||
}
|
||||
JSONArray projectList = JSONObject.parseArray(body);
|
||||
for (Object o : projectList) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(o));
|
||||
String id = jsonObject.getString("id");
|
||||
String name = jsonObject.getString("name");
|
||||
String path = jsonObject.getString("path");
|
||||
String nameSpace = jsonObject.getString("name_with_namespace");
|
||||
String pathSpace = jsonObject.getString("path_with_namespace");
|
||||
String sshUrl = jsonObject.getString("ssh_url_to_repo");
|
||||
String webUrl = jsonObject.getString("http_url_to_repo");
|
||||
String defaultBranch = jsonObject.getString("default_branch");
|
||||
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(path);
|
||||
thirdHouse.setNameWithSpace(nameSpace);
|
||||
thirdHouse.setPathWithSpace(pathSpace);
|
||||
thirdHouse.setHouseSshUrl(sshUrl);
|
||||
thirdHouse.setHouseWebUrl(webUrl);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
houseList.add(thirdHouse);
|
||||
}
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
return houseList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdHouse findStoreHouse(ThirdQuery thirdQuery) {
|
||||
AuthThird authServer = findAccessToken(thirdQuery.getAuthId());
|
||||
String accessToken = authServer.getAccessToken();
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = String.format("%s/api/v4/projects/%s",serverAddress,thirdQuery.getHouseId());
|
||||
ResponseEntity<String> forEntity;
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", "Bearer"+" "+accessToken);
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取仓库信息失败,获取信息为空!");
|
||||
}
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
String id = jsonObject.getString("id");
|
||||
String name = jsonObject.getString("name");
|
||||
String path = jsonObject.getString("path");
|
||||
String nameSpace = jsonObject.getString("name_with_namespace");
|
||||
String pathSpace = jsonObject.getString("path_with_namespace");
|
||||
String sshUrl = jsonObject.getString("ssh_url_to_repo");
|
||||
String webUrl = jsonObject.getString("http_url_to_repo");
|
||||
String defaultBranch = jsonObject.getString("default_branch");
|
||||
ThirdHouse thirdHouse = new ThirdHouse();
|
||||
thirdHouse.setId(id);
|
||||
thirdHouse.setName(name);
|
||||
thirdHouse.setPath(path);
|
||||
thirdHouse.setNameWithSpace(nameSpace);
|
||||
thirdHouse.setPathWithSpace(pathSpace);
|
||||
thirdHouse.setHouseSshUrl(sshUrl);
|
||||
thirdHouse.setHouseWebUrl(webUrl);
|
||||
thirdHouse.setDefaultBranch(defaultBranch);
|
||||
|
||||
return thirdHouse;
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThirdUser findAuthUser(ThirdQuery thirdQuery){
|
||||
AuthThird authServer = findAccessToken(thirdQuery.getAuthId());
|
||||
String accessToken = authServer.getAccessToken();
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = serverAddress+ "/api/v4/user";
|
||||
ResponseEntity<String> forEntity;
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", "Bearer"+" "+accessToken);
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(body);
|
||||
String id = jsonObject.getString("id");
|
||||
String login = jsonObject.getString("username");
|
||||
String name = jsonObject.getString("name");
|
||||
String avatar = jsonObject.getString("avatar_url");
|
||||
|
||||
ThirdUser thirdUser = new ThirdUser();
|
||||
thirdUser.setId(id);
|
||||
thirdUser.setName(name);
|
||||
thirdUser.setPath(login);
|
||||
thirdUser.setHead(avatar);
|
||||
return thirdUser;
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ThirdBranch> findStoreBranchList(ThirdQuery thirdQuery){
|
||||
AuthThird authServer = findAccessToken(thirdQuery.getAuthId());
|
||||
String accessToken = authServer.getAccessToken();
|
||||
String serverAddress = authServer.getServerAddress();
|
||||
List<ThirdBranch> branchList= new ArrayList<>();
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = String.format("%s/api/v4/projects/%s/repository/branches",serverAddress,thirdQuery.getHouseId());
|
||||
ResponseEntity<String> forEntity;
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", "Bearer"+" "+accessToken);
|
||||
MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(paramMap, headers);
|
||||
forEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
String body = forEntity.getBody();
|
||||
if (Objects.isNull(body)){
|
||||
throw new SystemException("获取分支信息失败,获取信息为空!");
|
||||
}
|
||||
JSONArray projectList = JSONObject.parseArray(body);
|
||||
for (Object o : projectList) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(o));
|
||||
String id = jsonObject.getString("commit");
|
||||
String name = jsonObject.getString("name");
|
||||
Boolean isDefault = jsonObject.getBoolean("default");
|
||||
Boolean idProtected = jsonObject.getBoolean("protected");
|
||||
ThirdBranch thirdBranch = new ThirdBranch();
|
||||
thirdBranch.setId(name);
|
||||
thirdBranch.setName(name);
|
||||
thirdBranch.setIsProtected(idProtected);
|
||||
thirdBranch.setIsProtected(false);
|
||||
|
||||
branchList.add(thirdBranch);
|
||||
}
|
||||
}catch (HttpClientErrorException e) {
|
||||
findGitlabErrorRequest(e.getRawStatusCode());
|
||||
throw new SystemException(String.valueOf(e));
|
||||
}
|
||||
return branchList;
|
||||
}
|
||||
|
||||
private void findGitlabErrorRequest(int code){
|
||||
switch (code){
|
||||
case 401 -> { throw new ApplicationException("令牌无效或已过期 !");}
|
||||
case 403 -> { throw new ApplicationException("令牌权限不足!");}
|
||||
case 404 -> { throw new ApplicationException("请求失败,接口不存在!");}
|
||||
case 405 -> { throw new ApplicationException("不支持该请求!");}
|
||||
case 429 -> { throw new ApplicationException("请求次数过多!");}
|
||||
case 503 -> { throw new ApplicationException("服务器暂时超载,无法处理该请求!");}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,221 @@
|
||||
package cd.casic.module.process.task.code.service.impl;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 20:14
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.ci.commons.rpc.annototion.Exporter;
|
||||
import cd.casic.module.process.process.setting.AuthService;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.task.code.dao.TaskCodeDao;
|
||||
import cd.casic.module.process.task.code.dataobject.TaskCodeDo;
|
||||
import cd.casic.module.process.task.code.model.TaskCode;
|
||||
import cd.casic.module.process.task.code.model.ThirdHouse;
|
||||
import cd.casic.module.process.task.code.model.ThirdQuery;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGitHubService;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGitLabService;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGiteeService;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeGittokService;
|
||||
import cd.casic.module.process.task.code.service.TaskCodePriGitLabService;
|
||||
import cd.casic.module.process.task.code.service.TaskCodeService;
|
||||
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cd.casic.ci.commons.bean.commons.PipelineConstants.AUTH_NONE;
|
||||
import static cd.casic.ci.commons.bean.commons.PipelineConstants.AUTH_USER_PASS;
|
||||
import static cd.casic.ci.commons.bean.commons.PipelineConstants.TASK_CODE_PRI_GITLAB;
|
||||
import static cd.casic.module.process.support.util.util.PipelineFinal.TASK_CODE_GITEE;
|
||||
import static cd.casic.module.process.support.util.util.PipelineFinal.TASK_CODE_GITHUB;
|
||||
import static cd.casic.module.process.support.util.util.PipelineFinal.TASK_CODE_GITLAB;
|
||||
import static cd.casic.module.process.support.util.util.PipelineFinal.TASK_CODE_SVN;
|
||||
import static cd.casic.module.process.support.util.util.PipelineFinal.TASK_CODE_XCODE;
|
||||
|
||||
|
||||
@Service
|
||||
@Exporter
|
||||
public class TaskCodeServiceImpl implements TaskCodeService {
|
||||
|
||||
@Resource
|
||||
TaskCodeDao taskCodeDao;
|
||||
|
||||
@Resource
|
||||
AuthService authServer;
|
||||
|
||||
@Resource
|
||||
AuthThirdService authServerServer;
|
||||
|
||||
@Resource
|
||||
TaskCodeGiteeService giteeService;
|
||||
|
||||
@Resource
|
||||
TaskCodeGitHubService gitHubService;
|
||||
|
||||
@Resource
|
||||
TaskCodeGitLabService gitLabService;
|
||||
|
||||
@Resource
|
||||
TaskCodePriGitLabService priGitLabService;
|
||||
|
||||
@Resource
|
||||
TaskCodeGittokService xcodeService;
|
||||
|
||||
@Override
|
||||
public String createCode(TaskCode taskCode) {
|
||||
return taskCodeDao.createCode(BeanMapper.map(taskCode, TaskCodeDo.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskCode findCodeByAuth(String taskId){
|
||||
TaskCodeDo oneCodeEntity = taskCodeDao.findOneCode(taskId);
|
||||
TaskCode taskCode = BeanMapper.map(oneCodeEntity, TaskCode.class);
|
||||
String authId = taskCode.getAuthId();
|
||||
|
||||
if (Objects.isNull(authId)){
|
||||
return taskCode;
|
||||
}
|
||||
taskCode.setAuth(findAuth(taskCode.getAuthId()));
|
||||
return taskCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean codeValid(String taskType,TaskCode code){
|
||||
switch (taskType) {
|
||||
case TASK_CODE_GITEE, TASK_CODE_GITLAB, TASK_CODE_GITHUB,TASK_CODE_PRI_GITLAB -> {
|
||||
if (StringUtils.isEmpty(code.getHouseId())) {
|
||||
return false;
|
||||
}
|
||||
return !StringUtils.isEmpty(code.getAuthId());
|
||||
}
|
||||
case TASK_CODE_XCODE -> {
|
||||
if (StringUtils.isEmpty(code.getHouseId())) {
|
||||
return false;
|
||||
}
|
||||
return !StringUtils.isEmpty(code.getAuthId());
|
||||
}
|
||||
case TASK_CODE_SVN -> {
|
||||
// String svnFile = code.getSvnFile();
|
||||
// return !StringUtils.isEmpty(svnFile);
|
||||
return true;
|
||||
}
|
||||
default -> {
|
||||
String codeAddress = code.getCodeAddress();
|
||||
return !StringUtils.isEmpty(codeAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCode(String codeId) {
|
||||
taskCodeDao.deleteCode(codeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCode(TaskCode taskCode) {
|
||||
TaskCodeDo oneCodeEntity = taskCodeDao.findOneCode(taskCode.getTaskId());
|
||||
TaskCode oneCode = BeanMapper.map(oneCodeEntity, TaskCode.class);
|
||||
String authId = oneCode.getAuthId();
|
||||
String houseId = taskCode.getHouseId();
|
||||
|
||||
if (!StringUtils.isEmpty(houseId)){
|
||||
ThirdHouse storeHouse = null;
|
||||
ThirdQuery thirdQuery = new ThirdQuery();
|
||||
thirdQuery.setHouseId(houseId);
|
||||
thirdQuery.setAuthId(authId);
|
||||
switch (taskCode.getType()) {
|
||||
case TASK_CODE_GITEE -> {
|
||||
storeHouse = giteeService.findStoreHouse(thirdQuery);
|
||||
}
|
||||
case TASK_CODE_GITHUB -> {
|
||||
storeHouse = gitHubService.findStoreHouse(thirdQuery);
|
||||
}
|
||||
case TASK_CODE_GITLAB -> {
|
||||
storeHouse = gitLabService.findStoreHouse(thirdQuery);
|
||||
}
|
||||
case TASK_CODE_PRI_GITLAB -> {
|
||||
storeHouse = priGitLabService.findStoreHouse(thirdQuery);
|
||||
}
|
||||
case TASK_CODE_XCODE -> {
|
||||
storeHouse = xcodeService.findStoreHouse(thirdQuery);
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
if (!Objects.isNull(storeHouse)){
|
||||
taskCode.setCodeAddress(storeHouse.getHouseWebUrl());
|
||||
taskCode.setCodeName(storeHouse.getNameWithSpace());
|
||||
taskCode.setCodeBranch(storeHouse.getDefaultBranch());
|
||||
}
|
||||
}else {
|
||||
taskCode.setCodeAddress(taskCode.getCodeName());
|
||||
}
|
||||
|
||||
String authType = taskCode.getAuthType();
|
||||
if (!StringUtils.isEmpty(authType)){
|
||||
if (authType.equals(AUTH_NONE)){
|
||||
taskCode.setUsername("");
|
||||
taskCode.setPassword("");
|
||||
taskCode.setPriKey("");
|
||||
}else if (authType.equals(AUTH_USER_PASS)){
|
||||
taskCode.setPriKey("");
|
||||
}else {
|
||||
taskCode.setUsername("");
|
||||
taskCode.setPassword("");
|
||||
}
|
||||
}
|
||||
TaskCodeDo taskCodeDo = BeanMapper.map(taskCode, TaskCodeDo.class);
|
||||
taskCodeDao.updateCode(taskCodeDo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOneCode(TaskCode taskCode){
|
||||
taskCodeDao.updateCode(BeanMapper.map(taskCode, TaskCodeDo.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskCode findOneCode(String codeId) {
|
||||
TaskCodeDo oneCodeEntity = taskCodeDao.findOneCode(codeId);
|
||||
return BeanMapper.map(oneCodeEntity, TaskCode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskCode> findAllCode() {
|
||||
List<TaskCodeDo> allCode = taskCodeDao.findAllCode();
|
||||
List<TaskCode> taskCodes = BeanMapper.mapList(allCode, TaskCode.class);
|
||||
if (taskCodes == null){
|
||||
return null;
|
||||
}
|
||||
for (TaskCode taskCode : taskCodes) {
|
||||
taskCode.setAuth(findAuth(taskCode.getAuthId()));
|
||||
}
|
||||
return taskCodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskCode> findAllCodeList(List<String> idList) {
|
||||
return BeanMapper.mapList(taskCodeDao.findAllCodeList(idList), TaskCode.class);
|
||||
}
|
||||
|
||||
//获认证信息
|
||||
private Object findAuth(String id){
|
||||
AuthThird oneAuthServer = authServerServer.findOneAuthServer(id);
|
||||
if (oneAuthServer != null){
|
||||
return oneAuthServer;
|
||||
}
|
||||
return authServer.findOneAuth(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,111 @@
|
||||
package cd.casic.module.process.task.codescan.controller;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/3 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.commons.Pagination;
|
||||
import cd.casic.ci.commons.bean.utils.Result;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
import cd.casic.module.process.task.code.service.SpotbugsScanService;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugInstance;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugPackageStats;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugQuery;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugSummary;
|
||||
import cd.casic.module.process.task.codescan.service.impl.SpotbugsXmlConfig;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @pi.protocol: http
|
||||
* @pi.groupName: 流水线代码扫描Spotbugs控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/spotbugsScan")
|
||||
public class SpotbugsScanController {
|
||||
|
||||
@Resource
|
||||
SpotbugsScanService spotbugsScanService;
|
||||
|
||||
/**
|
||||
* @pi.name:条件查询代码扫描结果
|
||||
* @pi.url:/spotbugsScan/findScanBugsList
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type:json
|
||||
* @pi.param: model=spotbugsBugQuery
|
||||
*/
|
||||
@RequestMapping(path = "/findScanBugsList", method = RequestMethod.POST)
|
||||
public Result<List<SpotbugsBugSummary>> findSpotbugsList(@RequestBody @Valid @NotNull SpotbugsBugQuery spotbugsBugQuery) {
|
||||
List<SpotbugsBugSummary> spotbugsList = spotbugsScanService.findSpotbugsList(spotbugsBugQuery);
|
||||
|
||||
return Result.ok(spotbugsList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @pi.name:分页查询代码扫描结果
|
||||
* @pi.url:/spotbugsScan/findSpotbugsPage
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type:json
|
||||
* @pi.param: model=spotbugsBugQuery
|
||||
*/
|
||||
@RequestMapping(path = "/findSpotbugsPage", method = RequestMethod.POST)
|
||||
public Result<Pagination<SpotbugsBugSummary>> findSpotbugsPage(@RequestBody @Valid @NotNull SpotbugsBugQuery spotbugsBugQuery) {
|
||||
|
||||
PageResult<SpotbugsBugSummary> spotbugsList = spotbugsScanService.findSpotbugsPage(spotbugsBugQuery);
|
||||
|
||||
return Result.ok(spotbugsList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @pi.name:查询代码扫描详情
|
||||
* @pi.url:/spotbugsScan/findBugs
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=xmlPath;dataType=string;value=xmlPath;
|
||||
*/
|
||||
@RequestMapping(path = "/findBugs", method = RequestMethod.POST)
|
||||
public Result<List<SpotbugsBugInstance>> findAllRepository(@NotNull String xmlPath) {
|
||||
List<SpotbugsBugInstance> scanBugs = new SpotbugsXmlConfig().findScanBugs(xmlPath);
|
||||
|
||||
return Result.ok(scanBugs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @pi.name:删除代码扫描结果
|
||||
* @pi.url:/spotbugsScan/deleteSpotbugs
|
||||
* @pi.methodType:post
|
||||
* @pi.request-type: formdata
|
||||
* @pi.param: name=bugId;dataType=string;value=bugId;
|
||||
*/
|
||||
@RequestMapping(path = "/deleteSpotbugs", method = RequestMethod.POST)
|
||||
public Result<List<SpotbugsBugPackageStats>> deleteSpotbugs(@NotNull String bugId) {
|
||||
|
||||
spotbugsScanService.deleteSpotbugs(bugId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package cd.casic.module.process.task.codescan.dao;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/3 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
import cd.casic.ci.commons.bean.commons.Pagination;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
import cd.casic.module.process.task.code.jpa.JpaTemplate;
|
||||
import cd.casic.module.process.task.codescan.dataobject.SpotbugsScanEntity;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugQuery;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugSummary;
|
||||
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Spotbugs代码扫描数据操作
|
||||
* @author zcamy
|
||||
*/
|
||||
@Repository
|
||||
public class SpotbugsScanDao {
|
||||
|
||||
|
||||
@Resource
|
||||
JpaTemplate jpaTemplate;
|
||||
|
||||
public String creatSpotbugs(SpotbugsBugSummary bugSummary) {
|
||||
SpotbugsScanEntity scanEntity = BeanMapper.map(bugSummary, SpotbugsScanEntity.class);
|
||||
return jpaTemplate.save(scanEntity,String.class);
|
||||
}
|
||||
|
||||
public void updateSpotbugs(SpotbugsBugSummary bugSummary) {
|
||||
SpotbugsScanEntity scanEntity = BeanMapper.map(bugSummary, SpotbugsScanEntity.class);
|
||||
jpaTemplate.update(scanEntity);
|
||||
}
|
||||
|
||||
|
||||
public void deleteSpotbugs(String bugId) {
|
||||
jpaTemplate.delete(SpotbugsScanEntity.class,bugId);
|
||||
}
|
||||
|
||||
|
||||
public SpotbugsBugSummary findOneSpotbugs(String bugId) {
|
||||
SpotbugsScanEntity scanEntity = jpaTemplate.findOne(SpotbugsScanEntity.class, bugId);
|
||||
|
||||
return BeanMapper.map(scanEntity,SpotbugsBugSummary.class);
|
||||
}
|
||||
|
||||
|
||||
public List<SpotbugsBugSummary> findAllSpotbugs() {
|
||||
List<SpotbugsScanEntity> scanEntityList = jpaTemplate.findAll(SpotbugsScanEntity.class);
|
||||
if (scanEntityList == null || scanEntityList.isEmpty()){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return BeanMapper.mapList(scanEntityList,SpotbugsBugSummary.class);
|
||||
}
|
||||
|
||||
|
||||
public List<SpotbugsBugSummary> findSpotbugsList(SpotbugsBugQuery bugQuery) {
|
||||
return BeanMapper.mapList(null,SpotbugsBugSummary.class);
|
||||
}
|
||||
|
||||
public PageResult<SpotbugsBugSummary> findSpotbugsPage(SpotbugsBugQuery bugQuery) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package cd.casic.module.process.task.codescan.dao;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:26
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.module.process.task.code.jpa.JpaTemplate;
|
||||
import cd.casic.module.process.task.codescan.dataobject.TaskCodeScanEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public class TaskCodeScanDao {
|
||||
|
||||
@Autowired
|
||||
JpaTemplate jpaTemplate ;
|
||||
|
||||
/**
|
||||
* 创建动态
|
||||
* @param taskCodeScanEntity 代码扫描
|
||||
* @return 代码扫描id
|
||||
*/
|
||||
public String createCodeScan(TaskCodeScanEntity taskCodeScanEntity){
|
||||
|
||||
return jpaTemplate.save(taskCodeScanEntity, String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除代码扫描
|
||||
* @param CodeScanId 代码扫描id
|
||||
*/
|
||||
public void deleteCodeScan(String CodeScanId){
|
||||
jpaTemplate.delete(TaskCodeScanEntity.class, CodeScanId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新代码扫描
|
||||
* @param taskCodeScanEntity 更新信息
|
||||
*/
|
||||
public void updateCodeScan(TaskCodeScanEntity taskCodeScanEntity){
|
||||
jpaTemplate.update(taskCodeScanEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个代码扫描信息
|
||||
* @param CodeScanId 代码扫描id
|
||||
* @return 代码扫描信息
|
||||
*/
|
||||
public TaskCodeScanEntity findOneCodeScan(String CodeScanId){
|
||||
return jpaTemplate.findOne(TaskCodeScanEntity.class,CodeScanId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有代码扫描
|
||||
* @return 代码扫描集合
|
||||
*/
|
||||
public List<TaskCodeScanEntity> findAllCodeScan(){
|
||||
return jpaTemplate.findAll(TaskCodeScanEntity.class);
|
||||
}
|
||||
|
||||
|
||||
public List<TaskCodeScanEntity> findAllCodeScanList(List<String> idList){
|
||||
return jpaTemplate.findList(TaskCodeScanEntity.class,idList);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package cd.casic.module.process.task.codescan.dataobject;
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:26
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author Spotbugs代码扫描
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "pip_task_code_scan_spotbugs", autoResultMap = true)
|
||||
public class SpotbugsScanEntity extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private String id;
|
||||
|
||||
// 流水线id
|
||||
private String pipelineId;
|
||||
|
||||
// 扫描时间
|
||||
private String scanTime;
|
||||
|
||||
// 总共扫描的类的数量。
|
||||
private String totalClasses;
|
||||
|
||||
// 引用的类的数量
|
||||
private String referencedClasses;
|
||||
|
||||
// 检测到的问题(Bugs)的数量
|
||||
private String totalBugs;
|
||||
|
||||
// 项目中的包(package)数量
|
||||
private String numPackages;
|
||||
|
||||
// 优先级为 1 的问题数
|
||||
private String priorityOne;
|
||||
|
||||
// 优先级为 2 的问题数
|
||||
private String priorityTwo;
|
||||
|
||||
// 优先级为 3 的问题数
|
||||
private String priorityThree;
|
||||
|
||||
private String xmlPath;
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package cd.casic.module.process.task.codescan.dataobject;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/2 19:26
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
|
||||
import cd.casic.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
/**
|
||||
* 代码扫描
|
||||
* @author zcamy
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "pip_task_code_scan", autoResultMap = true)
|
||||
public class TaskCodeScanEntity extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private String taskId;
|
||||
|
||||
private String projectName;
|
||||
|
||||
private String authId;
|
||||
|
||||
// 是否开启断言
|
||||
private String openAssert;
|
||||
|
||||
// 是否启用调试模式
|
||||
private String openDebug;
|
||||
|
||||
private String scanPath;
|
||||
|
||||
// 扫描等级 min--最小,default--默认,max--最大
|
||||
private String scanGrade;
|
||||
|
||||
// 扫描错误级别 default--默认 max--最大
|
||||
private String errGrade;
|
||||
|
||||
// jdk版本
|
||||
private String toolJdk;
|
||||
|
||||
// maven版本
|
||||
private String toolMaven;
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package cd.casic.module.process.task.codescan.service.impl;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/3 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
import cd.casic.module.process.task.code.service.SpotbugsScanService;
|
||||
import cd.casic.module.process.task.codescan.dao.SpotbugsScanDao;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugQuery;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugSummary;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Spotbugs代码扫描实现
|
||||
*/
|
||||
@Service
|
||||
public class SpotbugsScanServiceImpl implements SpotbugsScanService {
|
||||
|
||||
@Resource
|
||||
SpotbugsScanDao spotbugsScanDao;
|
||||
|
||||
@Override
|
||||
public String creatSpotbugs(SpotbugsBugSummary bugSummary) {
|
||||
return spotbugsScanDao.creatSpotbugs(bugSummary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSpotbugs(SpotbugsBugSummary bugSummary) {
|
||||
spotbugsScanDao.updateSpotbugs(bugSummary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSpotbugs(String bugId) {
|
||||
SpotbugsBugSummary spotbugs = findOneSpotbugs(bugId);
|
||||
if (Objects.isNull(spotbugs)){
|
||||
return;
|
||||
}
|
||||
String xmlPath = spotbugs.getXmlPath();
|
||||
|
||||
File file = new File(xmlPath);
|
||||
if (file.exists()){
|
||||
file.delete();
|
||||
}
|
||||
spotbugsScanDao.deleteSpotbugs(bugId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpotbugsBugSummary findOneSpotbugs(String bugId) {
|
||||
return spotbugsScanDao.findOneSpotbugs(bugId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpotbugsBugSummary> findAllSpotbugs() {
|
||||
return spotbugsScanDao.findAllSpotbugs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SpotbugsBugSummary> findSpotbugsList(SpotbugsBugQuery bugQuery) {
|
||||
return spotbugsScanDao.findSpotbugsList(bugQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<SpotbugsBugSummary> findSpotbugsPage(SpotbugsBugQuery bugQuery) {
|
||||
return spotbugsScanDao.findSpotbugsPage(bugQuery);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,550 @@
|
||||
package cd.casic.module.process.task.codescan.service.impl;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/3 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.exception.ApplicationException;
|
||||
import cd.casic.ci.commons.bean.exception.SystemException;
|
||||
import cd.casic.ci.commons.bean.utils.PipelineFileUtil;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugCategory;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugClass;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugClassStats;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugCode;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugField;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugFileStats;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugInstance;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugMethod;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugPackageStats;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugPattern;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugSourceLine;
|
||||
import cd.casic.module.process.task.codescan.model.SpotbugsBugSummary;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.File;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* SpotbugsXml文件解析
|
||||
* @author zcamy
|
||||
*/
|
||||
public class SpotbugsXmlConfig {
|
||||
|
||||
/**
|
||||
* 解析代码扫描统计信息
|
||||
* @param xmlPath 扫描结果文件
|
||||
* @return 解析结果
|
||||
*/
|
||||
public SpotbugsBugSummary findScanSummary(String xmlPath){
|
||||
try {
|
||||
File xmlFile = new File(xmlPath);
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(xmlFile);
|
||||
|
||||
// 可选:根据需要对Document进行额外的配置
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
// 获取根元素
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
|
||||
NodeList findBugsSummaryList = rootElement.getElementsByTagName("FindBugsSummary");
|
||||
for (int i = 0; i < findBugsSummaryList.getLength(); i++) {
|
||||
Node findBugsSummaryNode = findBugsSummaryList.item(i);
|
||||
if (findBugsSummaryNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element findBugsSummaryElement = (Element) findBugsSummaryNode;
|
||||
String totalClasses = findBugsSummaryElement.getAttribute("total_classes"); //总共扫描的类的数量。
|
||||
String referencedClasses = findBugsSummaryElement.getAttribute("referenced_classes");//引用的类的数量。
|
||||
String totalBugs = findBugsSummaryElement.getAttribute("total_bugs");//总共检测到的问题(Bugs)的数量。
|
||||
String numPackages = findBugsSummaryElement.getAttribute("num_packages");//项目中的包(package)数量。
|
||||
String vmVersion = findBugsSummaryElement.getAttribute("vm_version");//vm_version Java 版本信息。
|
||||
String priority2 = findBugsSummaryElement.getAttribute("priority_2");//优先级为 2 的问题数量。
|
||||
String priority1 = findBugsSummaryElement.getAttribute("priority_1");//优先级为 1 的问题数量。
|
||||
String priority3 = findBugsSummaryElement.getAttribute("priority_3");//优先级为 1 的问题数量。
|
||||
|
||||
// 转换时间
|
||||
String format;
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
|
||||
try {
|
||||
Date date = dateFormat.parse(findBugsSummaryElement.getAttribute("timestamp"));
|
||||
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
||||
} catch (ParseException e) {
|
||||
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
||||
}
|
||||
SpotbugsBugSummary summary = new SpotbugsBugSummary();
|
||||
summary.setScanTime(format);
|
||||
summary.setTotalClasses(totalClasses);
|
||||
summary.setReferencedClasses(referencedClasses);
|
||||
summary.setTotalBugs(totalBugs);
|
||||
summary.setNumPackages(numPackages);
|
||||
summary.setVmVersion(vmVersion);
|
||||
summary.setPriorityOne(priority1);
|
||||
summary.setPriorityTwo(priority2);
|
||||
summary.setPriorityThree(priority3);
|
||||
|
||||
return summary;
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
throw new SystemException("解析Xml文件失败,path:"+xmlPath+" ,message:"+e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析所有Bug
|
||||
* @param xmlPath 文件地址
|
||||
* @return Bug集合
|
||||
*/
|
||||
public List<SpotbugsBugFileStats> findBugFileStats(String xmlPath){
|
||||
try {
|
||||
File xmlFile = new File(xmlPath);
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(xmlFile);
|
||||
|
||||
// 可选:根据需要对Document进行额外的配置
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
List<SpotbugsBugFileStats> list = new ArrayList<>();
|
||||
|
||||
// 获取根元素
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
|
||||
NodeList findBugsSummaryList = rootElement.getElementsByTagName("FindBugsSummary");
|
||||
for (int i = 0; i < findBugsSummaryList.getLength(); i++) {
|
||||
Node findBugsSummaryNode = findBugsSummaryList.item(i);
|
||||
if (findBugsSummaryNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element findBugsSummaryElement = (Element) findBugsSummaryNode;
|
||||
|
||||
NodeList fileStatsList = findBugsSummaryElement.getElementsByTagName("FileStats");
|
||||
for (int i1 = 0; i1 < fileStatsList.getLength(); i1++) {
|
||||
Node fileStatsNide = fileStatsList.item(i);
|
||||
if (fileStatsNide.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element fileStatsElement = (Element) fileStatsNide;
|
||||
String path = fileStatsElement.getAttribute("path");
|
||||
String bugCount = fileStatsElement.getAttribute("bugCount");
|
||||
|
||||
String replace = path.replaceAll("/", ".").replace(".java","");
|
||||
|
||||
List<SpotbugsBugInstance> scanBugsList = findScanBugs(xmlPath);
|
||||
List<SpotbugsBugInstance> bugInstanceList = scanBugsList.stream()
|
||||
.filter(a -> !Objects.equals(a.getBugClass().getClassname(), replace)).toList();
|
||||
|
||||
SpotbugsBugFileStats spotbugsBugFileStats = new SpotbugsBugFileStats()
|
||||
.setPath(path)
|
||||
.setBugNumber(String.valueOf(scanBugsList.size()))
|
||||
.setBugInstanceList(bugInstanceList);
|
||||
|
||||
list.add(spotbugsBugFileStats);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}catch (Exception e){
|
||||
throw new SystemException("解析Xml文件失败,path:"+xmlPath+" ,message:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据包解析Bug
|
||||
* @param xmlPath xml文件地址
|
||||
* @return bug集合
|
||||
*/
|
||||
public List<SpotbugsBugPackageStats> findBugPackageStats(String xmlPath){
|
||||
try {
|
||||
File xmlFile = new File(xmlPath);
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(xmlFile);
|
||||
|
||||
// 可选:根据需要对Document进行额外的配置
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
List<SpotbugsBugPackageStats> list = new ArrayList<>();
|
||||
|
||||
// 获取根元素
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
|
||||
NodeList findBugsSummaryList = rootElement.getElementsByTagName("FindBugsSummary");
|
||||
for (int i = 0; i < findBugsSummaryList.getLength(); i++) {
|
||||
Node findBugsSummaryNode = findBugsSummaryList.item(i);
|
||||
if (findBugsSummaryNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element findBugsSummaryElement = (Element) findBugsSummaryNode;
|
||||
|
||||
NodeList packageStatsList = findBugsSummaryElement.getElementsByTagName("PackageStats");
|
||||
for (int i1 = 0; i1 < packageStatsList.getLength(); i1++) {
|
||||
Node fileStatsNide = packageStatsList.item(i);
|
||||
if (fileStatsNide.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element fileStatsElement = (Element) findBugsSummaryNode;
|
||||
String packagePath = fileStatsElement.getAttribute("package");
|
||||
String totalBugs = fileStatsElement.getAttribute("total_bugs");
|
||||
String totalTypes = fileStatsElement.getAttribute("total_types");
|
||||
|
||||
// 文件不存在bug
|
||||
if ("0".equals(totalBugs)){
|
||||
continue;
|
||||
}
|
||||
List<SpotbugsBugClassStats> classStatsArrayList = new ArrayList<>();
|
||||
|
||||
NodeList classStatsList = fileStatsElement.getElementsByTagName("ClassStats");
|
||||
for (int i2 = 0; i2 < classStatsList.getLength(); i2++) {
|
||||
Element classStatsElement = (Element) classStatsList.item(i);
|
||||
String aClass = classStatsElement.getAttribute("class");
|
||||
String bugs = classStatsElement.getAttribute("bugs");
|
||||
String idInterface = classStatsElement.getAttribute("interface");
|
||||
// if ("0".equals(bugs)){
|
||||
// continue;
|
||||
// }
|
||||
|
||||
List<SpotbugsBugInstance> scanBugsList = findScanBugs(xmlPath);
|
||||
List<SpotbugsBugInstance> bugInstanceList = scanBugsList.stream()
|
||||
.filter(a -> !Objects.equals(a.getBugClass().getClassname(), aClass)).toList();
|
||||
|
||||
SpotbugsBugClassStats spotbugsBugClassStats = new SpotbugsBugClassStats()
|
||||
// .setBugNumber(scanBugsList.size())
|
||||
.setClassName(aClass)
|
||||
// .setInterface(Boolean.valueOf(idInterface))
|
||||
.setBugInstanceList(bugInstanceList);
|
||||
|
||||
classStatsArrayList.add(spotbugsBugClassStats);
|
||||
}
|
||||
SpotbugsBugPackageStats spotbugsBugPackageStats = new SpotbugsBugPackageStats()
|
||||
.setTotalBugs(classStatsArrayList.size())
|
||||
.setPackagePath(packagePath)
|
||||
// .setTotalTypes(Integer.parseInt(totalTypes))
|
||||
.setClassStatsList(classStatsArrayList);
|
||||
list.add(spotbugsBugPackageStats);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}catch (Exception e){
|
||||
throw new SystemException("解析Xml文件失败,path:"+xmlPath+" ,message:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public List<SpotbugsBugInstance> findScanBugs(String xmlPath){
|
||||
try {
|
||||
// 读取XML文件
|
||||
File xmlFile = new File(xmlPath);
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.parse(xmlFile);
|
||||
|
||||
// 可选:根据需要对Document进行额外的配置
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
// 获取根元素
|
||||
Element rootElement = doc.getDocumentElement();
|
||||
|
||||
List<SpotbugsBugInstance> list = new ArrayList<>();
|
||||
|
||||
Map<String, SpotbugsBugCategory> categoryMap = analysisBugCategory(rootElement);
|
||||
|
||||
Map<String, SpotbugsBugPattern> patternMap = analysisBugPattern(rootElement);
|
||||
|
||||
Map<String, SpotbugsBugCode> bugCodeMap = analysisBugCode(rootElement);
|
||||
|
||||
|
||||
// 获取BugInstance元素的列表
|
||||
NodeList bugInstanceList = rootElement.getElementsByTagName("BugInstance");
|
||||
|
||||
// 遍历BugInstance元素列表
|
||||
for (int i = 0; i < bugInstanceList.getLength(); i++) {
|
||||
Node bugInstanceNode = bugInstanceList.item(i);
|
||||
|
||||
if (bugInstanceNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element bugInstanceElement = (Element) bugInstanceNode;
|
||||
|
||||
// 获取Bug 级别
|
||||
String priority = bugInstanceElement.getAttribute("priority");
|
||||
|
||||
String bugDescription = bugInstanceElement.getElementsByTagName("LongMessage")
|
||||
.item(0).getTextContent();
|
||||
|
||||
String shortMessage = bugInstanceElement.getElementsByTagName("ShortMessage")
|
||||
.item(0).getTextContent();
|
||||
|
||||
|
||||
String abbrev = bugInstanceElement.getAttribute("abbrev");
|
||||
SpotbugsBugCode spotbugsBugCode = bugCodeMap.get(abbrev);
|
||||
|
||||
String category = bugInstanceElement.getAttribute("category");
|
||||
SpotbugsBugCategory spotbugsBugCategory = categoryMap.get(category);
|
||||
|
||||
String bugType = bugInstanceElement.getAttribute("type");
|
||||
SpotbugsBugPattern spotbugsBugPattern = patternMap.get(bugType);
|
||||
|
||||
// 解析Class
|
||||
SpotbugsBugClass spotbugsBugClass = analysisClass(bugInstanceElement);
|
||||
|
||||
// 解析Method
|
||||
SpotbugsBugMethod spotbugsBugMethod = analysisMethod(bugInstanceElement);
|
||||
|
||||
// 解析Field
|
||||
SpotbugsBugField spotbugsBugField = analysisField(bugInstanceElement);
|
||||
|
||||
// 解析SourceLine
|
||||
SpotbugsBugSourceLine spotbugsBugSourceLine = analysisSourceLine(bugInstanceElement);
|
||||
|
||||
SpotbugsBugInstance spotbugsBugInstance = new SpotbugsBugInstance()
|
||||
.setBugClass(spotbugsBugClass)
|
||||
.setBugCode(spotbugsBugCode)
|
||||
.setBugField(spotbugsBugField)
|
||||
.setBugMethod(spotbugsBugMethod)
|
||||
.setBugField(spotbugsBugField)
|
||||
.setCategory(spotbugsBugCategory)
|
||||
.setBugPattern(spotbugsBugPattern)
|
||||
.setBugPriority(priority)
|
||||
.setBugSourceLine(spotbugsBugSourceLine)
|
||||
.setBugType(bugType)
|
||||
.setLongMessage(bugDescription)
|
||||
.setShortMessage(shortMessage);
|
||||
list.add(spotbugsBugInstance);
|
||||
}
|
||||
}
|
||||
return list.stream().sorted(Comparator.comparing(SpotbugsBugInstance::getBugPriority)).toList();
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new SystemException("解析Xml文件失败,path:"+xmlPath+" ,message:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 解析Class
|
||||
private SpotbugsBugClass analysisClass(Element element){
|
||||
Element classElement = (Element) element.getElementsByTagName("Class")
|
||||
.item(0);
|
||||
Element sourceLine = (Element) classElement.getElementsByTagName("SourceLine")
|
||||
.item(0);
|
||||
int beginLine = 0 ,endLine = 0;
|
||||
String start = sourceLine.getAttribute("start");
|
||||
if (!StringUtils.isEmpty(start)){
|
||||
beginLine = Integer.parseInt(sourceLine.getAttribute("start"));
|
||||
}
|
||||
String end = sourceLine.getAttribute("end");
|
||||
if (!StringUtils.isEmpty(end)){
|
||||
endLine = Integer.parseInt(sourceLine.getAttribute("end"));
|
||||
}
|
||||
String classname = classElement.getAttribute("classname");
|
||||
String message = classElement.getElementsByTagName("Message")
|
||||
.item(0).getTextContent();
|
||||
return new SpotbugsBugClass()
|
||||
.setMessage(message)
|
||||
.setStartLine(beginLine)
|
||||
.setEndLine(endLine)
|
||||
.setClassname(classname);
|
||||
}
|
||||
|
||||
// 解析Method
|
||||
private SpotbugsBugMethod analysisMethod(Element element){
|
||||
Element methodElement = (Element) element.getElementsByTagName("Method")
|
||||
.item(0);
|
||||
if (Objects.isNull(methodElement)){
|
||||
return null;
|
||||
}
|
||||
String name = methodElement.getAttribute("name");
|
||||
String signature = methodElement.getAttribute("signature");
|
||||
Element sourceLine = (Element) methodElement.getElementsByTagName("SourceLine")
|
||||
.item(0);
|
||||
int beginLine = 0 ,endLine = 0;
|
||||
String start = sourceLine.getAttribute("start");
|
||||
if (!StringUtils.isEmpty(start)){
|
||||
beginLine = Integer.parseInt(start);
|
||||
}
|
||||
String end = sourceLine.getAttribute("end");
|
||||
if (!StringUtils.isEmpty(end)){
|
||||
endLine = Integer.parseInt(end);
|
||||
}
|
||||
String message = methodElement.getElementsByTagName("Message")
|
||||
.item(0).getTextContent();
|
||||
return new SpotbugsBugMethod()
|
||||
.setMethodName(name)
|
||||
.setSignature(signature)
|
||||
.setStartLine(beginLine)
|
||||
.setEndLine(endLine)
|
||||
.setMessage(message);
|
||||
}
|
||||
|
||||
// 解析Field
|
||||
private SpotbugsBugField analysisField(Element element){
|
||||
Element fieldElement = (Element) element.getElementsByTagName("Field")
|
||||
.item(0);
|
||||
if (Objects.isNull(fieldElement)){
|
||||
return null;
|
||||
}
|
||||
String name = fieldElement.getAttribute("name");
|
||||
String signature = fieldElement.getAttribute("signature");
|
||||
String message = fieldElement.getElementsByTagName("Message")
|
||||
.item(0).getTextContent();
|
||||
return new SpotbugsBugField()
|
||||
.setFieldName(name)
|
||||
.setSignature(signature)
|
||||
.setMessage(message);
|
||||
}
|
||||
|
||||
// 解析SourceLine
|
||||
private SpotbugsBugSourceLine analysisSourceLine(Element element){
|
||||
Element sourceLineElement = (Element) element.getElementsByTagName("SourceLine").item(0);
|
||||
if (Objects.isNull(sourceLineElement)){
|
||||
return null;
|
||||
}
|
||||
String sourcePath = sourceLineElement.getAttribute("sourcepath");
|
||||
String sourceFile = sourceLineElement.getAttribute("sourcefile");
|
||||
|
||||
int beginLine = 0 ,endLine = 0;
|
||||
String start = sourceLineElement.getAttribute("start");
|
||||
if (!StringUtils.isEmpty(start)){
|
||||
beginLine = Integer.parseInt(start);
|
||||
}
|
||||
String end = sourceLineElement.getAttribute("end");
|
||||
if (!StringUtils.isEmpty(end)){
|
||||
endLine = Integer.parseInt(end);
|
||||
}
|
||||
String message = sourceLineElement.getElementsByTagName("Message").item(0).getTextContent();
|
||||
return new SpotbugsBugSourceLine()
|
||||
.setStartLine(beginLine)
|
||||
.setEndLine(endLine)
|
||||
.setMessage(message)
|
||||
.setSourceFile(sourceFile)
|
||||
.setSourcePath(sourcePath);
|
||||
}
|
||||
|
||||
// 解析Category
|
||||
private Map<String, SpotbugsBugCategory> analysisBugCategory(Element element){
|
||||
NodeList bugInstanceList = element.getElementsByTagName("BugCategory");
|
||||
Map<String, SpotbugsBugCategory> hashMap = new HashMap<>();
|
||||
for (int i = 0; i < bugInstanceList.getLength(); i++) {
|
||||
Node bugInstanceNode = bugInstanceList.item(i);
|
||||
|
||||
if (bugInstanceNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element categoryElement = (Element) bugInstanceNode;
|
||||
|
||||
String category = categoryElement.getAttribute("category");
|
||||
String description = categoryElement.getElementsByTagName("Description")
|
||||
.item(0).getTextContent();
|
||||
SpotbugsBugCategory spotbugsBugCategory = new SpotbugsBugCategory()
|
||||
.setCategory(category)
|
||||
.setDescription(description);
|
||||
|
||||
hashMap.put(category,spotbugsBugCategory);
|
||||
}
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
private Map<String, SpotbugsBugPattern> analysisBugPattern(Element element){
|
||||
NodeList bugInstanceList = element.getElementsByTagName("BugPattern");
|
||||
Map<String, SpotbugsBugPattern> hashMap = new HashMap<>();
|
||||
for (int i = 0; i < bugInstanceList.getLength(); i++) {
|
||||
Node bugInstanceNode = bugInstanceList.item(i);
|
||||
|
||||
if (bugInstanceNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element categoryElement = (Element) bugInstanceNode;
|
||||
|
||||
String category = categoryElement.getAttribute("category");
|
||||
String type = categoryElement.getAttribute("type");
|
||||
String abbrev = categoryElement.getAttribute("abbrev");
|
||||
|
||||
String shortDescription = categoryElement.getElementsByTagName("ShortDescription")
|
||||
.item(0).getTextContent();
|
||||
|
||||
String details = categoryElement.getElementsByTagName("Details")
|
||||
.item(0).getTextContent();
|
||||
SpotbugsBugPattern spotbugsBugPattern = new SpotbugsBugPattern()
|
||||
.setCategory(category)
|
||||
.setType(type)
|
||||
.setAbbrev(abbrev)
|
||||
.setShortDescription(shortDescription)
|
||||
.setDetails(details);
|
||||
|
||||
hashMap.put(type, spotbugsBugPattern);
|
||||
}
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
private Map<String, SpotbugsBugCode> analysisBugCode(Element element){
|
||||
NodeList bugInstanceList = element.getElementsByTagName("BugCode");
|
||||
Map<String, SpotbugsBugCode> hashMap = new HashMap<>();
|
||||
for (int i = 0; i < bugInstanceList.getLength(); i++) {
|
||||
Node bugInstanceNode = bugInstanceList.item(i);
|
||||
|
||||
if (bugInstanceNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
Element categoryElement = (Element) bugInstanceNode;
|
||||
|
||||
String cweid = categoryElement.getAttribute("cweid");
|
||||
String abbrev = categoryElement.getAttribute("abbrev");
|
||||
|
||||
String description = categoryElement.getElementsByTagName("Description")
|
||||
.item(0).getTextContent();
|
||||
|
||||
SpotbugsBugCode spotbugsBugCode = new SpotbugsBugCode()
|
||||
.setAbbrev(abbrev)
|
||||
.setCweid(cweid)
|
||||
.setDescription(description);
|
||||
|
||||
hashMap.put(abbrev,spotbugsBugCode);
|
||||
|
||||
}
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
private Map<String,String> findJavaFilePath(String filePath){
|
||||
|
||||
File file = new File(filePath);
|
||||
|
||||
if (!file.exists() || file.isFile()){
|
||||
throw new ApplicationException("文件夹不存在!" + filePath);
|
||||
}
|
||||
|
||||
Map<String , String> map = new HashMap<>();
|
||||
|
||||
List<String> javaPathList = PipelineFileUtil.getFilePath(file, new ArrayList<>());
|
||||
|
||||
for (String javaPath : javaPathList) {
|
||||
if (!javaPath.endsWith(".java")){
|
||||
continue;
|
||||
}
|
||||
String name = new File(javaPath).getName();
|
||||
|
||||
if (StringUtils.isEmpty(map.get(name))){
|
||||
String parent = new File(javaPath).getParent();
|
||||
map.put( parent+"/"+name ,javaPath);
|
||||
}else {
|
||||
map.put(name,javaPath);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package cd.casic.module.process.task.codescan.service.impl;
|
||||
|
||||
/**
|
||||
* @ClassName TaskArtifactXpackServiceImpl
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/3 20:15
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
import cd.casic.ci.commons.bean.process.setting.AuthThird;
|
||||
import cd.casic.ci.commons.bean.utils.PipelineUtil;
|
||||
import cd.casic.ci.commons.rpc.annototion.Exporter;
|
||||
import cd.casic.module.process.process.setting.AuthHostService;
|
||||
import cd.casic.module.process.process.setting.AuthThirdService;
|
||||
import cd.casic.module.process.task.codescan.dao.TaskCodeScanDao;
|
||||
import cd.casic.module.process.task.codescan.dataobject.TaskCodeScanEntity;
|
||||
import cd.casic.module.process.task.codescan.model.TaskCodeScan;
|
||||
import cd.casic.module.process.task.codescan.service.TaskCodeScanService;
|
||||
import cd.casic.module.process.toolkit.beans.BeanMapper;
|
||||
import cd.casic.module.process.toolkit.join.JoinTemplate;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cd.casic.module.process.support.util.util.PipelineFinal.TASK_CODESCAN_SONAR;
|
||||
|
||||
|
||||
@Service
|
||||
@Exporter
|
||||
public class TaskCodeScanServiceImpl implements TaskCodeScanService {
|
||||
|
||||
|
||||
@Resource
|
||||
TaskCodeScanDao codeScanDao;
|
||||
|
||||
@Resource
|
||||
AuthThirdService thirdServer;
|
||||
|
||||
@Resource
|
||||
JoinTemplate joinTemplate;
|
||||
|
||||
@Resource
|
||||
AuthHostService authHostService;
|
||||
|
||||
/**
|
||||
* 创建流水线代码扫描
|
||||
* @param taskCodeScan 流水线代码扫描
|
||||
* @return 流水线代码扫描id
|
||||
*/
|
||||
@Override
|
||||
public String createCodeScan(TaskCodeScan taskCodeScan) {
|
||||
TaskCodeScanEntity taskCodeScanEntity = BeanMapper.map(taskCodeScan, TaskCodeScanEntity.class);
|
||||
return codeScanDao.createCodeScan(taskCodeScanEntity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean codeScanValid(String taskType,TaskCodeScan taskCodeScan){
|
||||
|
||||
if (taskType.equals(TASK_CODESCAN_SONAR)) {
|
||||
if (StringUtils.isEmpty(taskCodeScan.getAuthId())){
|
||||
return false;
|
||||
}
|
||||
String projectName = taskCodeScan.getProjectName();
|
||||
return !StringUtils.isEmpty(projectName);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TaskCodeScan findCodeScanByAuth(String taskId){
|
||||
TaskCodeScan codeScan = findOneCodeScan(taskId);
|
||||
String authId = codeScan.getAuthId();
|
||||
if (!Objects.isNull(authId)){
|
||||
Object auth = authHostService.findOneAuthHost(authId);
|
||||
if (Objects.isNull(auth)){
|
||||
auth = thirdServer.findOneAuthServer(authId);
|
||||
codeScan.setAuth(auth);
|
||||
}
|
||||
codeScan.setAuth(auth);
|
||||
}
|
||||
return codeScan;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除流水线代码扫描
|
||||
* @param CodeScanId 流水线代码扫描id
|
||||
*/
|
||||
@Override
|
||||
public void deleteCodeScan(String CodeScanId) {
|
||||
codeScanDao.deleteCodeScan(CodeScanId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新代码扫描信息
|
||||
* @param taskCodeScan 信息
|
||||
*/
|
||||
@Override
|
||||
public void updateCodeScan(TaskCodeScan taskCodeScan) {
|
||||
TaskCodeScanEntity codeScanEntity = BeanMapper.map(taskCodeScan, TaskCodeScanEntity.class);
|
||||
codeScanDao.updateCodeScan(codeScanEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询代码扫描信息
|
||||
* @param codeScanId id
|
||||
* @return 信息集合
|
||||
*/
|
||||
@Override
|
||||
public TaskCodeScan findOneCodeScan(String codeScanId) {
|
||||
TaskCodeScanEntity oneCodeScan = codeScanDao.findOneCodeScan(codeScanId);
|
||||
TaskCodeScan codeScan = BeanMapper.map(oneCodeScan, TaskCodeScan.class);
|
||||
if (PipelineUtil.isNoNull(codeScan.getAuthId())){
|
||||
AuthThird authServer = thirdServer.findOneAuthServer(codeScan.getAuthId());
|
||||
codeScan.setAuth(authServer);
|
||||
}
|
||||
joinTemplate.joinQuery(codeScan);
|
||||
return codeScan;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有流水线代码扫描
|
||||
* @return 流水线代码扫描列表
|
||||
*/
|
||||
@Override
|
||||
public List<TaskCodeScan> findAllCodeScan() {
|
||||
List<TaskCodeScanEntity> allCodeScan = codeScanDao.findAllCodeScan();
|
||||
return BeanMapper.mapList(allCodeScan, TaskCodeScan.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskCodeScan> findAllCodeScanList(List<String> idList) {
|
||||
List<TaskCodeScanEntity> allCodeScanList = codeScanDao.findAllCodeScanList(idList);
|
||||
List<TaskCodeScan> taskCodeScans = BeanMapper.mapList(allCodeScanList, TaskCodeScan.class);
|
||||
joinTemplate.joinQuery(taskCodeScans);
|
||||
return taskCodeScans;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user