Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions scripts/vercel-ignore-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,23 @@ fi
# Only check PRs if we have the required variables
if [ -n "$VERCEL_GIT_PULL_REQUEST_ID" ] && [ -n "$GITHUB_TOKEN" ]; then
echo "Checking PR #$VERCEL_GIT_PULL_REQUEST_ID"

# Get PR info from GitHub API
PR_BASE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$VERCEL_GIT_REPO_OWNER/$VERCEL_GIT_REPO_SLUG/pulls/$VERCEL_GIT_PULL_REQUEST_ID" \
| jq -r '.base.ref')


# Get PR info from GitHub API (using grep/sed instead of jq since it's not available in Vercel)
API_URL="https://api.github.com/repos/$VERCEL_GIT_REPO_OWNER/$VERCEL_GIT_REPO_SLUG/pulls/$VERCEL_GIT_PULL_REQUEST_ID"
PR_RESPONSE=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$API_URL")

# Check if we got a valid response
if [ -z "$PR_RESPONSE" ]; then
echo "⚠️ No response from GitHub API"
elif echo "$PR_RESPONSE" | grep -q '"message"'; then
ERROR_MSG=$(echo "$PR_RESPONSE" | grep -o '"message":"[^"]*"' | sed 's/"message":"\([^"]*\)"/\1/')
Copy link
Preview

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern for extracting error messages is fragile and may break if the JSON contains escaped quotes or other special characters within the message string. Consider using a more robust approach or adding validation to handle edge cases.

Suggested change
ERROR_MSG=$(echo "$PR_RESPONSE" | grep -o '"message":"[^"]*"' | sed 's/"message":"\([^"]*\)"/\1/')
ERROR_MSG=$(echo "$PR_RESPONSE" | python3 -c 'import sys, json; print(json.load(sys.stdin).get("message", ""))')

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stick with grep/sed, since python env is much less certain and can change with version

echo "⚠️ GitHub API error: $ERROR_MSG"
fi

# Extract base.ref from JSON (handles multiline JSON format)
# Look for "base": { ... "ref": "branch-name" ... } across multiple lines
PR_BASE=$(echo "$PR_RESPONSE" | grep -A 5 '"base"' | grep '"ref"' | head -1 | sed 's/.*"ref"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')

# If we got a valid base branch
if [ -n "$PR_BASE" ] && [ "$PR_BASE" != "null" ]; then
echo "PR base branch: $PR_BASE"
Expand Down
Loading