scripts: find the pull request after it is merged

pr-at-commit.sh searched only open pull requests, so a pull request
merged before the comment run of its last workflow finished kept the
"emerging" status line in the bot comment, as on #15346 and #15348.

It now also searches the 30 most recently updated closed pull requests
and accepts a merged one whose head is the commit. A rebase merge keeps
the pull request head, so upsert-comment-section.sh still finds it at
HEAD_SHA.

Signed-off-by: Zakk <zakk@gentoozh.org>
This commit is contained in:
Zakk committed 2026-10-22 22:20:26 +11:00
1 parent 73825717ea
commit d06ff6a93f
1 file changed
+9 -5
+9 -5
View File
@@ -5,8 +5,12 @@ set -euo pipefail
repository=${1:?repository}
sha=${2:?sha}
# commits/{sha}/pulls returns nothing for a fork PR, and artifacts are not trusted to name it
pulls=$(gh api "repos/$repository/pulls?state=open&per_page=100" --paginate --slurp)
jq -r --arg sha "$sha" '
first(.[][] | select(.head.sha == $sha) | .number) // empty
' <<< "$pulls"
# commits/{sha}/pulls returns nothing for a fork PR, and artifacts are not trusted to name it.
# A pull request merged before its comment run is closed by then, so the recently updated
# closed ones count too when they were merged.
{
gh api "repos/$repository/pulls?state=open&per_page=100" --paginate
gh api "repos/$repository/pulls?state=closed&sort=updated&direction=desc&per_page=30"
} | jq -rs --arg sha "$sha" '
first(.[][] | select(.head.sha == $sha and (.state == "open" or .merged_at != null)) | .number) // empty
'