| 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) { |