Browse Source

🐞 fix: 更新正则匹配规则

Pchen. 2 months ago
parent
commit
54e24ef8fa
1 changed files with 20 additions and 9 deletions
  1. 20 9
      apis/Repos/GetCommitDetail.js

+ 20 - 9
apis/Repos/GetCommitDetail.js

@@ -79,15 +79,26 @@ class GetCommitDetail extends API {
                 diffs: []
             }
 
-            // 解析 diff 信息
-            const diffRegex = /diff --git a\/(.+?) b\/.+?\nindex .+\n--- a\/.+?\n\+\+\+ b\/.+?\n([\s\S]+?)(?=(diff --git a\/|$))/g
-            let diffMatch
-            while ((diffMatch = diffRegex.exec(result)) !== null) {
-                commitInfo.files.push(diffMatch[1])
-                commitInfo.diffs.push({
-                    file: diffMatch[1],
-                    changes: diffMatch[2].trim().split('\n')
-                })
+            // 检查是否为合并提交
+            const isMergeCommit = message.startsWith('Merge')
+
+            if (isMergeCommit) {
+                // 合并提交处理:如果是合并提交,直接返回合并信息
+                commitInfo.mergeInfo = {
+                    message: message,  // 这里返回合并提交的信息
+                    body: body         // 可能包含合并的详情
+                }
+            } else {
+                // 解析 diff 信息
+                const diffRegex = /diff --git a\/(.+?) b\/.+?\nindex .+\n--- a\/.+?\n\+\+\+ b\/.+?\n([\s\S]+?)(?=(diff --git a\/|$))/g
+                let diffMatch
+                while ((diffMatch = diffRegex.exec(result)) !== null) {
+                    commitInfo.files.push(diffMatch[1])
+                    commitInfo.diffs.push({
+                        file: diffMatch[1],
+                        changes: diffMatch[2].trim().split('\n')
+                    })
+                }
             }
 
             res.json({