Skip to content

Commit

Permalink
use ripgrep to search
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo-Mahfoud committed Oct 11, 2024
1 parent e125d96 commit 759b36e
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 4 deletions.
51 changes: 49 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 67 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Record<string, SearchResult[]>> {
const searchResults: Record<string, SearchResult[]> = {}

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 = ''
Expand Down

0 comments on commit 759b36e

Please sign in to comment.