|
|
@@ -0,0 +1,83 @@
|
|
|
+package cn.reghao.autodop.dmaster.app.controller;
|
|
|
+
|
|
|
+import cn.reghao.autodop.common.result.WebResult;
|
|
|
+import cn.reghao.autodop.dmaster.app.constant.AppEnv;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.BuildService;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.OssService;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.build.BuildDispatcher;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.AppToBuild;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.PageList;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.log.BuildDeployLog;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.log.BuildLogVO;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.log.CommitLogVO;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.log.DeployLogVO;
|
|
|
+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 org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.tmatesoft.svn.core.SVNException;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2019-08-30 18:49:15
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Api(tags = "webhook")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/hook")
|
|
|
+public class WebhookController {
|
|
|
+ private BuildDispatcher buildDispatcher;
|
|
|
+
|
|
|
+ public WebhookController(BuildDispatcher buildDispatcher) {
|
|
|
+ this.buildDispatcher = buildDispatcher;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/pipeline/{appId}")
|
|
|
+ public String build1(@PathVariable("appId") String appId,
|
|
|
+ @RequestHeader("X-Codeup-Event") String event,
|
|
|
+ @RequestHeader("x-codeup-delivery") String deliveryId,
|
|
|
+ @RequestBody String body) throws Exception {
|
|
|
+
|
|
|
+ if (event == null || deliveryId == null) {
|
|
|
+ return WebResult.fail("非 webhook 调用");
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> apps = checkArgs(appId);
|
|
|
+ List<BuildDeployLog> buildDeployLogs;
|
|
|
+ if (apps.size() == 0) {
|
|
|
+ return WebResult.success("ok");
|
|
|
+ } else {
|
|
|
+ buildDeployLogs = buildDispatcher.dispatch(apps, true);
|
|
|
+ List<DeployLogVO> deployResultVOS = buildDeployLogs.stream()
|
|
|
+ .filter(buildDeployLog -> buildDeployLog.getDeployLog() != null)
|
|
|
+ .map(BuildDeployLog::deployLog)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return WebResult.success(deployResultVOS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查参数
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2019-12-02 下午2:36
|
|
|
+ */
|
|
|
+ private Set<String> checkArgs(String appId) {
|
|
|
+ String whiteSpace = "\\s+";
|
|
|
+ String[] array = appId.replaceAll(whiteSpace, "").split(",");
|
|
|
+ return new HashSet<>(Arrays.asList(array));
|
|
|
+ }
|
|
|
+}
|