From ff2494dcf25f18c1f09753d2de17cdc4890b6bd3 Mon Sep 17 00:00:00 2001 From: Wonder Date: Mon, 13 Oct 2025 15:36:03 +0800 Subject: [PATCH] =?UTF-8?q?=20=E2=9C=A8Feat:=20=E8=8E=B7=E5=8F=96=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gitea-webhook/pom.xml | 7 ++++ .../webhook/service/FileService.java | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 gitea-webhook/src/main/java/cn/hezhaohui/webhook/service/FileService.java 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(); + } +}