PipelineController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package seecoder.devcloud.web.controller.pipeline;
  2. import io.swagger.annotations.Api;
  3. import io.swagger.annotations.ApiImplicitParam;
  4. import io.swagger.annotations.ApiImplicitParams;
  5. import io.swagger.annotations.ApiOperation;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.validation.annotation.Validated;
  8. import org.springframework.web.bind.annotation.*;
  9. import seecoder.devcloud.web.model.vo.Response;
  10. import seecoder.devcloud.web.model.vo.pipeline.PipelineConfigVO;
  11. import seecoder.devcloud.web.model.vo.pipeline.PipelineCreateVO;
  12. import seecoder.devcloud.web.model.vo.pipeline.PipelineHistoryVO;
  13. import seecoder.devcloud.web.model.vo.pipeline.PipelineInfoVO;
  14. import seecoder.devcloud.web.service.pipeline.PipelineService;
  15. import java.util.List;
  16. /**
  17. * @author PuHong Weng
  18. * @date 2021/3/11
  19. * @description:
  20. */
  21. @RestController
  22. @RequestMapping("/pipelines")
  23. @Api(tags = "流水线配置 API")
  24. public class PipelineController {
  25. private final PipelineService pipelineService;
  26. @Autowired
  27. public PipelineController(PipelineService pipelineService) {
  28. this.pipelineService = pipelineService;
  29. }
  30. @GetMapping("/list")
  31. @ApiOperation(value = "获取指定项目的所有流水线基本信息", httpMethod = "GET")
  32. @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query")
  33. public Response<List<PipelineInfoVO>> retrievePipelineInfos(@RequestParam("projectId") Integer projectId){
  34. return Response.buildSuccess(pipelineService.retrievePipelineInfos(projectId));
  35. }
  36. @GetMapping
  37. @ApiOperation(value = "获取指定一条流水线的配置json信息", httpMethod = "GET")
  38. @ApiImplicitParams({
  39. @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query"),
  40. @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query")
  41. })
  42. public Response<PipelineConfigVO> retrievePipelineConfig(@RequestParam("projectId")Integer projectId,
  43. @RequestParam("pipelineId")Integer pipelineId){
  44. return Response.buildSuccess(pipelineService.retrievePipelineConfig(projectId, pipelineId));
  45. }
  46. @GetMapping("/history/list")
  47. @ApiOperation(value = "获取指定一条流水线的历史构建信息列表", httpMethod = "GET")
  48. @ApiImplicitParams({
  49. @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query"),
  50. @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query")
  51. })
  52. public Response<List<PipelineHistoryVO>> retrievePipelineHistory(@RequestParam("projectId")Integer projectId,
  53. @RequestParam("pipelineId")Integer pipelineId){
  54. return Response.buildSuccess(pipelineService.retrievePipelineHistory(projectId,pipelineId));
  55. }
  56. @ApiOperation(value = "依据模板创建一个流水线配置", httpMethod = "POST")
  57. @ApiImplicitParam(name = "pipelineCreateVO", value = "流水线创建配置信息",dataType = "object",paramType = "body")
  58. @PostMapping
  59. public Response createPipelineConfig(@RequestBody @Validated PipelineCreateVO pipelineCreateVO){
  60. pipelineService.createPipelineConfig(pipelineCreateVO);
  61. return Response.buildSuccess();
  62. }
  63. @PutMapping("/config")
  64. @ApiOperation(value = "保存修改一条流水线的json配置信息", httpMethod = "PUT")
  65. @ApiImplicitParams({
  66. @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query"),
  67. @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query"),
  68. @ApiImplicitParam(name = "configJson", dataType = "string",paramType = "query")
  69. })
  70. public Response savePipelineConfig(@RequestParam("projectId")Integer projectId,
  71. @RequestParam("pipelineId")Integer pipelineId,
  72. @RequestParam("configJson")String configJson){
  73. //todo 验证configJson有效性
  74. pipelineService.savePipelineConfig(projectId,pipelineId, configJson);
  75. return Response.buildSuccess();
  76. }
  77. @ApiOperation(value = "删除一条流水线", httpMethod = "DELETE")
  78. @ApiImplicitParams({
  79. @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query"),
  80. @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query"),
  81. })
  82. @DeleteMapping
  83. public Response deletePipelineInfo(Integer projectId,Integer pipelineId){
  84. pipelineService.deletePipelineConfig(projectId, pipelineId);
  85. return Response.buildSuccess();
  86. }
  87. @ApiOperation(value = "获取可用的pipeline模板名字", httpMethod = "GET")
  88. @GetMapping("/templates")
  89. public Response<List<String>> getPipelineTemplateNames(){
  90. return Response.buildSuccess(pipelineService.getTemplateNames());
  91. }
  92. }