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

Method listFiles

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

Source from the content-addressed store, hash-verified

705 }
706
707 async listFiles(
708 path: string,
709 { repoURL = this.repoURL, branch = this.branch, depth = 1 } = {},
710 ): Promise<{ type: string; id: string; name: string; path: string; size: number }[]> {
711 const folder = trim(path, '/');
712 try {
713 const result: Endpoints['GET /repos/{owner}/{repo}/git/trees/{tree_sha}']['response']['data'] =
714 await this.request(`${repoURL}/git/trees/${branch}:${folder}`, {
715 // GitHub API supports recursive=1 for getting the entire recursive tree
716 // or omitting it to get the non-recursive tree
717 params: depth > 1 ? { recursive: 1 } : {},
718 });
719 return (
720 result.tree
721 // filter only files and up to the required depth
722 .filter(file => file.type === 'blob' && file.path && file.path.split('/').length <= depth)
723 .map(file => ({
724 type: file.type,
725 id: file.sha,
726 name: basename(file.path),
727 path: `${folder}/${file.path}`,
728 size: file.size || 0,
729 }))
730 );
731 } catch (err) {
732 if (err && err.status === 404) {
733 console.log('This 404 was expected and handled appropriately.');
734 return [];
735 } else {
736 throw err;
737 }
738 }
739 }
740
741 filterOpenAuthoringBranches = async (branch: string) => {
742 try {

Callers 2

updateTreeMethod · 0.95
API.spec.jsFile · 0.45

Calls 4

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

Tested by

no test coverage detected