Skip to content

Commit 8134391

Browse files
fix: enhance error handling for insufficient scopes in project board script (#127)
1 parent 1e01c2c commit 8134391

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

gh-cli/get-project-board-items.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
if [ $# -ne 2 ]; then
1111
echo "Usage: $0 <org> <project-number>"
1212
echo "Example: ./get-project-board-items.sh my-org 123"
13+
echo "Example: ./get-project-board-items.sh my-org 123" > results.txt
1314
echo ""
1415
echo "Note: This script works with Projects V2 (the newer project boards)"
1516
echo "To find project number, check the URL: github.com/orgs/ORG/projects/NUMBER"
@@ -145,7 +146,26 @@ response=$(gh api graphql --paginate -f org="$org" -F projectNumber="$project_nu
145146

146147
# Check for errors
147148
if [ $? -ne 0 ]; then
148-
if echo "$response" | grep -q "Could not resolve to a ProjectV2"; then
149+
if echo "$response" | grep -q "INSUFFICIENT_SCOPES"; then
150+
echo "❌ Error: Your GitHub token doesn't have the required permissions"
151+
echo ""
152+
echo "🔐 Required scope: 'read:project'"
153+
echo ""
154+
echo "Your token currently has these scopes:"
155+
# Extract current scopes from the error message
156+
current_scopes=$(echo "$response" | grep -o "but your token has only been granted the: \[.*\]" | sed "s/.*\[\(.*\)\].*/\1/" | tr ',' '\n' | sed "s/['\", ]//g" | grep -v "^$" | sort | uniq)
157+
if [ -n "$current_scopes" ]; then
158+
echo "$current_scopes" | sed 's/^/ • /'
159+
else
160+
echo " • (Unable to determine current scopes)"
161+
fi
162+
echo ""
163+
echo "📝 To fix this issue, run:"
164+
echo " gh auth refresh -h github.com -s read:project"
165+
echo ""
166+
echo "ℹ️ If using a PAT, go update the permissions to include the 'read:project' scope."
167+
exit 1
168+
elif echo "$response" | grep -q "Could not resolve to a ProjectV2"; then
149169
echo "❌ Error: Project #$project_number not found in organization '$org'"
150170
echo "Make sure:"
151171
echo "- The project number is correct"

0 commit comments

Comments
 (0)