(
path: string,
{ repoURL = this.repoURL, branch = this.branch, depth = 1 } = {},
)
| 730 | } |
| 731 | |
| 732 | async listFiles( |
| 733 | path: string, |
| 734 | { repoURL = this.repoURL, branch = this.branch, depth = 1 } = {}, |
| 735 | ): Promise<{ type: string; id: string; name: string; path: string; size: number }[]> { |
| 736 | const folder = trim(path, '/'); |
| 737 | try { |
| 738 | const result: Endpoints['GET /repos/{owner}/{repo}/git/trees/{tree_sha}']['response']['data'] = |
| 739 | await this.request(`${repoURL}/git/trees/${branch}:${folder}`, { |
| 740 | // GitHub API supports recursive=1 for getting the entire recursive tree |
| 741 | // or omitting it to get the non-recursive tree |
| 742 | params: depth > 1 ? { recursive: 1 } : {}, |
| 743 | }); |
| 744 | return ( |
| 745 | result.tree |
| 746 | // filter only files and up to the required depth |
| 747 | .filter(file => file.type === 'blob' && file.path && file.path.split('/').length <= depth) |
| 748 | .map(file => ({ |
| 749 | type: file.type, |
| 750 | id: file.sha, |
| 751 | name: basename(file.path), |
| 752 | path: `${folder}/${file.path}`, |
| 753 | size: file.size || 0, |
| 754 | })) |
| 755 | ); |
| 756 | } catch (err) { |
| 757 | if (err && err.status === 404) { |
| 758 | console.log('This 404 was expected and handled appropriately.'); |
| 759 | return []; |
| 760 | } else { |
| 761 | throw err; |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | filterOpenAuthoringBranches = async (branch: string) => { |
| 767 | try { |
no test coverage detected