feat: add support for ignoring files in branch diff results using regex patterns

This commit is contained in:
Martim Pimentel
2025-05-22 17:54:34 +01:00
parent c834ebc135
commit 75fd5e83e0
2 changed files with 18 additions and 2 deletions

View File

@ -2469,14 +2469,29 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
case "get_branch_diffs": {
const args = GetBranchDiffsSchema.parse(request.params.arguments);
const diffs = await getBranchDiffs(
const diffResp = await getBranchDiffs(
args.project_id,
args.from,
args.to,
args.straight
);
if (args.ignored_files_regex?.length) {
const regexPatterns = args.ignored_files_regex.map(pattern => new RegExp(pattern));
// Helper function to check if a path matches any regex pattern
const matchesAnyPattern = (path: string): boolean => {
if (!path) return false;
return regexPatterns.some(regex => regex.test(path));
};
// Filter out files that match any of the regex patterns on new files
diffResp.diffs = diffResp.diffs.filter(diff =>
!matchesAnyPattern(diff.new_path)
);
}
return {
content: [{ type: "text", text: JSON.stringify(diffs, null, 2) }],
content: [{ type: "text", text: JSON.stringify(diffResp, null, 2) }],
};
}