|
@@ -0,0 +1,203 @@
|
|
|
|
|
+package cn.seecoder.web.controller.code_review;
|
|
|
|
|
+
|
|
|
|
|
+import cn.seecoder.common.exceptions.ServiceException;
|
|
|
|
|
+import cn.seecoder.web.model.vo.Response;
|
|
|
|
|
+import cn.seecoder.web.model.vo.code_review.CodeReviewCreateVO;
|
|
|
|
|
+import cn.seecoder.web.model.vo.code_review.CodeReviewSortedList;
|
|
|
|
|
+import cn.seecoder.web.model.vo.code_review.CodeReviewVO;
|
|
|
|
|
+import cn.seecoder.web.model.vo.code_review.FileReviewCreateVO;
|
|
|
|
|
+import cn.seecoder.web.service.code_review.BranchReviewService;
|
|
|
|
|
+import cn.seecoder.web.service.code_review.FileReviewService;
|
|
|
|
|
+import com.nju.edu.gitlab.SeecoderGitlabApi;
|
|
|
|
|
+import com.nju.edu.gitlab.SeecoderGitlabException;
|
|
|
|
|
+import io.swagger.annotations.*;
|
|
|
|
|
+import org.gitlab4j.api.GitLabApiException;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author Zihe Chen
|
|
|
|
|
+ * @date 2022/1/12
|
|
|
|
|
+ * @description:
|
|
|
|
|
+ */
|
|
|
|
|
+@Api(tags = "Code Review相关Api")
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/code_review")
|
|
|
|
|
+public class CodeReviewController {
|
|
|
|
|
+ private final BranchReviewService branchReviewService;
|
|
|
|
|
+ private final FileReviewService fileReviewService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ public CodeReviewController(BranchReviewService branchReviewService, FileReviewService fileReviewService){
|
|
|
|
|
+ this.branchReviewService = branchReviewService;
|
|
|
|
|
+ this.fileReviewService = fileReviewService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/{projectId}")
|
|
|
|
|
+ @ApiOperation(value = "获取一个项目的所有code_review", httpMethod = "GET")
|
|
|
|
|
+ @ApiImplicitParam(value = "projectId", dataType = "int", paramType = "query")
|
|
|
|
|
+ public Response<CodeReviewSortedList> list(@PathVariable("projectId") Integer projectId){
|
|
|
|
|
+ return Response.buildSuccess(branchReviewService.list(projectId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/branch_review")
|
|
|
|
|
+ @ApiOperation(value = "创建一个code_review", httpMethod = "POST")
|
|
|
|
|
+ @ApiImplicitParam(value = "codeReviewCreateVO", dataType = "object", paramType = "body")
|
|
|
|
|
+ public Response createBranchReview(@RequestBody CodeReviewCreateVO codeReviewCreateVO){
|
|
|
|
|
+ try{
|
|
|
|
|
+ branchReviewService.create(codeReviewCreateVO);
|
|
|
|
|
+ return Response.buildSuccess();
|
|
|
|
|
+ } catch (RuntimeException exception) {
|
|
|
|
|
+ return Response.buildFailure(500, exception.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/branch_review/{codeReviewId}")
|
|
|
|
|
+ @ApiOperation(value = "获取某个code_review的详细信息", httpMethod = "GET")
|
|
|
|
|
+ @ApiImplicitParam(value = "codeReviewId", dataType = "int", paramType = "query")
|
|
|
|
|
+ public Response<CodeReviewVO> getBranchReviewById(@PathVariable("codeReviewId") Integer codeReviewId){
|
|
|
|
|
+ return Response.buildSuccess(branchReviewService.getById(codeReviewId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/close/{codeReviewId}")
|
|
|
|
|
+ @ApiOperation(value = "关闭某个code_review", httpMethod = "PUT")
|
|
|
|
|
+ @ApiImplicitParam(value = "codeReviewId", dataType = "int", paramType = "query")
|
|
|
|
|
+ public Response close(@PathVariable("codeReviewId") Integer codeReviewId){
|
|
|
|
|
+ branchReviewService.close(codeReviewId);
|
|
|
|
|
+ return Response.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/reopen/{codeReviewId}")
|
|
|
|
|
+ @ApiOperation(value = "重开某个code_review", httpMethod = "PUT")
|
|
|
|
|
+ @ApiImplicitParam(value = "codeReviewId", dataType = "int", paramType = "query")
|
|
|
|
|
+ public Response reopen(@PathVariable("codeReviewId") Integer codeReviewId){
|
|
|
|
|
+ branchReviewService.reopen(codeReviewId);
|
|
|
|
|
+ return Response.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/merge/{codeReviewId}")
|
|
|
|
|
+ @ApiOperation(value = "合并某个code_review", httpMethod = "PUT")
|
|
|
|
|
+ @ApiImplicitParam(value = "codeReviewId", dataType = "int", paramType = "query")
|
|
|
|
|
+ public Response merge(@PathVariable("codeReviewId") Integer codeReviewId) {
|
|
|
|
|
+ try{
|
|
|
|
|
+ branchReviewService.merge(codeReviewId);
|
|
|
|
|
+ return Response.buildSuccess();
|
|
|
|
|
+ } catch (SeecoderGitlabException | GitLabApiException exception) {
|
|
|
|
|
+ return Response.buildFailure(500, exception.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "获取指定项目的所有branch信息", httpMethod = "GET")
|
|
|
|
|
+ @GetMapping("/branches/{projectId}")
|
|
|
|
|
+ @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query")
|
|
|
|
|
+ public Response getProjectBranches(@PathVariable("projectId") Integer projectId){
|
|
|
|
|
+ try{
|
|
|
|
|
+ return Response.buildSuccess(branchReviewService.getBranches(projectId));
|
|
|
|
|
+ } catch (SeecoderGitlabException exception) {
|
|
|
|
|
+ return Response.buildFailure(500, exception.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation(value = "获取两个分支的比较信息", httpMethod = "GET")
|
|
|
|
|
+ @GetMapping("/compare")
|
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
|
+ @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query"),
|
|
|
|
|
+ @ApiImplicitParam(name = "fromBash", dataType = "String", paramType = "query"),
|
|
|
|
|
+ @ApiImplicitParam(name = "toBash", dataType = "String", paramType = "query")
|
|
|
|
|
+ })
|
|
|
|
|
+ public Response compare(@RequestParam("projectId")Integer projectId, @RequestParam("fromBash")String fromBash,
|
|
|
|
|
+ @RequestParam("toBash") String toBash){
|
|
|
|
|
+ try{
|
|
|
|
|
+ return Response.buildSuccess(branchReviewService.compareBranches(projectId, fromBash, toBash));
|
|
|
|
|
+ } catch (SeecoderGitlabException exception) {
|
|
|
|
|
+ return Response.buildFailure(500, exception.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/file_review")
|
|
|
|
|
+ @ApiOperation(value = "创建一个文件评审任务", httpMethod = "POST")
|
|
|
|
|
+ @ApiImplicitParam(value = "fileReviewCreateVO", dataType = "object", paramType = "body")
|
|
|
|
|
+ public Response createFileReview(@RequestBody FileReviewCreateVO fileReviewCreateVO){
|
|
|
|
|
+ fileReviewService.create(fileReviewCreateVO);
|
|
|
|
|
+ return Response.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/file_review")
|
|
|
|
|
+ @ApiOperation(value = "更新文件列表", httpMethod = "PUT")
|
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
|
+ @ApiImplicitParam(value = "fileReviewId", dataType = "int", paramType = "query"),
|
|
|
|
|
+ @ApiImplicitParam(value = "fileList", dataType = "array", paramType = "query")
|
|
|
|
|
+ })
|
|
|
|
|
+ public Response updateFileList(@RequestParam("fileReviewId") int fileReviewId, @RequestParam("fileList") List<String> fileList){
|
|
|
|
|
+ fileReviewService.updateFileList(fileReviewId, fileList);
|
|
|
|
|
+ return Response.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/file_review/{fileReviewId}")
|
|
|
|
|
+ @ApiOperation(value = "获取一个文件评审任务详细信息", httpMethod = "GET")
|
|
|
|
|
+ @ApiImplicitParam(value = "fileReviewId", dataType = "int", paramType = "query")
|
|
|
|
|
+ public Response getByFileReviewId(@PathVariable("fileReviewId") int fileReviewId){
|
|
|
|
|
+ return Response.buildSuccess(fileReviewService.getById(fileReviewId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/repository_tree")
|
|
|
|
|
+ @ApiOperation(value = "获取仓库文件列表", httpMethod = "GET")
|
|
|
|
|
+ public Response getRepositoryTree(@RequestParam("projectId") int projectId, @RequestParam("branch") String branch,
|
|
|
|
|
+ @RequestParam(value = "path", required = false) String path) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if(path != null) return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch, path));
|
|
|
|
|
+ else return Response.buildSuccess(fileReviewService.getRepositoryTree(projectId, branch));
|
|
|
|
|
+ } catch (IOException exception) {
|
|
|
|
|
+ return Response.buildFailure(500, exception.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/invite")
|
|
|
|
|
+ @ApiOperation(value = "通过手机号码邀请评审人", httpMethod = "GET")
|
|
|
|
|
+ public Response inviteReviewer(@RequestParam("phoneNumber") String phoneNumber) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Response.buildSuccess(fileReviewService.inviteUser(phoneNumber));
|
|
|
|
|
+ } catch (ServiceException exception) {
|
|
|
|
|
+ return Response.buildFailure(exception.getCode(), exception.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/file_content")
|
|
|
|
|
+ @ApiOperation(value = "获取某个文件的内容", httpMethod = "GET")
|
|
|
|
|
+ public Response getFileContent(@RequestParam("projectId") int projectId, @RequestParam("branch") String branch,
|
|
|
|
|
+ @RequestParam("path") String path) {
|
|
|
|
|
+ try{
|
|
|
|
|
+ return Response.buildSuccess(fileReviewService.getFile(projectId, branch, path));
|
|
|
|
|
+ } catch (SeecoderGitlabException exception) {
|
|
|
|
|
+ return Response.buildFailure(500, exception.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/inspect")
|
|
|
|
|
+ @ApiOperation(value = "将某个任务递交评审", httpMethod = "PUT")
|
|
|
|
|
+ public Response submitToInspect(@RequestParam("fileReviewId") int fileReviewId) {
|
|
|
|
|
+ fileReviewService.submitToInspection(fileReviewId);
|
|
|
|
|
+ return Response.buildSuccess();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/rework")
|
|
|
|
|
+ @ApiOperation(value = "将某个任务要求返工修改", httpMethod = "PUT")
|
|
|
|
|
+ public Response submitToRework(@RequestParam("fileReviewId") int fileReviewId, @RequestParam("reviewerId") int reviewerId) {
|
|
|
|
|
+ return Response.buildSuccess(fileReviewService.submitInspection(fileReviewId, reviewerId, 0));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PutMapping("/complete")
|
|
|
|
|
+ @ApiOperation(value = "将某一任务结束", httpMethod = "PUT")
|
|
|
|
|
+ public Response submitToComplete(@RequestParam("fileReviewId") int fileReviewId, @RequestParam("reviewerId") int reviewerId) {
|
|
|
|
|
+ return Response.buildSuccess(fileReviewService.submitInspection(fileReviewId, reviewerId, 1));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/hasInspected")
|
|
|
|
|
+ @ApiOperation(value = "查看评审人员是否已提交结果", httpMethod = "GET")
|
|
|
|
|
+ public Response hasInspected(@RequestParam("fileReviewId") int fileReviewId, @RequestParam("reviewerId") int reviewerId) {
|
|
|
|
|
+ return Response.buildSuccess(fileReviewService.hasInspected(fileReviewId, reviewerId));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|