fix: loop over the open pull requests to get an exact title match

The q= argument of the search may not return matches that are exactly
the title depending on how the issue search is defined.

https://code.forgejo.org/forgejo/end-to-end/actions/runs/3505/jobs/4

is an example of a failed run because q= did not match the right pull
request.
This commit is contained in:
Earl Warren 2025-07-20 07:12:05 +02:00
parent 80ba22a9a4
commit 3726ed27c9
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -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() {