diff --git a/dist/index.js b/dist/index.js index 4af6cb01..20b64c1e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -8191,7 +8191,7 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony import */ var _bot__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(2394); /* harmony import */ var _options__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(1846); /* harmony import */ var _prompts__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(4272); -/* harmony import */ var _review__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(2612); +/* harmony import */ var _review__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(2033); /* harmony import */ var _review_comment__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(5947); @@ -10672,7 +10672,7 @@ const handleReviewComment = async (reviewBot, options, prompts) => { /***/ }), -/***/ 2612: +/***/ 2033: /***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => { "use strict"; @@ -10833,6 +10833,12 @@ var lib_inputs = __nccwpck_require__(6180); var octokit = __nccwpck_require__(3258); // EXTERNAL MODULE: ./lib/tokenizer.js var tokenizer = __nccwpck_require__(652); +// EXTERNAL MODULE: ./node_modules/@vscode/ripgrep/lib/index.js +var lib = __nccwpck_require__(5455); +;// CONCATENATED MODULE: external "child_process" +const external_child_process_namespaceObject = require("child_process"); +// EXTERNAL MODULE: external "util" +var external_util_ = __nccwpck_require__(3837); ;// CONCATENATED MODULE: ./lib/review.js // eslint-disable-next-line camelcase @@ -10842,9 +10848,13 @@ var tokenizer = __nccwpck_require__(652); + + + // eslint-disable-next-line camelcase const context = github.context; const repo = context.repo; +const execFileAsync = (0,external_util_.promisify)(external_child_process_namespaceObject.execFile); const ignoreKeyword = '@erag: ignore'; async function codeReview(reviewBot, options, prompts) { const commenter = new lib_commenter/* Commenter */.Es(); @@ -11078,6 +11088,7 @@ ${summariesFailed.length > 0 (0,core.info)(`patches: ${patches}`); (0,core.info)(`symbols: ${symbols}`); } + await searchSymbols(symbols); // make a copy of inputs const ins = inputs.clone(); ins.filename = filename; @@ -11239,6 +11250,30 @@ ${reviewsSkipped.length > 0 // post the final summary comment await commenter.comment(`${summarizeComment}`, lib_commenter/* SUMMARIZE_TAG */.Rp, 'replace'); } +async function searchSymbols(symbols) { + const searchResults = {}; + for (const symbol of symbols) { + try { + // Execute ripgrep to search for the symbol in the current directory + const { stdout } = await execFileAsync(lib/* rgPath */.$, [symbol, '-n', '-w']); + (0,core.info)(`stdout for search symbol ${symbol}: \n\n${stdout}\n\n`); + const lines = stdout.split('\n').filter(line => line.trim() !== ''); + searchResults[symbol] = lines.map(line => { + const [file, lineNumber, ...matchParts] = line.split(':'); + return { + file, + line: parseInt(lineNumber, 10), + match: matchParts.join(':').trim() + }; + }); + } + catch (err) { + (0,core.warning)(`Error searching for symbol ${symbol}: ${err.message}`); + } + } + (0,core.info)(`\n\nsearchResults: ${JSON.stringify(searchResults, null, 2)}\n\n`); + return searchResults; +} async function determineHighestReviewedCommitId(existingCommitIdsBlock, pullRequest, commenter) { const allCommitIds = await commenter.getAllCommitIds(); let highestReviewedCommitId = ''; @@ -28231,6 +28266,18 @@ module.exports.implForWrapper = function (wrapper) { +/***/ }), + +/***/ 5455: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +"use strict"; + + +const path = __nccwpck_require__(1017); + +module.exports.$ = path.join(__dirname, `../bin/rg${process.platform === 'win32' ? '.exe' : ''}`); + /***/ }), /***/ 4812: diff --git a/package-lock.json b/package-lock.json index a4423914..b82cc8c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "openai-pr-reviewer", + "name": "erag-reviewer", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "openai-pr-reviewer", + "name": "erag-reviewer", "version": "0.0.0", "license": "MIT", "dependencies": { @@ -15,6 +15,7 @@ "@octokit/action": "^6.0.4", "@octokit/plugin-retry": "^4.1.3", "@octokit/plugin-throttling": "^6.1.0", + "@vscode/ripgrep": "^1.15.9", "axios": "^1.7.2", "minimatch": "^9.0.1", "node-fetch": "^3.3.1", @@ -2495,6 +2496,40 @@ "ncc": "dist/ncc/cli.js" } }, + "node_modules/@vscode/ripgrep": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/@vscode/ripgrep/-/ripgrep-1.15.9.tgz", + "integrity": "sha512-4q2PXRvUvr3bF+LsfrifmUZgSPmCNcUZo6SbEAZgArIChchkezaxLoIeQMJe/z3CCKStvaVKpBXLxN3Z8lQjFQ==", + "hasInstallScript": true, + "dependencies": { + "https-proxy-agent": "^7.0.2", + "proxy-from-env": "^1.1.0", + "yauzl": "^2.9.2" + } + }, + "node_modules/@vscode/ripgrep/node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/@vscode/ripgrep/node_modules/https-proxy-agent": { + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", + "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/abab": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", @@ -2992,6 +3027,14 @@ "node-int64": "^0.4.0" } }, + "node_modules/buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", + "engines": { + "node": "*" + } + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -4481,6 +4524,14 @@ "bser": "2.1.1" } }, + "node_modules/fd-slicer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", + "dependencies": { + "pend": "~1.2.0" + } + }, "node_modules/fetch-blob": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", @@ -8680,6 +8731,11 @@ "node": ">=8" } }, + "node_modules/pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==" + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -10100,6 +10156,15 @@ "node": ">=10" } }, + "node_modules/yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", + "dependencies": { + "buffer-crc32": "~0.2.3", + "fd-slicer": "~1.1.0" + } + }, "node_modules/yocto-queue": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz", diff --git a/package.json b/package.json index ac6e3718..ccd65534 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@octokit/action": "^6.0.4", "@octokit/plugin-retry": "^4.1.3", "@octokit/plugin-throttling": "^6.1.0", + "@vscode/ripgrep": "^1.15.9", "axios": "^1.7.2", "minimatch": "^9.0.1", "node-fetch": "^3.3.1", diff --git a/src/review.ts b/src/review.ts index c377234f..491f45cb 100644 --- a/src/review.ts +++ b/src/review.ts @@ -17,10 +17,14 @@ import {octokit} from './octokit' import {type Options} from './options' import {type Prompts} from './prompts' import {getTokenCount} from './tokenizer' +import {rgPath} from '@vscode/ripgrep' +import {execFile} from 'child_process' +import {promisify} from 'util' // eslint-disable-next-line camelcase const context = github_context const repo = context.repo +const execFileAsync = promisify(execFile) const ignoreKeyword = '@erag: ignore' @@ -291,6 +295,9 @@ ${ info(`patches: ${patches}`) info(`symbols: ${symbols}`) } + + await searchSymbols(symbols) + // make a copy of inputs const ins: Inputs = inputs.clone() ins.filename = filename @@ -466,6 +473,40 @@ ${ await commenter.comment(`${summarizeComment}`, SUMMARIZE_TAG, 'replace') } +interface SearchResult { + file: string + line: number + match: string +} + +async function searchSymbols(symbols: string[]): Promise> { + const searchResults: Record = {} + + for (const symbol of symbols) { + try { + // Execute ripgrep to search for the symbol in the current directory + const {stdout} = await execFileAsync(rgPath, [symbol, '-n', '-w']) + info(`stdout for search symbol ${symbol}: \n\n${stdout}\n\n`) + const lines = stdout.split('\n').filter(line => line.trim() !== '') + + searchResults[symbol] = lines.map(line => { + const [file, lineNumber, ...matchParts] = line.split(':') + return { + file, + line: parseInt(lineNumber, 10), + match: matchParts.join(':').trim() + } + }) + } catch (err: any) { + warning(`Error searching for symbol ${symbol}: ${err.message as string}`) + } + } + + info(`\n\nsearchResults: ${JSON.stringify(searchResults, null, 2)}\n\n`) + + return searchResults +} + async function determineHighestReviewedCommitId(existingCommitIdsBlock: string, pullRequest: any, commenter: Commenter) { const allCommitIds = await commenter.getAllCommitIds() let highestReviewedCommitId = ''