|
|
@@ -2,7 +2,13 @@ package cn.seecoder.web.service.impl.project;
|
|
|
|
|
|
import cn.seecoder.web.dao.user.UserMapper;
|
|
|
import cn.seecoder.web.model.enums.CommitRelatedEnum;
|
|
|
+import cn.seecoder.web.model.po.bug_list.BugListPO;
|
|
|
+import cn.seecoder.web.model.po.tree.TreeNodePO;
|
|
|
+import cn.seecoder.web.model.vo.bug_list.BugListVO;
|
|
|
import cn.seecoder.web.model.vo.project.CommitVO;
|
|
|
+import cn.seecoder.web.model.vo.tree.TreeNodeVO;
|
|
|
+import cn.seecoder.web.service.bug_list.BugListService;
|
|
|
+import cn.seecoder.web.service.tree.TreeNodeService;
|
|
|
import com.nju.edu.gitlab.SeecoderGitlabApi;
|
|
|
import com.nju.edu.gitlab.vo.DiffVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -11,10 +17,7 @@ import cn.seecoder.web.dao.project.CommitMapper;
|
|
|
import cn.seecoder.web.model.po.project.CommitPO;
|
|
|
import cn.seecoder.web.service.project.CommitService;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -27,12 +30,16 @@ public class CommitServiceImpl implements CommitService {
|
|
|
|
|
|
private final CommitMapper commitMapper;
|
|
|
private final SeecoderGitlabApi seecoderGitlabApi;
|
|
|
+ private final TreeNodeService treeNodeService;
|
|
|
+ private final BugListService bugListService;
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
- public CommitServiceImpl(CommitMapper commitMapper, SeecoderGitlabApi seecoderGitlabApi) {
|
|
|
+ public CommitServiceImpl(CommitMapper commitMapper, SeecoderGitlabApi seecoderGitlabApi, TreeNodeService treeNodeService, BugListService bugListService) {
|
|
|
this.commitMapper = commitMapper;
|
|
|
this.seecoderGitlabApi = seecoderGitlabApi;
|
|
|
+ this.treeNodeService = treeNodeService;
|
|
|
+ this.bugListService = bugListService;
|
|
|
}
|
|
|
|
|
|
@Autowired
|
|
|
@@ -82,7 +89,17 @@ public class CommitServiceImpl implements CommitService {
|
|
|
try{
|
|
|
List<com.nju.edu.gitlab.vo.commit.CommitVO> commitsResponse = seecoderGitlabApi.getCommitsByBranch(projectId, "master");
|
|
|
for (com.nju.edu.gitlab.vo.commit.CommitVO commit : commitsResponse){
|
|
|
- allCommits.add(new CommitVO(commit));
|
|
|
+ CommitVO commitVO = new CommitVO(commit);
|
|
|
+ CommitPO commitPO = commitMapper.selectByCommitId(commitVO.getId());
|
|
|
+ if (commitPO != null){
|
|
|
+// System.out.println(commitPO.getId());
|
|
|
+ commitVO.setRelatedType(commitPO.getRelatedType());
|
|
|
+ commitVO.setRelatedId(commitPO.getRelatedId());
|
|
|
+ } else {
|
|
|
+// System.out.println("hh");
|
|
|
+ commitVO.setRelatedType(CommitRelatedEnum.NONE);
|
|
|
+ }
|
|
|
+ allCommits.add(commitVO);
|
|
|
}
|
|
|
|
|
|
} catch (Exception e){
|
|
|
@@ -97,7 +114,17 @@ public class CommitServiceImpl implements CommitService {
|
|
|
public CommitVO getCommitByHash(Integer projectId, String hash) {
|
|
|
try {
|
|
|
com.nju.edu.gitlab.vo.commit.CommitVO commit = seecoderGitlabApi.getCommitByHash(projectId, hash);
|
|
|
- return new CommitVO(commit);
|
|
|
+ CommitVO commitVO = new CommitVO(commit);
|
|
|
+ CommitPO commitPO = commitMapper.selectByCommitId(hash);
|
|
|
+ if (commitPO != null){
|
|
|
+ System.out.println(commitPO.getId());
|
|
|
+ commitVO.setRelatedType(commitPO.getRelatedType());
|
|
|
+ commitVO.setRelatedId(commitPO.getRelatedId());
|
|
|
+ } else {
|
|
|
+ System.out.println("hh");
|
|
|
+ commitVO.setRelatedType(CommitRelatedEnum.NONE);
|
|
|
+ }
|
|
|
+ return commitVO;
|
|
|
} catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return null;
|
|
|
@@ -114,4 +141,48 @@ public class CommitServiceImpl implements CommitService {
|
|
|
}
|
|
|
return new HashSet<>();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean link(Integer projectId, String commitHash, CommitRelatedEnum relatedType, Integer relatedId) {
|
|
|
+ // check if the related target exists
|
|
|
+ if (relatedType == CommitRelatedEnum.TREE_ID){
|
|
|
+ TreeNodePO node = treeNodeService.getNodeByNodeId(relatedId);
|
|
|
+ if (node == null){
|
|
|
+ return false;
|
|
|
+ } else if (! node.getProjectId().equals(projectId)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ BugListPO node = bugListService.getBugById(relatedId);
|
|
|
+ if (node == null){
|
|
|
+ return false;
|
|
|
+ } else if (! node.getProjectId().equals(projectId)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // check if the commit is already exist, then update it. if not, insert a new one.
|
|
|
+ CommitPO commitPODB = commitMapper.selectByCommitId(commitHash);
|
|
|
+ if (commitPODB != null){
|
|
|
+ commitPODB.setRelatedType(relatedType);
|
|
|
+ commitPODB.setRelatedId(relatedId);
|
|
|
+ commitMapper.update(commitPODB);
|
|
|
+ } else {
|
|
|
+ CommitVO commit = this.getCommitByHash(projectId, commitHash);
|
|
|
+
|
|
|
+ CommitPO commitPO = new CommitPO();
|
|
|
+ commitPO.setId(commit.getId());
|
|
|
+ commitPO.setMessage(commit.getMessage());
|
|
|
+ commitPO.setTitle(commit.getTitle());
|
|
|
+ commitPO.setProjectId(projectId);
|
|
|
+// commitPO.setTimestamp(commit.getTimestamp());
|
|
|
+ commitPO.setGitlabUsername(commit.getGitlabUsername());
|
|
|
+ commitPO.setEmail(commit.getAuthorEmail());
|
|
|
+ commitPO.setRelatedType(relatedType);
|
|
|
+ commitPO.setRelatedId(relatedId);
|
|
|
+
|
|
|
+ this.save(commitPO);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|