1
0
mirror of synced 2025-12-21 19:06:49 -05:00

Workflow to test docs.github.com links on github/github (#21601)

* run prettier

* removing files from test/integration

* update cron job to not start on the hour

* add github/github comment

* update comment

* updating to search by indices in the content rather than by line

* small updates and updating character max

* update name of script run

* updating to use api search code and get contents

* using api search code and get contents

* adding token check and .js

* remove blank line for title

* update issue body content

* update comment

* add support for GitHub.developer_help_url links
This commit is contained in:
Grace Park
2021-10-01 10:23:58 -07:00
committed by GitHub
parent 1e2fedd16a
commit 96ff67d756
3 changed files with 259 additions and 0 deletions

View File

@@ -126,3 +126,46 @@ export async function createIssueComment(owner, repo, pullNumber, body) {
throw err
}
}
// Search for a string in a file in code and return the array of paths to files that contain string
export async function getPathsWithMatchingStrings(strArr, org, repo) {
const perPage = 100
const paths = new Set()
for (const str of strArr) {
try {
const q = `q=${str}+in:file+repo:${org}/${repo}`
let currentPage = 1
let totalCount = 0
let currentCount = 0
do {
const data = await searchCode(q, perPage, currentPage)
data.items.map((el) => paths.add(el.path))
totalCount = data.total_count
currentCount += data.items.length
currentPage++
} while (currentCount < totalCount)
} catch (err) {
console.log(`error searching for ${str} in ${org}/${repo}`)
throw err
}
}
return paths
}
async function searchCode(q, perPage, currentPage) {
try {
const { data } = await github.rest.search.code({
q,
per_page: perPage,
page: currentPage,
})
return data
} catch (err) {
console.log(`error searching for ${q} in code`)
throw err
}
}