diff --git a/cascading-pr.sh b/cascading-pr.sh index 7dd7180..99f3c81 100755 --- a/cascading-pr.sh +++ b/cascading-pr.sh @@ -132,7 +132,19 @@ function pr_get_origin() { function pr_get_destination() { local title=$(pr_destination_title) - repo_curl ${options[destination_repo]} api --get --data state=open --data type=pulls --data-urlencode q="$title" ${options[destination_api]}/issues | jq --raw-output .[0] >$TMPDIR/destination-pr.json + local page=1 + touch $TMPDIR/destination-pr.json + while true; do + repo_curl ${options[destination_repo]} api --get --data page=$page --data state=open --data type=pulls ${options[destination_api]}/issues >$TMPDIR/destination-prs.json + if test "$(jq length <$TMPDIR/destination-prs.json)" = 0; then + break + fi + jq --argjson title "\"$title\"" '.[] | select(.title == $title)' <$TMPDIR/destination-prs.json >$TMPDIR/destination-pr.json + if test -s $TMPDIR/destination-pr.json; then + break + fi + page=$(expr $page + 1) + done } function pr_get() {