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

Method getFileSha

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

Source from the content-addressed store, hash-verified

944 }
945
946 async getFileSha(path: string, { repoURL = this.repoURL, branch = this.branch } = {}) {
947 /**
948 * We need to request the tree first to get the SHA. We use extended SHA-1
949 * syntax (<rev>:<path>) to get a blob from a tree without having to recurse
950 * through the tree.
951 */
952
953 const pathArray = path.split('/');
954 const filename = last(pathArray);
955 const directory = initial(pathArray).join('/');
956 const fileDataPath = encodeURIComponent(directory);
957 const fileDataURL = `${repoURL}/git/trees/${branch}:${fileDataPath}`;
958
959 const result: Endpoints['GET /repos/{owner}/{repo}/git/trees/{tree_sha}']['response']['data'] =
960 await this.request(fileDataURL);
961 const file = result.tree.find(file => file.path === filename);
962 if (file) {
963 return file.sha;
964 } else {
965 throw new APIError('Not Found', 404, API_NAME);
966 }
967 }
968
969 async deleteFiles(paths: string[], message: string) {
970 if (this.useOpenAuthoring) {

Callers 1

readFileMethod · 0.95

Calls 2

requestMethod · 0.95
findMethod · 0.80

Tested by

no test coverage detected