|
@@ -1,5 +1,6 @@
|
|
|
package cn.seecoder.web.service.impl.codereview;
|
|
package cn.seecoder.web.service.impl.codereview;
|
|
|
|
|
|
|
|
|
|
+import cn.seecoder.common.exceptions.ServiceException;
|
|
|
import cn.seecoder.web.dao.codereview.BranchReviewMapper;
|
|
import cn.seecoder.web.dao.codereview.BranchReviewMapper;
|
|
|
import cn.seecoder.web.model.enums.CodeReviewStatusEnum;
|
|
import cn.seecoder.web.model.enums.CodeReviewStatusEnum;
|
|
|
import cn.seecoder.web.model.enums.CommentTypeEnum;
|
|
import cn.seecoder.web.model.enums.CommentTypeEnum;
|
|
@@ -12,29 +13,18 @@ import cn.seecoder.web.service.codereview.CommentService;
|
|
|
import cn.seecoder.web.service.codereview.FileReviewService;
|
|
import cn.seecoder.web.service.codereview.FileReviewService;
|
|
|
import cn.seecoder.web.service.message.MessageService;
|
|
import cn.seecoder.web.service.message.MessageService;
|
|
|
import cn.seecoder.web.service.user.UserService;
|
|
import cn.seecoder.web.service.user.UserService;
|
|
|
-import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.nju.edu.gitlab.SeecoderGitlabApi;
|
|
import com.nju.edu.gitlab.SeecoderGitlabApi;
|
|
|
import com.nju.edu.gitlab.SeecoderGitlabException;
|
|
import com.nju.edu.gitlab.SeecoderGitlabException;
|
|
|
import com.nju.edu.gitlab.vo.BranchVO;
|
|
import com.nju.edu.gitlab.vo.BranchVO;
|
|
|
import com.nju.edu.gitlab.vo.DiffVO;
|
|
import com.nju.edu.gitlab.vo.DiffVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import okhttp3.*;
|
|
|
|
|
-import org.gitlab4j.api.GitLabApi;
|
|
|
|
|
-import org.gitlab4j.api.GitLabApiException;
|
|
|
|
|
-import org.gitlab4j.api.models.MergeRequest;
|
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -50,7 +40,6 @@ public class BranchReviewServiceImpl implements BranchReviewService {
|
|
|
private final FileReviewService fileReviewService;
|
|
private final FileReviewService fileReviewService;
|
|
|
private final CommentService commentService;
|
|
private final CommentService commentService;
|
|
|
private final SeecoderGitlabApi seecoderGitlabApi;
|
|
private final SeecoderGitlabApi seecoderGitlabApi;
|
|
|
- private OkHttpClient client;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
public BranchReviewServiceImpl(BranchReviewMapper branchReviewMapper, MessageService messageService, FileReviewService fileReviewService,
|
|
public BranchReviewServiceImpl(BranchReviewMapper branchReviewMapper, MessageService messageService, FileReviewService fileReviewService,
|
|
@@ -60,7 +49,6 @@ public class BranchReviewServiceImpl implements BranchReviewService {
|
|
|
this.fileReviewService = fileReviewService;
|
|
this.fileReviewService = fileReviewService;
|
|
|
this.commentService = commentService;
|
|
this.commentService = commentService;
|
|
|
this.seecoderGitlabApi = seecoderGitlabApi;
|
|
this.seecoderGitlabApi = seecoderGitlabApi;
|
|
|
- client = (new OkHttpClient.Builder()).connectTimeout(60L, TimeUnit.SECONDS).writeTimeout(60L, TimeUnit.SECONDS).retryOnConnectionFailure(true).build();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -77,13 +65,13 @@ public class BranchReviewServiceImpl implements BranchReviewService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void create(CodeReviewCreateVO codeReviewCreateVO) throws RuntimeException {
|
|
|
|
|
|
|
+ public void create(CodeReviewCreateVO codeReviewCreateVO) throws ServiceException {
|
|
|
CodeReviewPO codeReviewPO = new CodeReviewPO();
|
|
CodeReviewPO codeReviewPO = new CodeReviewPO();
|
|
|
BeanUtils.copyProperties(codeReviewCreateVO, codeReviewPO);
|
|
BeanUtils.copyProperties(codeReviewCreateVO, codeReviewPO);
|
|
|
List<CodeReviewPO> openedList = branchReviewMapper.selectOpenedReviews(codeReviewCreateVO.getProjectId());
|
|
List<CodeReviewPO> openedList = branchReviewMapper.selectOpenedReviews(codeReviewCreateVO.getProjectId());
|
|
|
for(CodeReviewPO temp : openedList) {
|
|
for(CodeReviewPO temp : openedList) {
|
|
|
if(temp.getTargetBranch().equals(codeReviewCreateVO.getTargetBranch()) && temp.getSourceBranch().equals(codeReviewCreateVO.getSourceBranch())) {
|
|
if(temp.getTargetBranch().equals(codeReviewCreateVO.getTargetBranch()) && temp.getSourceBranch().equals(codeReviewCreateVO.getSourceBranch())) {
|
|
|
- throw new RuntimeException("已存在相同的代码评审任务,无法创建");
|
|
|
|
|
|
|
+ throw new ServiceException("已存在相同的代码评审任务,无法创建");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
codeReviewPO.setStatus(CodeReviewStatusEnum.OPENED);
|
|
codeReviewPO.setStatus(CodeReviewStatusEnum.OPENED);
|
|
@@ -143,11 +131,15 @@ public class BranchReviewServiceImpl implements BranchReviewService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void merge(int id) throws GitLabApiException, SeecoderGitlabException {
|
|
|
|
|
|
|
+ public void merge(int id) throws ServiceException {
|
|
|
UserPO currentUser = UserService.loginUser();
|
|
UserPO currentUser = UserService.loginUser();
|
|
|
CodeReviewPO codeReviewPO = branchReviewMapper.selectById(id);
|
|
CodeReviewPO codeReviewPO = branchReviewMapper.selectById(id);
|
|
|
- seecoderGitlabApi.mergeBranch(codeReviewPO.getProjectId(), codeReviewPO.getSourceBranch(), codeReviewPO.getTargetBranch(),
|
|
|
|
|
- codeReviewPO.getTitle(), codeReviewPO.getDescription(), codeReviewPO.getReviewerId());
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ seecoderGitlabApi.mergeBranch(codeReviewPO.getProjectId(), codeReviewPO.getSourceBranch(), codeReviewPO.getTargetBranch(),
|
|
|
|
|
+ codeReviewPO.getTitle(), codeReviewPO.getDescription(), codeReviewPO.getReviewerId());
|
|
|
|
|
+ } catch (SeecoderGitlabException e) {
|
|
|
|
|
+ throw new ServiceException("合并代码评审失败", e);
|
|
|
|
|
+ }
|
|
|
//数据库操作与对应的评论和消息创建
|
|
//数据库操作与对应的评论和消息创建
|
|
|
branchReviewMapper.merge(id);
|
|
branchReviewMapper.merge(id);
|
|
|
CodeReviewVO codeReviewVO = this.getById(id);
|
|
CodeReviewVO codeReviewVO = this.getById(id);
|
|
@@ -167,18 +159,26 @@ public class BranchReviewServiceImpl implements BranchReviewService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<BranchVO> getBranches(int projectId) throws SeecoderGitlabException {
|
|
|
|
|
- return seecoderGitlabApi.getProjectBranches(projectId);
|
|
|
|
|
|
|
+ public List<BranchVO> getBranches(int projectId) throws ServiceException {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return seecoderGitlabApi.getProjectBranches(projectId);
|
|
|
|
|
+ } catch (SeecoderGitlabException e) {
|
|
|
|
|
+ throw new ServiceException("获取分支列表失败", e);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Set<DiffVO> compareBranches(int projectId, String fromBash, String toBash) throws SeecoderGitlabException {
|
|
|
|
|
|
|
+ public Set<DiffVO> compareBranches(int projectId, String fromBash, String toBash) throws ServiceException {
|
|
|
// ObjectMapper objectMapper = new ObjectMapper();
|
|
// ObjectMapper objectMapper = new ObjectMapper();
|
|
|
// Request request = new Request.Builder().url("https://seecoder-gitlab-server.seec.seecoder.cn/api/project/compare?projectId="+projectId+
|
|
// Request request = new Request.Builder().url("https://seecoder-gitlab-server.seec.seecoder.cn/api/project/compare?projectId="+projectId+
|
|
|
// "&fromBash="+fromBash+"&toBash="+toBash).build();
|
|
// "&fromBash="+fromBash+"&toBash="+toBash).build();
|
|
|
// Response response = client.newCall(request).execute();
|
|
// Response response = client.newCall(request).execute();
|
|
|
// return objectMapper.readTree(response.body().string());
|
|
// return objectMapper.readTree(response.body().string());
|
|
|
log.info("Compare Branch, fromBash : {}, toBash: {}", fromBash, toBash);
|
|
log.info("Compare Branch, fromBash : {}, toBash: {}", fromBash, toBash);
|
|
|
- return seecoderGitlabApi.compare(projectId, fromBash, toBash);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ return seecoderGitlabApi.compare(projectId, fromBash, toBash);
|
|
|
|
|
+ } catch (SeecoderGitlabException e) {
|
|
|
|
|
+ throw new ServiceException("比较分支失败", e);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|