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>
17 lines
663 B
Bash
Executable File
17 lines
663 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# usage: pr-at-commit.sh <repository> <sha>
|
|
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.
|
|
# 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
|
|
'
|