Browse Source

🎈 perf: 优化commit详情获取接口

Pchen. 3 months ago
parent
commit
45761e22a3
1 changed files with 13 additions and 5 deletions
  1. 13 5
      apis/Repos/GetCommitDetail.js

+ 13 - 5
apis/Repos/GetCommitDetail.js

@@ -51,19 +51,27 @@ class GetCommitDetail extends API {
                         msg: '获取提交详情失败!'
                     })
 
-                const commitRegex = /^commit (\w+)\nAuthor: (.+)\nDate:\s+(.+)\n\n\s*(.+)/
+                // 修改正则表达式,捕获多行 commit message(包括 body)
+                const commitRegex = /^commit (\w+)\nAuthor: (.+) <(.+)>\nDate:\s+(.+)\n\n([\s\S]+?)(?=diff --git|$)/;
                 const match = result.match(commitRegex)
-                if (!match) 
+                if (!match)
                     return res.json({
                         ...BaseStdResponse.ERR,
                         msg: '解析提交详情失败!'
                     })
 
+                // 拆分 message 和 body
+                const fullMessage = match[5].trim().split("\n");
+                const message = fullMessage[0]; // 第一行短描述
+                const body = fullMessage.slice(1).join("\n").trim(); // 多行 body
+
                 const commitInfo = {
                     hash: match[1],
                     author: match[2],
-                    date: match[3],
-                    message: match[4],
+                    email: match[3],
+                    date: match[4],
+                    message,
+                    body,
                     files: [],
                     diffs: []
                 }
@@ -78,7 +86,7 @@ class GetCommitDetail extends API {
                         changes: diffMatch[2].trim().split('\n')
                     })
                 }
-                
+
                 res.json({
                     ...BaseStdResponse.OK,
                     data: commitInfo