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

Method getFileSha

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

Source from the content-addressed store, hash-verified

982 }
983
984 async getFileSha(path: string, { repoURL = this.repoURL, branch = this.branch } = {}) {
985 /**
986 * We need to request the tree first to get the SHA. We use extended SHA-1
987 * syntax (<rev>:<path>) to get a blob from a tree without having to recurse
988 * through the tree.
989 */
990
991 const pathArray = path.split('/');
992 const filename = last(pathArray);
993 const directory = initial(pathArray).join('/');
994 const fileDataPath = encodeURIComponent(directory);
995 const fileDataURL = `${repoURL}/git/trees/${branch}:${fileDataPath}`;
996
997 const result: Endpoints['GET /repos/{owner}/{repo}/git/trees/{tree_sha}']['response']['data'] =
998 await this.request(fileDataURL);
999 const file = result.tree.find(file => file.path === filename);
1000 if (file) {
1001 return file.sha;
1002 } else {
1003 throw new APIError('Not Found', 404, API_NAME);
1004 }
1005 }
1006
1007 async deleteFiles(paths: string[], message: string) {
1008 if (this.useOpenAuthoring) {

Callers 1

readFileMethod · 0.95

Calls 2

requestMethod · 0.95
findMethod · 0.80

Tested by

no test coverage detected