MCPcopy Index your code
hub / github.com/github/docs / getPathsWithMatchingStrings

Function getPathsWithMatchingStrings

script/helpers/git-utils.js:137–162  ·  view source on GitHub ↗
(strArr, org, repo)

Source from the content-addressed store, hash-verified

135
136// Search for a string in a file in code and return the array of paths to files that contain string
137export async function getPathsWithMatchingStrings(strArr, org, repo) {
138 const perPage = 100
139 const paths = new Set()
140
141 for (const str of strArr) {
142 try {
143 const q = `q=${str}+in:file+repo:${org}/${repo}`
144 let currentPage = 1
145 let totalCount = 0
146 let currentCount = 0
147
148 do {
149 const data = await searchCode(q, perPage, currentPage)
150 data.items.map((el) => paths.add(el.path))
151 totalCount = data.total_count
152 currentCount += data.items.length
153 currentPage++
154 } while (currentCount < totalCount)
155 } catch (err) {
156 console.log(`error searching for ${str} in ${org}/${repo}`)
157 throw err
158 }
159 }
160
161 return paths
162}
163
164async function searchCode(q, perPage, currentPage) {
165 try {

Callers 1

mainFunction · 0.90

Calls 1

searchCodeFunction · 0.85

Tested by

no test coverage detected