|
@@ -10,8 +10,6 @@ import cn.seecoder.web.service.bug_list.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.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;
|
|
@@ -21,10 +19,6 @@ 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 java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author chenyz
|
|
* @author chenyz
|
|
|
* @date 2021/2/4
|
|
* @date 2021/2/4
|
|
@@ -60,22 +54,27 @@ public class HookController {
|
|
|
* 因为gitlab官方,考虑性能原因导致
|
|
* 因为gitlab官方,考虑性能原因导致
|
|
|
* 详见 https://docs.gitlab.com/ee/user/project/integrations/webhooks.html push event内容
|
|
* 详见 https://docs.gitlab.com/ee/user/project/integrations/webhooks.html push event内容
|
|
|
* 暂时无解
|
|
* 暂时无解
|
|
|
|
|
+ * 只关注push event
|
|
|
|
|
+ * 所有分支的push都分析
|
|
|
*/
|
|
*/
|
|
|
@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) throws ServiceException {
|
|
public void pushHook(@RequestBody GitWebHookVO gitWebHookVO) throws ServiceException {
|
|
|
|
|
+
|
|
|
|
|
+//
|
|
|
|
|
+// List<String> emails = new ArrayList<>();
|
|
|
|
|
+// emails.add(gitWebHookVO.getUser_email());
|
|
|
|
|
+// List<GitlabUserEmailDTO> users;
|
|
|
|
|
+// try {
|
|
|
|
|
+// users = seecoderGitlabApi.findUserByEmails(emails);
|
|
|
|
|
+// } catch (SeecoderGitlabException e) {
|
|
|
|
|
+// throw new ServiceException("统一代码服务出现访问错误,无法正确分析webhook信息");
|
|
|
|
|
+// }
|
|
|
|
|
+// Integer userId = users.size()!=0 ? users.get(0).getUserId() : null;
|
|
|
|
|
+
|
|
|
Integer projectId = gitWebHookVO.getProject_id();
|
|
Integer projectId = gitWebHookVO.getProject_id();
|
|
|
- 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: gitWebHookVO.getCommits()){
|
|
|
if (commitService.isResolved(commit.getId())){
|
|
if (commitService.isResolved(commit.getId())){
|
|
|
//已经解析过了
|
|
//已经解析过了
|
|
|
continue;
|
|
continue;
|
|
@@ -85,15 +84,14 @@ 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, CommitRelatedEnum.BUG_ID,userId));
|
|
|
|
|
|
|
+ commitService.save(new CommitPO(commit,projectId, CommitRelatedEnum.BUG_ID));
|
|
|
break;
|
|
break;
|
|
|
case FIX:
|
|
case FIX:
|
|
|
bugListService.updateState(rule.getState(), rule.getId());
|
|
bugListService.updateState(rule.getState(), rule.getId());
|
|
|
- commitService.save(new CommitPO(commit,projectId, CommitRelatedEnum.BUG_ID,userId));
|
|
|
|
|
|
|
+ commitService.save(new CommitPO(commit,projectId, CommitRelatedEnum.BUG_ID));
|
|
|
break;
|
|
break;
|
|
|
case UNKNOWN:
|
|
case UNKNOWN:
|
|
|
break;
|
|
break;
|