✨Feat: 支持 AI 总结代码修改内容
This commit is contained in:
@@ -14,4 +14,6 @@ public class AIConstant {
|
|||||||
"[Modified Files]: ...\n" +
|
"[Modified Files]: ...\n" +
|
||||||
"【输出格式】" +
|
"【输出格式】" +
|
||||||
"[总结]: ...";
|
"[总结]: ...";
|
||||||
|
|
||||||
|
public static final String DEFAULT_ERROR_RESPONSE = "*变化文件数量过多,请在仓库中查看";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package cn.hezhaohui.webhook.service;
|
|||||||
|
|
||||||
import cn.hezhaohui.lark.entity.CardData;
|
import cn.hezhaohui.lark.entity.CardData;
|
||||||
import cn.hezhaohui.lark.util.Lark;
|
import cn.hezhaohui.lark.util.Lark;
|
||||||
|
import cn.hezhaohui.webhook.constant.AIConstant;
|
||||||
import cn.hezhaohui.webhook.entity.GiteaPushEvent;
|
import cn.hezhaohui.webhook.entity.GiteaPushEvent;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -13,6 +15,12 @@ import java.util.stream.Stream;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class HookService {
|
public class HookService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AIService aiService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
public void handlePush(GiteaPushEvent event) {
|
public void handlePush(GiteaPushEvent event) {
|
||||||
List<String> commitMsgList = event.getCommits().stream()
|
List<String> commitMsgList = event.getCommits().stream()
|
||||||
.map(GiteaPushEvent.Commit::getMessage)
|
.map(GiteaPushEvent.Commit::getMessage)
|
||||||
@@ -20,22 +28,48 @@ public class HookService {
|
|||||||
|
|
||||||
List<String> addedFiles = event.getCommits().stream()
|
List<String> addedFiles = event.getCommits().stream()
|
||||||
.flatMap(commit -> commit.getAdded().stream())
|
.flatMap(commit -> commit.getAdded().stream())
|
||||||
|
.distinct()
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
List<String> removedFiles = event.getCommits().stream()
|
List<String> removedFiles = event.getCommits().stream()
|
||||||
.flatMap(commit -> commit.getRemoved().stream())
|
.flatMap(commit -> commit.getRemoved().stream())
|
||||||
|
.distinct()
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
List<String> modifiedFiles = event.getCommits().stream()
|
List<String> modifiedFiles = event.getCommits().stream()
|
||||||
.flatMap(commit -> commit.getModified().stream())
|
.flatMap(commit -> commit.getModified().stream())
|
||||||
|
.distinct()
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
if (addedFiles.isEmpty() && removedFiles.isEmpty() && modifiedFiles.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ai = AIConstant.DEFAULT_ERROR_RESPONSE;
|
||||||
|
|
||||||
|
|
||||||
|
if (addedFiles.size() + removedFiles.size() + modifiedFiles.size() <= 20) {
|
||||||
|
String addedFilesContent = fileService.getAllFiles(event.getRepository().getHtml_url(), addedFiles);
|
||||||
|
String removedFilesContent = fileService.getAllFiles(event.getRepository().getHtml_url(), removedFiles);
|
||||||
|
String modifiedFilesContent = fileService.getAllFiles(event.getRepository().getHtml_url(), modifiedFiles);
|
||||||
|
|
||||||
|
String allFilesContentString = "[Added Files]: \n" +
|
||||||
|
addedFilesContent +
|
||||||
|
"\n[Removed Files]: \n" +
|
||||||
|
removedFilesContent +
|
||||||
|
"\n[Modified Files]: \n" +
|
||||||
|
modifiedFilesContent;
|
||||||
|
String input = "[Commit Messages]: \n" +
|
||||||
|
String.join("\n", commitMsgList) +
|
||||||
|
"\n" + allFilesContentString;
|
||||||
|
ai = aiService.getAIResponse(input);
|
||||||
|
}
|
||||||
|
|
||||||
log.info("commitMsgList: {}\n", commitMsgList);
|
log.info("commitMsgList: {}\n", commitMsgList);
|
||||||
log.info("addedFiles: {}\n", addedFiles);
|
log.info("addedFiles: {}\n", addedFiles);
|
||||||
log.info("removedFiles: {}\n", removedFiles);
|
log.info("removedFiles: {}\n", removedFiles);
|
||||||
log.info("modifiedFiles: {}\n", modifiedFiles);
|
log.info("modifiedFiles: {}\n", modifiedFiles);
|
||||||
|
|
||||||
// TODO: 调用 AI 模块
|
|
||||||
|
|
||||||
CardData cardData = CardData.builder()
|
CardData cardData = CardData.builder()
|
||||||
.title("[Gitea] 仓库状态变化")
|
.title("[Gitea] 仓库状态变化")
|
||||||
@@ -44,7 +78,7 @@ public class HookService {
|
|||||||
.msg(String.join("\n", commitMsgList))
|
.msg(String.join("\n", commitMsgList))
|
||||||
.tag("PUSH")
|
.tag("PUSH")
|
||||||
.subtitle("Ciallo~(∠・ω< )⌒★")
|
.subtitle("Ciallo~(∠・ω< )⌒★")
|
||||||
.ai("待开发")
|
.ai(ai)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user