Skip to content

Commit 75fd5e8

Browse files
author
Martim Pimentel
committed
feat: add support for ignoring files in branch diff results using regex patterns
1 parent c834ebc commit 75fd5e8

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,14 +2469,29 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
24692469

24702470
case "get_branch_diffs": {
24712471
const args = GetBranchDiffsSchema.parse(request.params.arguments);
2472-
const diffs = await getBranchDiffs(
2472+
const diffResp = await getBranchDiffs(
24732473
args.project_id,
24742474
args.from,
24752475
args.to,
24762476
args.straight
24772477
);
2478+
2479+
if (args.ignored_files_regex?.length) {
2480+
const regexPatterns = args.ignored_files_regex.map(pattern => new RegExp(pattern));
2481+
2482+
// Helper function to check if a path matches any regex pattern
2483+
const matchesAnyPattern = (path: string): boolean => {
2484+
if (!path) return false;
2485+
return regexPatterns.some(regex => regex.test(path));
2486+
};
2487+
2488+
// Filter out files that match any of the regex patterns on new files
2489+
diffResp.diffs = diffResp.diffs.filter(diff =>
2490+
!matchesAnyPattern(diff.new_path)
2491+
);
2492+
}
24782493
return {
2479-
content: [{ type: "text", text: JSON.stringify(diffs, null, 2) }],
2494+
content: [{ type: "text", text: JSON.stringify(diffResp, null, 2) }],
24802495
};
24812496
}
24822497

schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ export const GetBranchDiffsSchema = ProjectParamsSchema.extend({
633633
from: z.string().describe("The base branch or commit SHA to compare from"),
634634
to: z.string().describe("The target branch or commit SHA to compare to"),
635635
straight: z.boolean().optional().describe("Comparison method: false for '...' (default), true for '--'"),
636+
ignored_files_regex: z.array(z.string()).optional().describe("Regex patterns to exclude files from diff results (e.g., 'test/mocks.*', 'go\\.sum')"),
636637
});
637638

638639
export const GetMergeRequestSchema = ProjectParamsSchema.extend({

0 commit comments

Comments
 (0)