diff --git a/gitea-webhook/pom.xml b/gitea-webhook/pom.xml index 60c83aa..3351ff7 100644 --- a/gitea-webhook/pom.xml +++ b/gitea-webhook/pom.xml @@ -28,6 +28,13 @@ org.springframework.boot spring-boot-starter-web + + + + cn.hutool + hutool-http + 5.8.27 + \ No newline at end of file diff --git a/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/FileService.java b/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/FileService.java new file mode 100644 index 0000000..75832cf --- /dev/null +++ b/gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/FileService.java @@ -0,0 +1,33 @@ +package cn.hezhaohui.webhook.service; + +import cn.hutool.http.HttpUtil; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class FileService { + // repo: http://47.121.181.112:3000/wonder/lark-webhook-sender + // prefix: /raw/branch/main/ + // raw: gitea-webhook/src/main/java/cn/hezhaohui/webhook/controller/HookController.java + // parse: http://47.121.181.112:3000/wonder/lark-webhook-sender/raw/branch/main/gitea-webhook/src/main/java/cn/hezhaohui/webhook/controller/HookController.java + + public String getRawUrl(String repo, String raw) { + return repo +"/raw/branch/main/" +raw; + } + + public String getRawContents(String repo, String raw) { + String url = getRawUrl(repo, raw); + String fileName = raw.substring(raw.lastIndexOf("/")+1); + String fileContent = HttpUtil.get(url); + return "[FileName]" + fileName + "\n" + "[FileContent]" + fileContent + "\n"; + } + + public String getAllFiles(String repo, List files) { + StringBuilder sb = new StringBuilder(); + for (String file : files) { + sb.append(getRawContents(repo, file)); + } + return sb.toString(); + } +}