|
@@ -1,11 +1,17 @@
|
|
|
package cn.seecoder.web.controller.gitlab;
|
|
package cn.seecoder.web.controller.gitlab;
|
|
|
|
|
|
|
|
|
|
+import cn.seecoder.common.exceptions.ServiceException;
|
|
|
|
|
+import cn.seecoder.core.commit.CommitResolver;
|
|
|
|
|
+import cn.seecoder.core.commit.CommitRule;
|
|
|
import cn.seecoder.web.model.enums.CommitRelatedType;
|
|
import cn.seecoder.web.model.enums.CommitRelatedType;
|
|
|
import cn.seecoder.web.model.po.project.CommitPO;
|
|
import cn.seecoder.web.model.po.project.CommitPO;
|
|
|
import cn.seecoder.web.model.vo.GitWebHookVO;
|
|
import cn.seecoder.web.model.vo.GitWebHookVO;
|
|
|
import cn.seecoder.web.service.project.BugListService;
|
|
import cn.seecoder.web.service.project.BugListService;
|
|
|
import cn.seecoder.web.service.project.CommitService;
|
|
import cn.seecoder.web.service.project.CommitService;
|
|
|
import cn.seecoder.web.service.tree.TreeNodeService;
|
|
import cn.seecoder.web.service.tree.TreeNodeService;
|
|
|
|
|
+import com.nju.edu.gitlab.SeecoderGitlabApi;
|
|
|
|
|
+import com.nju.edu.gitlab.SeecoderGitlabException;
|
|
|
|
|
+import com.nju.edu.gitlab.dto.GitlabUserEmailDTO;
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -14,10 +20,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
-import cn.seecoder.core.commit.CommitResolver;
|
|
|
|
|
-import cn.seecoder.core.commit.CommitRule;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author chenyz
|
|
* @author chenyz
|
|
@@ -35,11 +41,14 @@ public class HookController {
|
|
|
|
|
|
|
|
private final CommitService commitService;
|
|
private final CommitService commitService;
|
|
|
|
|
|
|
|
|
|
+ private final SeecoderGitlabApi seecoderGitlabApi;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- public HookController(BugListService bugListService, TreeNodeService treeNodeService, CommitService commitService) {
|
|
|
|
|
|
|
+ public HookController(BugListService bugListService, TreeNodeService treeNodeService, CommitService commitService, SeecoderGitlabApi seecoderGitlabApi) {
|
|
|
this.bugListService = bugListService;
|
|
this.bugListService = bugListService;
|
|
|
this.treeNodeService = treeNodeService;
|
|
this.treeNodeService = treeNodeService;
|
|
|
this.commitService = commitService;
|
|
this.commitService = commitService;
|
|
|
|
|
+ this.seecoderGitlabApi = seecoderGitlabApi;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -55,10 +64,17 @@ public class HookController {
|
|
|
@ApiOperation(value = "push回调接口", httpMethod = "POST")
|
|
@ApiOperation(value = "push回调接口", httpMethod = "POST")
|
|
|
@PostMapping
|
|
@PostMapping
|
|
|
@ApiImplicitParam(name = "gitWebHookVO",dataType = "object", paramType = "body")
|
|
@ApiImplicitParam(name = "gitWebHookVO",dataType = "object", paramType = "body")
|
|
|
- public void pushHook(@RequestBody GitWebHookVO gitWebHookVO)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public void pushHook(@RequestBody GitWebHookVO gitWebHookVO) throws ServiceException {
|
|
|
Integer projectId = gitWebHookVO.getProject_id();
|
|
Integer projectId = gitWebHookVO.getProject_id();
|
|
|
List<GitWebHookVO.Commit> commits = gitWebHookVO.getCommits();
|
|
List<GitWebHookVO.Commit> commits = gitWebHookVO.getCommits();
|
|
|
|
|
+ List<String> emails = commits.stream().map(x->x.getAuthor().getEmail()).collect(Collectors.toList());
|
|
|
|
|
+ List<GitlabUserEmailDTO> users;
|
|
|
|
|
+ try {
|
|
|
|
|
+ users = seecoderGitlabApi.findUserByEmails(emails);
|
|
|
|
|
+ } catch (SeecoderGitlabException e) {
|
|
|
|
|
+ throw new ServiceException("统一代码服务出现访问错误,无法正确分析webhook信息");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String,Integer> userIdMap = users.stream().collect(Collectors.toMap(x->x.getEmail(), x->x.getUserId()));
|
|
|
for (GitWebHookVO.Commit commit:commits){
|
|
for (GitWebHookVO.Commit commit:commits){
|
|
|
if (commitService.isResolved(commit.getId())){
|
|
if (commitService.isResolved(commit.getId())){
|
|
|
//已经解析过了
|
|
//已经解析过了
|
|
@@ -69,14 +85,15 @@ public class HookController {
|
|
|
//不符合规范
|
|
//不符合规范
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ Integer userId = userIdMap.get(commit.getAuthor().getEmail());
|
|
|
switch (rule.getType()){
|
|
switch (rule.getType()){
|
|
|
case FEAT:
|
|
case FEAT:
|
|
|
treeNodeService.updateNodeState(rule.getId(),rule.getState());
|
|
treeNodeService.updateNodeState(rule.getId(),rule.getState());
|
|
|
- commitService.save(new CommitPO(commit,projectId, CommitRelatedType.BUG_ID));
|
|
|
|
|
|
|
+ commitService.save(new CommitPO(commit,projectId, CommitRelatedType.BUG_ID,userId));
|
|
|
break;
|
|
break;
|
|
|
case FIX:
|
|
case FIX:
|
|
|
bugListService.updateState(rule.getState(), rule.getId());
|
|
bugListService.updateState(rule.getState(), rule.getId());
|
|
|
- commitService.save(new CommitPO(commit,projectId, CommitRelatedType.BUG_ID));
|
|
|
|
|
|
|
+ commitService.save(new CommitPO(commit,projectId, CommitRelatedType.BUG_ID,userId));
|
|
|
break;
|
|
break;
|
|
|
case UNKNOWN:
|
|
case UNKNOWN:
|
|
|
break;
|
|
break;
|