Skip to content

Commit c4e5d83

Browse files
committed
fix: discover-lean-pr-testing.yml more reliably finds PRs (#28692)
See [#nightly-testing > Mathlib status updates @ 💬](https://leanprover.zulipchat.com/#narrow/channel/428973-nightly-testing/topic/Mathlib.20status.20updates/near/535301862)
1 parent 691373c commit c4e5d83

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

.github/workflows/discover-lean-pr-testing.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,36 @@ jobs:
7474
# This will only fetch commits newer than previously fetched commits (ie $OLD)
7575
git fetch origin tag "$NEW" --no-tags
7676
77-
# Find all commits to lean4 between the $OLD and $NEW toolchains
78-
# and extract the github PR numbers
79-
# (drop anything that doesn't look like a PR number from the final result)
80-
PRS=$(git log --oneline "$OLD..$NEW" | sed 's/.*(#\([0-9]\+\))$/\1/' | grep -E '^[0-9]+$')
77+
# Get all commit SHAs between the $OLD and $NEW toolchains
78+
COMMIT_SHAS=$(git log --format="%H" "$OLD..$NEW")
79+
80+
# Initialize an empty string to collect PR numbers
81+
PRS=""
82+
83+
# For each commit, query the GitHub API to get associated PRs
84+
for commit_sha in $COMMIT_SHAS; do
85+
echo "Checking commit $commit_sha for associated PRs..."
86+
87+
# Query GitHub API for PRs associated with this commit
88+
# Using jq to extract PR numbers from the response
89+
pr_numbers=$(curl -s -H "Accept: application/vnd.github.v3+json" \
90+
"https://api.github.com/repos/leanprover/lean4/commits/$commit_sha/pulls" | \
91+
jq -r '.[] | select(.merged_at != null) | .number | tostring' 2>/dev/null || echo "")
92+
93+
# Add each PR number to our list (duplicates will be handled later)
94+
for pr_num in $pr_numbers; do
95+
if [[ "$pr_num" =~ ^[0-9]+$ ]]; then
96+
PRS="$PRS $pr_num"
97+
echo "Found PR #$pr_num associated with commit $commit_sha"
98+
fi
99+
done
100+
done
101+
102+
# Remove duplicates and trim whitespace
103+
PRS=$(echo "$PRS" | tr ' ' '\n' | sort -u | tr '\n' ' ' | xargs)
81104
82105
# Output the PRs
83-
echo "$PRS"
106+
echo "Found PRs: $PRS"
84107
printf "prs<<EOF\n%s\nEOF" "$PRS" >> "$GITHUB_OUTPUT"
85108
86109
- name: Use merged PRs information

0 commit comments

Comments
 (0)