@@ -22,15 +22,26 @@ clone() {
2222}
2323
2424# Try the PR author's branch in case it exists on the deps as well.
25- # If BUILDKITE_BRANCH is set, it will contain either:
25+ # First we check if BUILDKITE_BRANCH is defined,
26+ # if it isn't we can assume this is a Netlify build
27+ if [ -z ${BUILDKITE_BRANCH+x} ]; then
28+ # Netlify doesn't give us info about the fork so we have to get it from GitHub API
29+ apiEndpoint=" https://api.github.com/repos/matrix-org/matrix-react-sdk/pulls/"
30+ apiEndpoint+=$REVIEW_ID
31+ head=$( curl $apiEndpoint | jq -r ' .head.label' )
32+ else
33+ head=$BUILDKITE_BRANCH
34+ fi
35+
36+ # If head is set, it will contain either:
2637# * "branch" when the author's branch and target branch are in the same repo
27- # * "author :branch" when the author's branch is in their fork
38+ # * "fork :branch" when the author's branch is in their fork or if this is a Netlify build
2839# We can split on `:` into an array to check.
29- BUILDKITE_BRANCH_ARRAY =(${BUILDKITE_BRANCH //:/ } )
30- if [[ " ${# BUILDKITE_BRANCH_ARRAY [@]} " == " 1" ]]; then
40+ BRANCH_ARRAY =(${head //:/ } )
41+ if [[ " ${# BRANCH_ARRAY [@]} " == " 1" ]]; then
3142 clone $deforg $defrepo $BUILDKITE_BRANCH
32- elif [[ " ${# BUILDKITE_BRANCH_ARRAY [@]} " == " 2" ]]; then
33- clone ${BUILDKITE_BRANCH_ARRAY [0]} $defrepo ${BUILDKITE_BRANCH_ARRAY [1]}
43+ elif [[ " ${# BRANCH_ARRAY [@]} " == " 2" ]]; then
44+ clone ${BRANCH_ARRAY [0]} $defrepo ${BRANCH_ARRAY [1]}
3445fi
3546# Try the target branch of the push or PR.
3647clone $deforg $defrepo $BUILDKITE_PULL_REQUEST_BASE_BRANCH
0 commit comments