|
|
@@ -1,32 +1,13 @@
|
|
|
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.common.utils.JsonUtil;
|
|
|
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 com.google.gson.JsonObject;
|
|
|
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
|
|
|
@@ -43,41 +24,13 @@ public class WebhookController {
|
|
|
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));
|
|
|
+ @PostMapping("/pipeline")
|
|
|
+ public String build(@RequestBody String body) throws Exception {
|
|
|
+ JsonObject jsonObject = JsonUtil.jsonObject(body);
|
|
|
+ String repo = jsonObject.get("repository").getAsJsonObject().get("url").getAsString();
|
|
|
+ String ref = jsonObject.get("ref").getAsString();
|
|
|
+ String branch = ref.substring(ref.lastIndexOf("/")+1);
|
|
|
+ BuildDeployLog buildDeployLog = buildDispatcher.dispatch(repo, branch, true);
|
|
|
+ return WebResult.success(buildDeployLog);
|
|
|
}
|
|
|
}
|