|
|
@@ -18,6 +18,7 @@ import com.nju.edu.gitlab.SeecoderGitlabApi;
|
|
|
import com.nju.edu.gitlab.SeecoderGitlabException;
|
|
|
import com.nju.edu.gitlab.vo.BranchVO;
|
|
|
import com.nju.edu.gitlab.vo.DiffVO;
|
|
|
+import cn.seecoder.seecoderlog.utils.SeecoderLogUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.*;
|
|
|
import org.gitlab4j.api.GitLabApi;
|
|
|
@@ -146,24 +147,65 @@ public class BranchReviewServiceImpl implements BranchReviewService {
|
|
|
public void merge(int id) throws GitLabApiException, SeecoderGitlabException {
|
|
|
UserPO currentUser = UserService.loginUser();
|
|
|
CodeReviewPO codeReviewPO = branchReviewMapper.selectById(id);
|
|
|
- seecoderGitlabApi.mergeBranch(codeReviewPO.getProjectId(), codeReviewPO.getSourceBranch(), codeReviewPO.getTargetBranch(),
|
|
|
- codeReviewPO.getTitle(), codeReviewPO.getDescription(), codeReviewPO.getReviewerId());
|
|
|
- //数据库操作与对应的评论和消息创建
|
|
|
- branchReviewMapper.merge(id);
|
|
|
- CodeReviewVO codeReviewVO = this.getById(id);
|
|
|
- CommentCreateVO commentCreateVO = new CommentCreateVO();
|
|
|
- commentCreateVO.setCodeReviewId(id);
|
|
|
- commentCreateVO.setCommentType(CommentTypeEnum.MERGE);
|
|
|
- commentCreateVO.setCreatorId(currentUser.getId());
|
|
|
- commentCreateVO.setCreatorName(currentUser.getUsername());
|
|
|
- commentCreateVO.setReplyId(-1);
|
|
|
- commentService.create(commentCreateVO, false);
|
|
|
- MessageCreateVO messageCreateVO = new MessageCreateVO();
|
|
|
- messageCreateVO.setCreatorId(currentUser.getId());
|
|
|
- messageCreateVO.setReceiverId(codeReviewVO.getCreatorId());
|
|
|
- messageCreateVO.setContent("代码评审任务\""+codeReviewVO.getTitle()+"\"已被合并");
|
|
|
- messageCreateVO.setLinkTo("/project/"+codeReviewVO.getProjectId()+"/codereviewdetail?codeReviewId="+id);
|
|
|
- messageService.create(messageCreateVO);
|
|
|
+ try {
|
|
|
+ seecoderGitlabApi.mergeBranch(codeReviewPO.getProjectId(), codeReviewPO.getSourceBranch(), codeReviewPO.getTargetBranch(),
|
|
|
+ codeReviewPO.getTitle(), codeReviewPO.getDescription(), codeReviewPO.getReviewerId());
|
|
|
+ //数据库操作与对应的评论和消息创建
|
|
|
+ branchReviewMapper.merge(id);
|
|
|
+ CodeReviewVO codeReviewVO = this.getById(id);
|
|
|
+ CommentCreateVO commentCreateVO = new CommentCreateVO();
|
|
|
+ commentCreateVO.setCodeReviewId(id);
|
|
|
+ commentCreateVO.setCommentType(CommentTypeEnum.MERGE);
|
|
|
+ commentCreateVO.setCreatorId(currentUser.getId());
|
|
|
+ commentCreateVO.setCreatorName(currentUser.getUsername());
|
|
|
+ commentCreateVO.setReplyId(-1);
|
|
|
+ commentService.create(commentCreateVO, false);
|
|
|
+ MessageCreateVO messageCreateVO = new MessageCreateVO();
|
|
|
+ messageCreateVO.setCreatorId(currentUser.getId());
|
|
|
+ messageCreateVO.setReceiverId(codeReviewVO.getCreatorId());
|
|
|
+ messageCreateVO.setContent("代码评审任务\""+codeReviewVO.getTitle()+"\"已被合并");
|
|
|
+ messageCreateVO.setLinkTo("/project/"+codeReviewVO.getProjectId()+"/codereviewdetail?codeReviewId="+id);
|
|
|
+ messageService.create(messageCreateVO);
|
|
|
+
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ long taskDurationMs = now - codeReviewPO.getCreateTime().getTime();
|
|
|
+ SeecoderLogUtils.info(
|
|
|
+ "D4_TASK_COMPLETED",
|
|
|
+ "taskType=branchReview",
|
|
|
+ "taskId=" + id,
|
|
|
+ "projectId=" + codeReviewVO.getProjectId(),
|
|
|
+ "operatorId=" + currentUser.getId(),
|
|
|
+ "taskDurationMs=" + taskDurationMs,
|
|
|
+ "completedTs=" + now
|
|
|
+ );
|
|
|
+ SeecoderLogUtils.info(
|
|
|
+ "D4_COLLAB_EFFECTIVE",
|
|
|
+ "source=branchReviewMerge",
|
|
|
+ "taskId=" + id,
|
|
|
+ "projectId=" + codeReviewVO.getProjectId(),
|
|
|
+ "operatorId=" + currentUser.getId(),
|
|
|
+ "ts=" + now
|
|
|
+ );
|
|
|
+ } catch (SeecoderGitlabException e) {
|
|
|
+ SeecoderLogUtils.warn(
|
|
|
+ "D4_COLLAB_CONFLICT_CREATED",
|
|
|
+ "conflictType=branchMerge",
|
|
|
+ "taskId=" + id,
|
|
|
+ "projectId=" + codeReviewPO.getProjectId(),
|
|
|
+ "operatorId=" + currentUser.getId(),
|
|
|
+ "reason=" + e.getClass().getSimpleName(),
|
|
|
+ "ts=" + System.currentTimeMillis()
|
|
|
+ );
|
|
|
+ SeecoderLogUtils.error(
|
|
|
+ e,
|
|
|
+ "D4_COLLAB_CONFLICT_CREATED",
|
|
|
+ "conflictType=branchMerge",
|
|
|
+ "taskId=" + id,
|
|
|
+ "projectId=" + codeReviewPO.getProjectId(),
|
|
|
+ "operatorId=" + currentUser.getId()
|
|
|
+ );
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|