|
@@ -1,13 +1,18 @@
|
|
|
package cn.seecoder.web.controller.commit;
|
|
package cn.seecoder.web.controller.commit;
|
|
|
|
|
|
|
|
|
|
+import cn.seecoder.common.exceptions.ServiceException;
|
|
|
|
|
+import cn.seecoder.web.model.enums.CommitRelatedEnum;
|
|
|
import cn.seecoder.web.model.vo.Response;
|
|
import cn.seecoder.web.model.vo.Response;
|
|
|
|
|
+import cn.seecoder.web.model.vo.commit.CommitQualityVO;
|
|
|
import cn.seecoder.web.model.vo.commit.CommitVO;
|
|
import cn.seecoder.web.model.vo.commit.CommitVO;
|
|
|
|
|
+import cn.seecoder.web.model.vo.commit.GitWebHookVO;
|
|
|
|
|
+import cn.seecoder.web.model.vo.hook.SonarResultHookVO;
|
|
|
|
|
+import cn.seecoder.web.service.branch.BranchService;
|
|
|
|
|
+import cn.seecoder.web.service.commit.CommitLinkService;
|
|
|
|
|
+import cn.seecoder.web.service.commit.CommitQualityService;
|
|
|
import cn.seecoder.web.service.commit.CommitService;
|
|
import cn.seecoder.web.service.commit.CommitService;
|
|
|
|
|
+import com.nju.edu.gitlab.vo.BranchVO;
|
|
|
import com.nju.edu.gitlab.vo.DiffVO;
|
|
import com.nju.edu.gitlab.vo.DiffVO;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
|
|
-import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
-import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -20,51 +25,122 @@ import java.util.Set;
|
|
|
* @date 2021/2/4
|
|
* @date 2021/2/4
|
|
|
* @description: 提交管理接口
|
|
* @description: 提交管理接口
|
|
|
*/
|
|
*/
|
|
|
-@Api(tags = "Commit Manage API")
|
|
|
|
|
|
|
+
|
|
|
@RestController
|
|
@RestController
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class CommitController {
|
|
public class CommitController {
|
|
|
private final CommitService commitService;
|
|
private final CommitService commitService;
|
|
|
|
|
|
|
|
|
|
+ private final BranchService branchService;
|
|
|
|
|
+
|
|
|
|
|
+ private final CommitLinkService commitLinkService;
|
|
|
|
|
+
|
|
|
|
|
+ private final CommitQualityService commitQualityService;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- public CommitController(CommitService commitService) {
|
|
|
|
|
|
|
+ public CommitController(CommitService commitService,BranchService branchService,CommitLinkService commitLinkService,CommitQualityService commitQualityService) {
|
|
|
this.commitService = commitService;
|
|
this.commitService = commitService;
|
|
|
|
|
+ this.branchService = branchService;
|
|
|
|
|
+ this.commitLinkService = commitLinkService;
|
|
|
|
|
+ this.commitQualityService = commitQualityService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "获取指定项目指定分支所有的commit信息", httpMethod = "GET")
|
|
|
|
|
|
|
+ private final static String GET_BRANCHES_ERROR = "Fail to search all branches";
|
|
|
|
|
+
|
|
|
|
|
+ private final static String LINK_FAIL_ERROR = "Commit Link Failed! No Such Bug or Task!";
|
|
|
|
|
+
|
|
|
|
|
+ private final static String QUALITY_QUERY_ERROR = "查询代码版本质量失败";
|
|
|
|
|
+
|
|
|
@GetMapping("/commits/by_branch")
|
|
@GetMapping("/commits/by_branch")
|
|
|
- @ApiImplicitParams({
|
|
|
|
|
- @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query"),
|
|
|
|
|
- @ApiImplicitParam(name = "branchName", dataType = "String", paramType = "query")
|
|
|
|
|
- })
|
|
|
|
|
public Response<List<CommitVO>> getCommitsByBranch(@RequestParam("projectId") Integer projectId,
|
|
public Response<List<CommitVO>> getCommitsByBranch(@RequestParam("projectId") Integer projectId,
|
|
|
@RequestParam("branchName") String branchName){
|
|
@RequestParam("branchName") String branchName){
|
|
|
return Response.buildSuccess(commitService.getCommitsByBranchName(projectId, branchName));
|
|
return Response.buildSuccess(commitService.getCommitsByBranchName(projectId, branchName));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "获得一个commit的信息", httpMethod = "GET")
|
|
|
|
|
|
|
+
|
|
|
@GetMapping("/commit")
|
|
@GetMapping("/commit")
|
|
|
- @ApiImplicitParams({
|
|
|
|
|
- @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query"),
|
|
|
|
|
- @ApiImplicitParam(name = "hash", dataType = "String", paramType = "query")
|
|
|
|
|
- })
|
|
|
|
|
public Response<CommitVO> getCommitByHash(@RequestParam("projectId") Integer projectId,
|
|
public Response<CommitVO> getCommitByHash(@RequestParam("projectId") Integer projectId,
|
|
|
@RequestParam("hash") String hash)
|
|
@RequestParam("hash") String hash)
|
|
|
{
|
|
{
|
|
|
return Response.buildSuccess(commitService.getCommitByHash(projectId, hash));
|
|
return Response.buildSuccess(commitService.getCommitByHash(projectId, hash));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @ApiOperation(value = "获得两个提交之间的差异", httpMethod = "GET")
|
|
|
|
|
|
|
+
|
|
|
@GetMapping("/commits/diff")
|
|
@GetMapping("/commits/diff")
|
|
|
- @ApiImplicitParams({
|
|
|
|
|
- @ApiImplicitParam(name = "projectId", dataType = "int", paramType = "query"),
|
|
|
|
|
- @ApiImplicitParam(name = "from", dataType = "String", paramType = "query"),
|
|
|
|
|
- @ApiImplicitParam(name = "to", dataType = "String", paramType = "query")
|
|
|
|
|
- })
|
|
|
|
|
public Response<Set<DiffVO>> getDiff(@RequestParam("projectId") Integer projectId,
|
|
public Response<Set<DiffVO>> getDiff(@RequestParam("projectId") Integer projectId,
|
|
|
@RequestParam("from") String from,
|
|
@RequestParam("from") String from,
|
|
|
@RequestParam("to") String to)
|
|
@RequestParam("to") String to)
|
|
|
{
|
|
{
|
|
|
return Response.buildSuccess(commitService.getDiff(projectId, from, to));
|
|
return Response.buildSuccess(commitService.getDiff(projectId, from, to));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/branch/list")
|
|
|
|
|
+ public Response<Object> getAllBranches(@RequestParam("projectId") Integer projectId){
|
|
|
|
|
+ List<BranchVO> allBranches = branchService.getAllBranches(projectId);
|
|
|
|
|
+ if (allBranches != null) {
|
|
|
|
|
+ return Response.buildSuccess(allBranches);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return Response.buildFailure(500, GET_BRANCHES_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @author chenyz
|
|
|
|
|
+ * @date 2021/2/4
|
|
|
|
|
+ * @description: 此接口挂载在webhooks的push回调中
|
|
|
|
|
+ * 只关注push event
|
|
|
|
|
+ * 所有分支的push都分析
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/hook")
|
|
|
|
|
+ public void pushHook(@RequestBody GitWebHookVO gitWebHookVO) throws ServiceException {
|
|
|
|
|
+ commitLinkService.linkCommitByInfoFromGitlab(gitWebHookVO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/commits/tree")
|
|
|
|
|
+ public Response<List<CommitVO>> getTreeCommits(@RequestParam("treeId") Integer treeId){
|
|
|
|
|
+ return Response.buildSuccess(commitLinkService.getTreeLinkedCommits(treeId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/commits/bug_list")
|
|
|
|
|
+ public Response<List<CommitVO>> getBugCommits(@RequestParam("bugId") Integer bugId){
|
|
|
|
|
+ return Response.buildSuccess(commitLinkService.getBugLinkedCommits(bugId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/commits/list")
|
|
|
|
|
+ public Response<List<CommitVO>> getCommits(@RequestParam("projectId") Integer projectId) {
|
|
|
|
|
+ return Response.buildSuccess(commitLinkService.getLinkedCommits(projectId));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/commits/link")
|
|
|
|
|
+ public Response<Object> linkCommit(@RequestParam("projectId") Integer projectId,
|
|
|
|
|
+ @RequestParam("commitId") String commitId,
|
|
|
|
|
+ @RequestParam("relatedType") CommitRelatedEnum relatedType,
|
|
|
|
|
+ @RequestParam("relatedId") Integer relatedId)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (commitLinkService.link(projectId, commitId, relatedType, relatedId)) {
|
|
|
|
|
+ return Response.buildSuccess(null);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return Response.buildFailure(404, LINK_FAIL_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 这是sonar的hook
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/sonar_hook")
|
|
|
|
|
+ public Response<Object> sonarHook(@RequestBody SonarResultHookVO sonarResultHookVO) throws ServiceException {
|
|
|
|
|
+ if (commitQualityService.processSonarResult(sonarResultHookVO)) {
|
|
|
|
|
+ return Response.buildSuccess("ok");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return Response.buildFailure(500, "Post Body Process Error!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("commit/quality")
|
|
|
|
|
+ public Response<CommitQualityVO> getQualityByProjectIdAndCommit(@RequestParam("projectId") Integer projectId,
|
|
|
|
|
+ @RequestParam("commitId") String commitId)
|
|
|
|
|
+ {
|
|
|
|
|
+ CommitQualityVO quality = commitQualityService.getQualityByCommit(projectId, commitId);
|
|
|
|
|
+ return Response.buildSuccess(quality);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|