microsoft/typespec
Publicmirrored from https://github.com/microsoft/typespecAvailable
eng/common/scripts/resolve-target-branch.js
23lines · modecode
| 1 | // @ts-check |
| 2 | const prTargetBranch = process.env["SYSTEM_PULLREQUEST_TARGETBRANCHNAME"]; |
| 3 | const currentBranch = process.env["BUILD_SOURCEBRANCH"]; |
| 4 | |
| 5 | console.log("Branches:", { |
| 6 | prTargetBranch, |
| 7 | currentBranch, |
| 8 | }); |
| 9 | |
| 10 | if (prTargetBranch !== undefined) { |
| 11 | console.log("Target branch is", prTargetBranch); |
| 12 | console.log(`##vso[task.setvariable variable=TARGET_BRANCH]${prTargetBranch}`); |
| 13 | } else if (currentBranch) { |
| 14 | const match = currentBranch.match(/refs\/heads\/gh-readonly-queue\/(.*)\/pr-.*/); |
| 15 | if (match !== null) { |
| 16 | const targetBranch = match[1]; |
| 17 | console.log("Target branch is", targetBranch); |
| 18 | console.log(`##vso[task.setvariable variable=TARGET_BRANCH]${targetBranch}`); |
| 19 | } |
| 20 | } else { |
| 21 | console.log("Failed to resolve target branch."); |
| 22 | process.exit(1); |
| 23 | } |
| 24 | |