(branchName: string, sha: string)
| 1266 | } |
| 1267 | |
| 1268 | async createBranch(branchName: string, sha: string) { |
| 1269 | try { |
| 1270 | const result = await this.createRef('heads', branchName, sha); |
| 1271 | return result; |
| 1272 | } catch (e) { |
| 1273 | const message = String(e.message || ''); |
| 1274 | if (message === 'Reference update failed') { |
| 1275 | await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME); |
| 1276 | } else if ( |
| 1277 | message === 'Reference already exists' && |
| 1278 | branchName.startsWith(`${CMS_BRANCH_PREFIX}/`) |
| 1279 | ) { |
| 1280 | try { |
| 1281 | // this can happen if the branch wasn't deleted when the PR was merged |
| 1282 | // we backup the existing branch just in case and patch it with the new sha |
| 1283 | await this.backupBranch(branchName); |
| 1284 | const result = await this.patchBranch(branchName, sha, { force: true }); |
| 1285 | return result; |
| 1286 | } catch (e) { |
| 1287 | console.log(e); |
| 1288 | } |
| 1289 | } |
| 1290 | throw e; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | assertCmsBranch(branchName: string) { |
| 1295 | return branchName.startsWith(`${CMS_BRANCH_PREFIX}/`); |
no test coverage detected