This can be determined by calling the following api,
GET /repos/{owner}/{repo}/compare/{basehead}
e.g. openshift/thanos:master vs thanos-io/thanos:v0.22.0
curl -s https://api.github.com/repos/openshift/thanos/compare/{master}...{thanos-io:v0.22.0} -o - | jq .ahead_by