UNPKG

debugg-ai-mcp

Version:

MCP Server for debugg ai web browsing

128 lines (127 loc) 5.46 kB
export const createCoverageService = (tx) => ({ /** * Create a test coverage file for a given file */ async createCoverage(fileContents, filePath, repoName, branchName, params) { try { const serverUrl = "api/v1/coverage/"; console.error('Branch name - ', branchName, ' repo name - ', repoName, ' repo path - ', params?.repoPath); let relativePath = filePath; // Convert absolute path to relative path if (params?.repoPath) { relativePath = filePath.replace(params?.repoPath + "/", ""); } else { console.error("No repo path found for file"); // split based on the repo name const repoBaseName = repoName.split("/")[-1]; // typically the form of 'userName/repoName' const splitPath = filePath.split(repoBaseName); if (splitPath.length === 2) { // if the repo name is in the path & only once, otherwise unclear how to handle relativePath = splitPath[1]; } else { relativePath = filePath; } } console.error("GET_COVERAGE: Full path - ", filePath, ". Relative path - ", relativePath); const fileParams = { ...params, fileContents: fileContents, absPath: filePath, filePath: relativePath, repoName: repoName, branchName: branchName, }; const response = await tx.post(serverUrl, { ...fileParams }); console.error("Raw API response:", response); return response; } catch (err) { console.error("Error fetching issues in file:", err); return null; } }, /** * Log a failed run for a given test file */ async logFailedRun(fileContents, filePath, repoName, branchName, params) { try { const serverUrl = "api/v1/coverage/log_failed_run/"; console.error('Branch name - ', branchName, ' repo name - ', repoName, ' repo path - ', params?.repoPath); let relativePath = filePath; // Convert absolute path to relative path if (params?.repoPath) { relativePath = filePath.replace(params?.repoPath + "/", ""); } else { console.error("No repo path found for file"); // split based on the repo name const repoBaseName = repoName.split("/")[-1]; // typically the form of 'userName/repoName' const splitPath = filePath.split(repoBaseName); if (splitPath.length === 2) { // if the repo name is in the path & only once, otherwise unclear how to handle relativePath = splitPath[1]; } else { relativePath = filePath; } } console.error("GET_COVERAGE: Full path - ", filePath, ". Relative path - ", relativePath); const fileParams = { ...params, fileContents: fileContents, absPath: filePath, filePath: relativePath, repoName: repoName, branchName: branchName, }; const response = await tx.post(serverUrl, { ...fileParams }); console.error("Raw API response:", response); return response; } catch (err) { console.error("Error fetching issues in file:", err); return null; } }, /** * Get a test coverage file for a given file */ async getCoverage(filePath, repoName, branchName, params) { try { const serverUrl = "api/v1/coverage/for_file/"; console.error('Branch name - ', branchName, ' repo name - ', repoName, ' repo path - ', params?.repoPath); let relativePath = filePath; // Convert absolute path to relative path if (params?.repoPath) { relativePath = filePath.replace(params?.repoPath + "/", ""); } else { console.error("No repo path found for file"); // split based on the repo name const repoBaseName = repoName.split("/")[-1]; // typically the form of 'userName/repoName' const splitPath = filePath.split(repoBaseName); if (splitPath.length === 2) { // if the repo name is in the path & only once, otherwise unclear how to handle relativePath = splitPath[1]; } else { relativePath = filePath; } } console.error("GET_COVERAGE: Full path - ", filePath, ". Relative path - ", relativePath); const fileParams = { ...params, filePath: relativePath, absPath: filePath, repoName: repoName, branchName: branchName, }; const response = await tx.get(serverUrl, { ...fileParams }); console.error("Raw API response:", response); return response; } catch (err) { console.error("Error fetching issues in file:", err); return null; } } });