(branchName: string, sha: string)
| 1292 | } |
| 1293 | |
| 1294 | async createBranch(branchName: string, sha: string) { |
| 1295 | try { |
| 1296 | const result = await this.createRef('heads', branchName, sha); |
| 1297 | return result; |
| 1298 | } catch (e) { |
| 1299 | const message = String(e.message || ''); |
| 1300 | if (message === 'Reference update failed') { |
| 1301 | await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME); |
| 1302 | } else if ( |
| 1303 | message === 'Reference already exists' && |
| 1304 | branchName.startsWith(`${CMS_BRANCH_PREFIX}/`) |
| 1305 | ) { |
| 1306 | try { |
| 1307 | // this can happen if the branch wasn't deleted when the PR was merged |
| 1308 | // we backup the existing branch just in case and patch it with the new sha |
| 1309 | await this.backupBranch(branchName); |
| 1310 | const result = await this.patchBranch(branchName, sha, { force: true }); |
| 1311 | return result; |
| 1312 | } catch (e) { |
| 1313 | console.log(e); |
| 1314 | } |
| 1315 | } |
| 1316 | throw e; |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | assertCmsBranch(branchName: string) { |
| 1321 | return branchName.startsWith(`${CMS_BRANCH_PREFIX}/`); |
no test coverage detected