Skip to content

Commit 07b4743

Browse files
authored
fix: first pr comment logic (2nd attempt) (#12)
1 parent fba6619 commit 07b4743

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

.github/workflows/pr-auto-comments.yml

+11-6
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,22 @@ jobs:
104104
105105
# Only check if this is their first PR if needed
106106
if [[ "${{ steps.event.outputs.type }}" == "opened" ]]; then
107-
# Check if this is their first PR to the repo using REST API instead of GraphQL
108-
PR_COUNT=$(gh api -H "Accept: application/vnd.github+json" \
109-
"/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/pulls?state=all&creator=$PR_AUTHOR" | jq length)
107+
# Use the GitHub Search API to find PRs by this author to this specific repo
108+
SEARCH_QUERY="repo:${{ github.repository }} is:pr author:$PR_AUTHOR"
109+
PR_SEARCH=$(gh api -H "Accept: application/vnd.github+json" \
110+
"/search/issues?q=$(echo $SEARCH_QUERY | sed 's/ /%20/g')&per_page=100" || echo '{"total_count": 0}')
110111
111-
echo "Found $PR_COUNT PRs from this contributor"
112+
# Get the total count from the search results
113+
PR_COUNT=$(echo $PR_SEARCH | jq '.total_count')
114+
115+
echo "Search query: $SEARCH_QUERY"
116+
echo "Found $PR_COUNT PRs from this contributor to this repository"
112117
113118
if [ "$PR_COUNT" -eq 1 ]; then
114-
echo "First PR from this contributor"
119+
echo "First PR from this contributor to this repository"
115120
echo "is_first_pr=true" >> $GITHUB_OUTPUT
116121
else
117-
echo "Not the first PR from this contributor"
122+
echo "Not the first PR from this contributor to this repository"
118123
echo "is_first_pr=false" >> $GITHUB_OUTPUT
119124
fi
120125
else

0 commit comments

Comments
 (0)