Browse Source

fix: merge error

claws 4 years ago
parent
commit
2843fb1ee9

+ 0 - 132
web/src/main/java/cn/seecoder/web/controller/gitlab/CommitController.java

@@ -1,132 +0,0 @@
-package cn.seecoder.web.controller.gitlab;
-
-import cn.seecoder.common.exceptions.ServiceException;
-import cn.seecoder.web.core.commit.CommitResolver;
-import cn.seecoder.web.core.commit.model.CommitRule;
-import cn.seecoder.web.model.enums.CommitRelatedEnum;
-import cn.seecoder.web.model.po.project.CommitPO;
-import cn.seecoder.web.model.vo.GitWebHookVO;
-import cn.seecoder.web.model.vo.Response;
-import cn.seecoder.web.model.vo.project.CommitVO;
-import cn.seecoder.web.service.bug_list.BugListService;
-import cn.seecoder.web.service.project.CommitService;
-import cn.seecoder.web.service.tree.TreeNodeService;
-import com.nju.edu.gitlab.SeecoderGitlabApi;
-import com.nju.edu.gitlab.SeecoderGitlabException;
-import com.nju.edu.gitlab.vo.BranchVO;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiOperation;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.List;
-
-/**
- * @author chenyz
- * @date 2021/2/4
- * @description: 与GitLab进行交互的接口
- */
-@Api(tags = "GitLab Hook API")
-@RestController
-@Slf4j
-public class CommitController {
-
-    private final BugListService bugListService;
-
-    private final TreeNodeService treeNodeService;
-
-    private final CommitService commitService;
-
-    private final SeecoderGitlabApi seecoderGitlabApi;
-
-    @Autowired
-    public CommitController(BugListService bugListService, TreeNodeService treeNodeService, CommitService commitService, SeecoderGitlabApi seecoderGitlabApi) {
-        this.bugListService = bugListService;
-        this.treeNodeService = treeNodeService;
-        this.commitService = commitService;
-        this.seecoderGitlabApi = seecoderGitlabApi;
-    }
-
-
-    /**
-     * @author chenyz
-     * @date 2021/2/4
-     * @description: 此接口挂载在webhooks的push回调中
-     * todo webhook最多只能获取20个commit
-     *  因为gitlab官方,考虑性能原因导致
-     *  详见 https://docs.gitlab.com/ee/user/project/integrations/webhooks.html push event内容
-     *  暂时无解
-     * 只关注push event
-     * 所有分支的push都分析
-     */
-    @ApiOperation(value = "push回调接口", httpMethod = "POST")
-    @PostMapping("/hook")
-    @ApiImplicitParam(name = "gitWebHookVO",dataType = "object", paramType = "body")
-    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();
-        for (GitWebHookVO.Commit commit: gitWebHookVO.getCommits()){
-            if (commitService.isResolved(commit.getId())){
-                //已经解析过了
-                log.info("Commits 已经解析过了, id: {}", commit.getId());
-                continue;
-            }
-            log.info("resolving commit id : {}, title : {}, message : {}", commit.getId(), commit.getTitle(), commit.getMessage());
-            //todo 注意目前分析的是 message
-            // 应该分析 title 还是 message 与学生的提交规范有关
-            CommitRule rule = CommitResolver.resolve(commit.getMessage());
-            if (rule == null){
-                log.info("Commits 不符合规范, id: {}", commit.getId());
-                continue;
-            }
-            switch (rule.getType()){
-                case FEAT:
-                    treeNodeService.updateNodeState(rule.getId(),rule.getState());
-                    commitService.save(new CommitPO(commit,projectId, CommitRelatedEnum.BUG_ID, rule.getId()));
-                    log.info("Commits 关联tree节点, id: {}", commit.getId());
-                    break;
-                case FIX:
-                    bugListService.updateState(rule.getState(), rule.getId());
-                    commitService.save(new CommitPO(commit,projectId, CommitRelatedEnum.BUG_ID, rule.getId()));
-                    log.info("Commits 关联bug节点, id: {}", commit.getId());
-                    break;
-                case UNKNOWN:
-                    break;
-            }
-        }
-    }
-
-    @ApiOperation(value = "获取某个需求树结点的所有commit信息", httpMethod = "GET")
-    @GetMapping("/commits/tree")
-    @ApiImplicitParam(name = "treeId",dataType = "int", paramType = "query")
-    public Response<List<CommitVO>> getTreeCommits(@RequestParam("treeId") Integer treeId){
-        return Response.buildSuccess(commitService.getTreeCommit(treeId));
-    }
-
-    @ApiOperation(value = "获取bug list中一个bug关联的所有commit信息", httpMethod = "GET")
-    @GetMapping("/commits/bug_list")
-    @ApiImplicitParam(name = "bugId",dataType = "int", paramType = "query")
-    public Response<List<CommitVO>> getBugCommits(@RequestParam("bugId") Integer bugId){
-        return Response.buildSuccess(commitService.getBugCommit(bugId));
-    }
-
-    @ApiOperation(value = "获取指定项目的所有commit信息", httpMethod = "GET")
-    @GetMapping("/commits/list")
-    @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query")
-    public Response<List<CommitVO>> getCommits(@RequestParam("projectId") Integer projectId) {
-        return Response.buildSuccess(commitService.getCommits(projectId));
-    }
-}

+ 27 - 27
web/src/main/java/cn/seecoder/web/infrastructure/config/WebSecurityConfig.java

@@ -139,38 +139,38 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers(PUT, "/tree/node").access("@authTools.checkTreeNodeOwnershipBody(request)")
                 .antMatchers(DELETE, "/tree/node/{nodeId}").access("@authTools.checkTreeNodeOwnership(#nodeId)")
                 // User Controller
-                .antMatchers(HttpMethod.GET, "/users/self").authenticated()
-                .antMatchers(HttpMethod.POST, "/users/gitlab").authenticated()
+                .antMatchers(GET, "/users/self").authenticated()
+                .antMatchers(POST, "/users/gitlab").authenticated()
                 // CodeReviewController
-                .antMatchers(HttpMethod.GET, "/code_review/compare").authenticated()
-                .antMatchers(HttpMethod.GET, "/code_review/{projectId}").authenticated()
+                .antMatchers(GET, "/code_review/compare").authenticated()
+                .antMatchers(GET, "/code_review/{projectId}").authenticated()
                 //BranchReviewRelated
-                .antMatchers(HttpMethod.POST, "/code_review/branch_review").authenticated()
-                .antMatchers(HttpMethod.GET, "/code_review/branches/{projectId}").authenticated()
-                .antMatchers(HttpMethod.GET, "/code_review/branch_review/{codeReviewId}").authenticated()
-                .antMatchers(HttpMethod.PUT, "/code_review/close/{codeReviewId}").authenticated()
-                .antMatchers(HttpMethod.PUT, "/code_review/reopen/{codeReviewId}").authenticated()
-                .antMatchers(HttpMethod.PUT, "/code_review/merge/{codeReviewId}").authenticated()
+                .antMatchers(POST, "/code_review/branch_review").authenticated()
+                .antMatchers(GET, "/code_review/branches/{projectId}").authenticated()
+                .antMatchers(GET, "/code_review/branch_review/{codeReviewId}").authenticated()
+                .antMatchers(PUT, "/code_review/close/{codeReviewId}").authenticated()
+                .antMatchers(PUT, "/code_review/reopen/{codeReviewId}").authenticated()
+                .antMatchers(PUT, "/code_review/merge/{codeReviewId}").authenticated()
                 //FileReviewRelated
-                .antMatchers(HttpMethod.GET, "/code_review/file_review/{fileReviewId}").authenticated()
-                .antMatchers(HttpMethod.POST, "/code_review/file_review").authenticated()
-                .antMatchers(HttpMethod.GET, "/code_review/repository_tree").authenticated()
-                .antMatchers(HttpMethod.GET, "/code_review/invite").authenticated()
-                .antMatchers(HttpMethod.PUT,"/code_review/file_review").authenticated()
-                .antMatchers(HttpMethod.PUT, "/code_review/inspect").authenticated()
-                .antMatchers(HttpMethod.GET, "/code_review/file_content").authenticated()
-                .antMatchers(HttpMethod.PUT, "/code_review/rework").authenticated()
-                .antMatchers(HttpMethod.PUT, "/code_review/complete").authenticated()
-                .antMatchers(HttpMethod.GET, "/code_review/hasInspected").authenticated()
+                .antMatchers(GET, "/code_review/file_review/{fileReviewId}").authenticated()
+                .antMatchers(POST, "/code_review/file_review").authenticated()
+                .antMatchers(GET, "/code_review/repository_tree").authenticated()
+                .antMatchers(GET, "/code_review/invite").authenticated()
+                .antMatchers(PUT,"/code_review/file_review").authenticated()
+                .antMatchers(PUT, "/code_review/inspect").authenticated()
+                .antMatchers(GET, "/code_review/file_content").authenticated()
+                .antMatchers(PUT, "/code_review/rework").authenticated()
+                .antMatchers(PUT, "/code_review/complete").authenticated()
+                .antMatchers(GET, "/code_review/hasInspected").authenticated()
                 //CommentController
-                .antMatchers(HttpMethod.GET, "/comment/{codeReviewId}").authenticated()
-                .antMatchers(HttpMethod.GET, "/comment/listForFileReview/{fileReviewId}").authenticated()
-                .antMatchers(HttpMethod.POST, "/comment/create").authenticated()
-                .antMatchers(HttpMethod.POST, "/comment/createForFileReview").authenticated()
+                .antMatchers(GET, "/comment/{codeReviewId}").authenticated()
+                .antMatchers(GET, "/comment/listForFileReview/{fileReviewId}").authenticated()
+                .antMatchers(POST, "/comment/create").authenticated()
+                .antMatchers(POST, "/comment/createForFileReview").authenticated()
                 //MessageController
-                .antMatchers(HttpMethod.GET, "/message/{receiverId}").authenticated()
-                .antMatchers(HttpMethod.GET, "/message/listByUser").authenticated()
-                .antMatchers(HttpMethod.GET,"/message/read/{messageId}").authenticated()
+                .antMatchers(GET, "/message/{receiverId}").authenticated()
+                .antMatchers(GET, "/message/listByUser").authenticated()
+                .antMatchers(GET,"/message/read/{messageId}").authenticated()
                 // Swagger
                 .antMatchers("/**/*swagger*/**").permitAll()
                 .antMatchers("/**/*api-docs*/**").permitAll()