(branchName: string, sha: string)
| 1305 | } |
| 1306 | |
| 1307 | async createBranch(branchName: string, sha: string) { |
| 1308 | try { |
| 1309 | const result = await this.createRef('heads', branchName, sha); |
| 1310 | return result; |
| 1311 | } catch (e) { |
| 1312 | const message = String(e.message || ''); |
| 1313 | if (message === 'Reference update failed') { |
| 1314 | await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME); |
| 1315 | } else if ( |
| 1316 | message === 'Reference already exists' && |
| 1317 | branchName.startsWith(`${CMS_BRANCH_PREFIX}/`) |
| 1318 | ) { |
| 1319 | try { |
| 1320 | // this can happen if the branch wasn't deleted when the PR was merged |
| 1321 | // we backup the existing branch just in case and patch it with the new sha |
| 1322 | await this.backupBranch(branchName); |
| 1323 | const result = await this.patchBranch(branchName, sha, { force: true }); |
| 1324 | return result; |
| 1325 | } catch (e) { |
| 1326 | console.log(e); |
| 1327 | } |
| 1328 | } |
| 1329 | throw e; |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | assertCmsBranch(branchName: string) { |
| 1334 | return branchName.startsWith(`${CMS_BRANCH_PREFIX}/`); |
no test coverage detected