Skip to content

Commit

Permalink
功能优化 (#11)
Browse files Browse the repository at this point in the history
功能优化
  • Loading branch information
languyue authored Feb 10, 2025
1 parent 18cb9ff commit dfc5d26
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum ErrorCode {
NOT_FIND_PIPELINE(HttpStatus.BAD_REQUEST, "Pipeline.000015", "当前流水线不存在"),
CREATE_BRANCH_ERROR(HttpStatus.BAD_REQUEST, "Pipeline.000016", "创建分支失败"),
PIPELINE_RUNNING_NOT_DELETE_PUBLISH(HttpStatus.INTERNAL_SERVER_ERROR, "Pipeline.000017", "流水线正在运行,无法删除发布分支"),
PIPELINE_NOT_BIND_SERVICE(HttpStatus.BAD_REQUEST, "Pipeline.000018", "流水线不属于当前服务"),
PIPELINE_NOT_BELONG_SERVICE(HttpStatus.BAD_REQUEST, "Pipeline.000018", "流水线不属于当前服务"),
RUN_PIPELINE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Pipeline.000019", "流水线任务调度失败,请稍后重试"),
SERVICE_CREATE_PUBLISH_PIPELINE(HttpStatus.INTERNAL_SERVER_ERROR, "Pipeline.000020", "当前服务未创建发布流水线,无法推送发布"),
/*==================Service服务==================*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* 对象拷贝
Expand All @@ -17,7 +18,7 @@ public static <T> T convert(Object source, Class<T> target) {
}

public static <S, D> List<D> convertList(Iterable<S> source, Class<D> target) {
if (source == null) {
if (Objects.isNull(source)) {
return Collections.emptyList();
}
return mapperFactory.getMapperFacade().mapAsList(source, target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
@Data
public class BugBO {

private Long id;

/**
* bug名称
* */
Expand Down Expand Up @@ -50,6 +52,11 @@ public class BugBO {
* */
private String proposer;

/**
* 工作量
*/
private Integer workload;

/**
* 接受人名称
* */
Expand Down Expand Up @@ -81,26 +88,21 @@ public class BugBO {
private Integer status;

/**
* 需求ID
* 空间ID
*/
private String relationId;
private String spaceId;

/**
* 空间ID
* 需求ID
*/
private String spaceId;
private String relationId;

/**
* 迭代ID
*/
private String iterationId;


/**
* 工作量
*/
private Integer workload;

/**
* 创建时间
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@Data
public class DispatchLogBO {

private Long id;

/**
* 日志Id
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@Data
public class NodeBindBO {

private Long id;

/**
* 流水线执行点ID
*/
Expand All @@ -26,7 +28,6 @@ public class NodeBindBO {
*/
private String description;

//todo 这个时接口参数不是数据库参数
private List<String> executors;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@Data
public class NodeRecordBO {

private Long id;

/**
* 流水线节点Id
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
@Data
public class PipelineActionBO {

private Long id;

/**
* 执行动作Id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
import com.zj.common.entity.pipeline.PipelineConfig;
import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
Expand All @@ -16,6 +12,8 @@
@Data
public class PipelineBO {

private Long id;

/**
* 流水线Id
*/
Expand All @@ -24,13 +22,11 @@ public class PipelineBO {
/**
* 流水线名称
*/
@NotEmpty(message = "流水线名称不能为空")
private String pipelineName;

/**
* 服务Id
*/
@NotEmpty(message = "服务Id不能为空")
private String serviceId;

/**
Expand All @@ -41,17 +37,11 @@ public class PipelineBO {
/**
* 流水线类型
*/
@NotNull(message = "流水线类型不能为空")
@Min(1)
@Max(3)
private Integer pipelineType;

/**
* 执行方式
* */
@NotNull(message = "执行方式不能为空")
@Min(1)
@Max(3)
private Integer executeType;

/**
Expand All @@ -64,6 +54,5 @@ public class PipelineBO {
*/
private Integer pipelineStatus;

@NotEmpty
private List<PipelineStageBO> stageList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@ public class Bug {
* */
private String proposerName;

/**
* 提出人
* */
private String proposer;

/**
* 工作量
*/
private Integer workload;

/**
* 提出人
* */
private String proposer;

/**
* 接受人名称
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@Getter
public enum GitEventType {
COMMIT("push", "代码提交");
PUSH("push", "代码提交");

private final String type;
private final String desc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public GitPushResultVo webhook(String data, HttpServletRequest request) {
log.info("can not find service by git url={}", gitPushResultVo.getRepository());
return null;
}

//如果没有流水线执行就直接退出
gitPushResultVo.setRelatedServiceId(microservice.getServiceId());
List<PipelineBO> pushPipelines = getServicePipelineByType(microservice, gitPushResultVo, PipelineExecuteType.PUSH);
if (CollectionUtils.isEmpty(pushPipelines)){
return null;
return gitPushResultVo;
}

//根据当前推送的分支查找关联的流水线,然后执行
Expand All @@ -77,8 +78,6 @@ public GitPushResultVo webhook(String data, HttpServletRequest request) {
log.info("web hook trigger pipeline execute pipeline={}", pipeline.getPipelineId());
}
}));

gitPushResultVo.setRelatedServiceId(microservice.getServiceId());
return gitPushResultVo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public GitPushResultVo analyzeData(String data, HttpServletRequest request) {
String branch = getBranchFromHookData(giteaHookVo.getRef());
log.info("get repository name={} branch name={}", name, branch);
return GitPushResultVo.builder().repository(name).branch(branch).gitType(PlatformEnum.gitea.name())
.eventType(GitEventType.COMMIT.getType()).build();
.eventType(GitEventType.PUSH.getType()).build();
}

private boolean checkSecret(HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public GitPushResultVo analyzeData(String data, HttpServletRequest request) {
return GitPushResultVo.builder().repository(repository.getRepository())
.gitType(PlatformEnum.github.name())
.branch(branch)
.eventType(GitEventType.COMMIT.getType()).build();
.eventType(GitEventType.PUSH.getType()).build();
}

private boolean checkSignature(String data, HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,29 @@ public PipelineHistoryRest(PipelineHistoryService historyService) {

@ResponseBody
@GetMapping("/history/{historyId}")
public ResponseMeta<PipelineHistoryBO> queryPipelineHistory(
@NotNull @PathVariable("historyId") String historyId) {
return new ResponseMeta<PipelineHistoryBO>(ErrorCode.SUCCESS,
historyService.getPipelineHistory(historyId));
public ResponseMeta<PipelineHistoryBO> queryPipelineHistory(@Validated @NotNull @PathVariable("historyId") String historyId) {
return new ResponseMeta<PipelineHistoryBO>(ErrorCode.SUCCESS, historyService.getPipelineHistory(historyId));
}

@ResponseBody
@PostMapping("/history")
public ResponseMeta<String> createPipelineHistory(
@NotNull @Validated @RequestBody PipelineHistoryBO pipelineHistoryBO) {
return new ResponseMeta<String>(ErrorCode.SUCCESS,
historyService.createPipelineHistory(pipelineHistoryBO));
return new ResponseMeta<String>(ErrorCode.SUCCESS, historyService.createPipelineHistory(pipelineHistoryBO));
}

@ResponseBody
@GetMapping("/{pipelineId}/histories")
public ResponseMeta<List<PipelineHistoryBO>> listPipelineHistories(
@NotNull @PathVariable("pipelineId") String pipelineId) {
return new ResponseMeta<List<PipelineHistoryBO>>(ErrorCode.SUCCESS,
historyService.listPipelineHistories(pipelineId));
public ResponseMeta<List<PipelineHistoryBO>> listPipelineHistories(@NotNull @PathVariable("pipelineId") String pipelineId) {
return new ResponseMeta<List<PipelineHistoryBO>>(ErrorCode.SUCCESS, historyService.listPipelineHistories(pipelineId));
}

@ResponseBody
@GetMapping("/{service}/{pipelineId}/latest/history")
public ResponseMeta<PipelineHistoryBO> getLatestPipelineHistory(
@PathVariable("service") String service,
@PathVariable("pipelineId") String pipelineId) {
public ResponseMeta<PipelineHistoryBO> getLatestPipelineHistory(@PathVariable("service") String service,
@PathVariable("pipelineId") String pipelineId) {
return new ResponseMeta<PipelineHistoryBO>(ErrorCode.SUCCESS,
historyService.getLatestPipelineHistory(pipelineId));
historyService.getLatestPipelineHistory(service, pipelineId));
}

@ResponseBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,15 @@ public Boolean deleteCodeChange(String serviceId, String codeChangeId) {
}

public List<RelationDemandBug> queryRelationIds(String queryName) {
CompletableFuture<List<BugBO>> bugFuture =
CompletableFuture.supplyAsync(() -> bugRepository.getBugsFuzzyByName(queryName));
CompletableFuture<List<DemandBO>> demandFuture =
CompletableFuture.supplyAsync(() -> demandRepository.getDemandsByFuzzName(queryName));
CompletableFuture<List<WorkTaskBO>> workFuture =
CompletableFuture.supplyAsync(() -> workTaskRepository.getWorkTaskByName(queryName));
CompletableFuture.allOf(bugFuture, demandFuture, workFuture).join();
List<BugBO> bugs = bugRepository.getBugsFuzzyByName(queryName);
List<DemandBO> demands = demandRepository.getDemandsByFuzzName(queryName);
List<WorkTaskBO> works = workTaskRepository.getWorkTaskByName(queryName);
try {
List<RelationDemandBug> relationList =
bugFuture.get().stream().map(bug -> new RelationDemandBug(bug.getBugId(),
List<RelationDemandBug> relationList = bugs.stream().map(bug -> new RelationDemandBug(bug.getBugId(),
RelationType.BUG.getType(), bug.getBugName())).collect(Collectors.toList());
List<RelationDemandBug> relationDemands =
demandFuture.get().stream().map(demand -> new RelationDemandBug(demand.getDemandId(),
List<RelationDemandBug> relationDemands = demands.stream().map(demand -> new RelationDemandBug(demand.getDemandId(),
RelationType.DEMAND.getType(), demand.getDemandName())).collect(Collectors.toList());
List<RelationDemandBug> relationWorks =
workFuture.get().stream().map(work -> new RelationDemandBug(work.getTaskId(),
List<RelationDemandBug> relationWorks = works.stream().map(work -> new RelationDemandBug(work.getTaskId(),
RelationType.WORK.getType(), work.getTaskName())).collect(Collectors.toList());
relationList.addAll(relationDemands);
relationList.addAll(relationWorks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private String getBodyString(HttpServletRequest request){

private void updateProcessStatusIfNeed(GitPushResultVo gitPushResultVo) {
try {
if (Objects.nonNull(gitPushResultVo) && Objects.equals(gitPushResultVo.getEventType(), GitEventType.COMMIT.getType())) {
if (Objects.nonNull(gitPushResultVo) && Objects.equals(gitPushResultVo.getEventType(), GitEventType.PUSH.getType())) {
List<CodeChangeBO> codeChanges = codeChangeRepository.getServiceChanges(gitPushResultVo.getRelatedServiceId());
List<String> demandCodeChanges = codeChanges.stream().filter(codeChange ->
Objects.equals(RelationType.DEMAND.getType(), codeChange.getRelationType()))
Expand Down
Loading

0 comments on commit dfc5d26

Please sign in to comment.