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

Method getFileSha

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

Source from the content-addressed store, hash-verified

969 }
970
971 async getFileSha(path: string, { repoURL = this.repoURL, branch = this.branch } = {}) {
972 /**
973 * We need to request the tree first to get the SHA. We use extended SHA-1
974 * syntax (<rev>:<path>) to get a blob from a tree without having to recurse
975 * through the tree.
976 */
977
978 const pathArray = path.split('/');
979 const filename = last(pathArray);
980 const directory = initial(pathArray).join('/');
981 const fileDataPath = encodeURIComponent(directory);
982 const fileDataURL = `${repoURL}/git/trees/${branch}:${fileDataPath}`;
983
984 const result: Endpoints['GET /repos/{owner}/{repo}/git/trees/{tree_sha}']['response']['data'] =
985 await this.request(fileDataURL);
986 const file = result.tree.find(file => file.path === filename);
987 if (file) {
988 return file.sha;
989 } else {
990 throw new APIError('Not Found', 404, API_NAME);
991 }
992 }
993
994 async deleteFiles(paths: string[], message: string) {
995 if (this.useOpenAuthoring) {

Callers 1

readFileMethod · 0.95

Calls 2

requestMethod · 0.95
findMethod · 0.80

Tested by

no test coverage detected