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": { case "get_branch_diffs": {
const args = GetBranchDiffsSchema.parse(request.params.arguments); const args = GetBranchDiffsSchema.parse(request.params.arguments);
const diffs = await getBranchDiffs( const diffResp = await getBranchDiffs(
args.project_id, args.project_id,
args.from, args.from,
args.to, args.to,
args.straight 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 { return {
content: [{ type: "text", text: JSON.stringify(diffs, null, 2) }], content: [{ type: "text", text: JSON.stringify(diffResp, null, 2) }],
}; };
} }

View File

@ -633,6 +633,7 @@ export const GetBranchDiffsSchema = ProjectParamsSchema.extend({
from: z.string().describe("The base branch or commit SHA to compare from"), from: z.string().describe("The base branch or commit SHA to compare from"),
to: z.string().describe("The target branch or commit SHA to compare to"), to: z.string().describe("The target branch or commit SHA to compare to"),
straight: z.boolean().optional().describe("Comparison method: false for '...' (default), true for '--'"), straight: z.boolean().optional().describe("Comparison method: false for '...' (default), true for '--'"),
ignored_files_regex: z.array(z.string()).optional().describe("Regex patterns to exclude files from diff results (e.g., 'test/mocks.*', 'go\\.sum')"),
}); });
export const GetMergeRequestSchema = ProjectParamsSchema.extend({ export const GetMergeRequestSchema = ProjectParamsSchema.extend({