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

Method getFileSha

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

Source from the content-addressed store, hash-verified

426 }
427
428 async getFileSha(path: string, { repoURL = this.repoURL, branch = this.branch } = {}) {
429 /**
430 * We need to request the tree first to get the SHA. We use extended SHA-1
431 * syntax (<rev>:<path>) to get a blob from a tree without having to recurse
432 * through the tree.
433 */
434
435 const pathArray = path.split('/');
436 const filename = last(pathArray);
437 const directory = initial(pathArray).join('/');
438 const fileDataPath = encodeURIComponent(directory);
439 const fileDataURL = `${repoURL}/git/trees/${branch}:${fileDataPath}`;
440
441 const result: GitGetTreeResponse = await this.request(fileDataURL);
442 const file = result.tree.find(file => file.path === filename);
443 if (file) {
444 return file.sha;
445 } else {
446 throw new APIError('Not Found', 404, API_NAME);
447 }
448 }
449
450 async deleteFiles(paths: string[], message: string) {
451 const operations: ChangeFileOperation[] = await Promise.all(

Callers 3

readFileMethod · 0.95
deleteFilesMethod · 0.95

Calls 2

requestMethod · 0.95
findMethod · 0.80

Tested by

no test coverage detected