Skip to content

Commit

Permalink
Reduce number of API calls to get list of files tracked by GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Mar 7, 2021
1 parent f285c4c commit 953bdcc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
19 changes: 14 additions & 5 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions src/utils/github-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,29 @@ export async function listFiles(octokit: InstanceType<typeof GitHub>, sha: strin
}

async function listGitTree(octokit: InstanceType<typeof GitHub>, sha: string, path: string): Promise<string[]> {
const tree = await octokit.git.getTree({
let truncated = false
let tree = await octokit.git.getTree({
recursive: 'true',
tree_sha: sha,
...github.context.repo
})

if (tree.data.truncated) {
truncated = true
tree = await octokit.git.getTree({
tree_sha: sha,
...github.context.repo
})
}

const result: string[] = []
for (const tr of tree.data.tree) {
const file = `${path}${tr.path}`
if (tr.type === 'tree') {
if (tr.type === 'blob') {
result.push(file)
} else if (tr.type === 'tree' && truncated) {
const files = await listGitTree(octokit, tr.sha, `${file}/`)
result.push(...files)
} else {
result.push(file)
}
}

Expand Down

0 comments on commit 953bdcc

Please sign in to comment.