mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Reduce number of API calls to get list of files tracked by GitHub
This commit is contained in:
parent
f285c4c6d7
commit
953bdcc20a
3 changed files with 29 additions and 10 deletions
19
dist/index.js
generated
vendored
19
dist/index.js
generated
vendored
|
|
@ -1490,20 +1490,29 @@ async function listFiles(octokit, sha) {
|
|||
}
|
||||
exports.listFiles = listFiles;
|
||||
async function listGitTree(octokit, sha, path) {
|
||||
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 = [];
|
||||
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);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue