Ver código fonte

feat: 添加webhook回调接口

ChenYZ 5 anos atrás
pai
commit
9bc359dbc6

+ 33 - 0
web/src/main/java/seecoder/devcloud/web/controller/gitlab/HookController.java

@@ -0,0 +1,33 @@
+package seecoder.devcloud.web.controller.gitlab;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import seecoder.devcloud.web.vo.GitWebHookVO;
+
+/**
+ * @author chenyz
+ * @date 2021/2/4
+ * @description: 与GitLab进行交互的接口
+ */
+@Api(tags = "GitLab Hook API")
+@RestController
+@RequestMapping("/hook")
+public class HookController {
+
+    /**
+     * @author chenyz
+     * @date 2021/2/4
+     * @description: 此接口挂载在webhooks的push回调中
+     */
+    @ApiOperation("push回调接口")
+    @PostMapping("/push")
+    public void pushHook(@RequestBody GitWebHookVO gitWebHookVO)
+    {
+        System.out.println(gitWebHookVO);
+        // todo:提取commit信息并进行处理
+    }
+}

+ 1 - 0
web/src/main/java/seecoder/devcloud/web/vo/ResponseEnums.java → web/src/main/java/seecoder/devcloud/web/enums/ResponseEnums.java

@@ -21,6 +21,7 @@ public enum ResponseEnums {
     private String code;
     private String msg;
 
+
     ResponseEnums(String code, String msg) {
         this.code = code;
         this.msg = msg;

+ 77 - 0
web/src/main/java/seecoder/devcloud/web/vo/GitWebHookVO.java

@@ -0,0 +1,77 @@
+package com.seecoder;
+
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+import java.util.List;
+
+@Data
+@ToString
+public class GitWebHookVO {
+    private String object_kind;
+    private String before;
+    private String after;
+    private String ref;
+    private String checkout_sha;
+    private Integer user_id;
+    private String user_name;
+    private String user_username;
+    private String user_email;
+    private String user_avatar;
+    private Integer project_id;
+    private Project project;
+    private Repository repository;
+    private List<Commit> commits;
+    private Integer total_commits_count;
+
+    @Data
+    @NoArgsConstructor
+    static class Project{
+        private Integer id;
+        private String name;
+        private String description;
+        private String web_url;
+        private String avatar_url;
+        private String git_ssh_url;
+        private String git_http_url;
+        private String namespace;
+        private Integer visibility_level;
+        private String path_with_namespace;
+        private String default_branch;
+        private String homepage;
+        private String url;
+        private String ssh_url;
+        private String http_url;
+    }
+    @Data
+    @NoArgsConstructor
+    static class Repository{
+        private String name;
+        private String url;
+        private String description;
+        private String homepage;
+        private String git_http_url;
+        private String git_ssh_url;
+        private Integer visibility_level;
+    }
+    @Data
+    @NoArgsConstructor
+    static class Commit{
+        private String id;
+        private String message;
+        private String title;
+        private String timestamp;
+        private String url;
+        private Author author;
+        private List<String> added;
+        private List<String> modified;
+        private List<String> removed;
+    }
+    @Data
+    @NoArgsConstructor
+    static class Author{
+        private String name;
+        private String email;
+    }
+}