- ref=$(curl "${gerrit_url}/changes/${gerrit_id}${gerrit_query}" | tail -n+2 | jq -r "$gerrit_json_query")
- change_status=$(curl "${gerrit_url}/changes/${gerrit_id}${gerrit_query}" | tail -n+2 | jq -r "$gerrit_json_query_status")
+ case $project in
+ lttng-*)
+ # This is necessary since a cherry pick can have the same change id
+ # across branches. Still this is only valid for projects where the
+ # branch name fits the same branch name style of the lttng-tools
+ # project.
+ # We will need to be much more clever if the situation arise where
+ # we need to depends-on a cherry picked change id for the
+ # userspace-rcu or babeltrace project. Until then let's use this
+ # hack. The quick solution to this is to tell the committer to change
+ # the change id. We could also be clever and require that the
+ # "branch name" be included in the `Depends-on` clause.
+ local_query="${gerrit_url}/changes/?q=change:${gerrit_id}+branch:${GERRIT_BRANCH}${gerrit_query}"
+ default_branch="${GERRIT_BRANCH}"
+ ;;
+ *)
+ local_query="${gerrit_url}/changes/?q=change:${gerrit_id}${gerrit_query}"
+ default_branch="master"
+ ;;
+ esac
+
+ json_doc=$(curl "$local_query" | tail -n+2)
+ count=$(jq -r '. | length' <<< "$json_doc")
+ if [ "$count" != "1" ]; then
+ echo "Expected an array of size 1 got $count"
+ exit 1
+ fi
+
+ ref=$(jq -r "$gerrit_json_query" <<< "$json_doc")
+ change_status=$(jq -r "$gerrit_json_query_status" <<< "$json_doc")