Skip to content

Commit

Permalink
fix: 修复diff细节
Browse files Browse the repository at this point in the history
  • Loading branch information
Lydanne committed Aug 8, 2023
1 parent 9a2fb06 commit d4376d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/diffReview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReviewResult, Reviewer } from "./Reviewer";
import { findCommonAncestor } from "./findCommonAncestor";
import { getCurrentBranch } from "./getCurrentBranch";
import { AiReviewer } from "./reviewer/AiReviewer";
import { ESLintReviewer } from "./reviewer/ESLintReviewer";
Expand All @@ -15,6 +16,8 @@ export async function diffReview(target: string, options: Options) {
);
}

target = findCommonAncestor(current, target) || target;

Check failure on line 19 in src/diffReview.ts

View workflow job for this annotation

GitHub Actions / lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator

return await Reviewer.review(current, target, {
cwd: options.cwd ?? process.cwd(),
patter: options.patter,
Expand Down
15 changes: 15 additions & 0 deletions src/findCommonAncestor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { execSync } from "child_process";

export function findCommonAncestor(branch1: string, branch2: string) {
try {
// 执行 Git 命令获取共同节点的哈希值
const command = `git merge-base ${branch1} ${branch2}`;
const output = execSync(command, { encoding: "utf-8" });

// 返回共同节点的哈希值
return output.trim();
} catch (error) {
console.error("Error finding common ancestor:", error);
return undefined;
}
}

0 comments on commit d4376d1

Please sign in to comment.