MCPcopy Create free account
hub / github.com/decaporg/decap-cms / listFiles

Method listFiles

packages/decap-cms-backend-github/src/API.ts:735–767  ·  view source on GitHub ↗
(
    path: string,
    { repoURL = this.repoURL, branch = this.branch, depth = 1 } = {},
  )

Source from the content-addressed store, hash-verified

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

Callers 3

updateTreeMethod · 0.95
API.spec.jsFile · 0.45
GraphQLAPI.spec.jsFile · 0.45

Calls 4

requestMethod · 0.95
basenameFunction · 0.90
mapMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected