|
| 1 | +#!/bin/bash |
| 2 | +# Quick test for GitHub PAT GraphQL permissions |
| 3 | +# ./utils/github_pat_check.sh "$(cat ./easycla-github-oauth-token.secret)" finos fluxnova-modeler 85 |
| 4 | +# ./utils/github_pat_check.sh "$(cat /etc/github/oauth)" cncf devstats 114 |
| 5 | + |
| 6 | +if ( [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ] ) |
| 7 | +then |
| 8 | + echo "Usage: $0 YOUR_GITHUB_TOKEN org repo pr-number" |
| 9 | + echo "Example: $0 ghp_xxxxxxxxxxxxxxxxxxxx cncf devstats 114" |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +TOKEN="$1" |
| 14 | +ORG="$2" |
| 15 | +REPO="$3" |
| 16 | +PR="$4" |
| 17 | +echo "Testing GitHub PAT GraphQL with token: ${TOKEN:0:4} for $ORG/$REPO PR:$PR..." |
| 18 | + |
| 19 | +echo -e "\n1. Testing Simple GraphQL Query:" |
| 20 | +echo "--------------------------------" |
| 21 | +curl -s -H "Authorization: Bearer $TOKEN" \ |
| 22 | + -H "Content-Type: application/json" \ |
| 23 | + -d '{"query":"query { viewer { login } }"}' \ |
| 24 | + https://api.github.com/graphql |
| 25 | + |
| 26 | +echo -e "\n\n2. Checking Token Scopes:" |
| 27 | +echo "------------------------" |
| 28 | +curl -s -I -H "Authorization: Bearer $TOKEN" \ |
| 29 | + https://api.github.com/user | grep -i "x-oauth-scopes" || echo "No scopes header found" |
| 30 | + |
| 31 | +echo -e "\n\n3. Testing Repository Access:" |
| 32 | +echo "----------------------------" |
| 33 | +curl -s -H "Authorization: Bearer $TOKEN" \ |
| 34 | + -H "Content-Type: application/json" \ |
| 35 | + -d '{"query":"query { repository(owner:\"'"$ORG"'\", name:\"'"$REPO"'\") { name } }"}' \ |
| 36 | + https://api.github.com/graphql |
| 37 | + |
| 38 | +echo -e "\n\n4. Testing PR Commits (the failing query):" |
| 39 | +echo "------------------------------------------" |
| 40 | +curl -s -H "Authorization: Bearer $TOKEN" \ |
| 41 | + -H "Content-Type: application/json" \ |
| 42 | + -d '{"query":"query { repository(owner:\"'"$ORG"'\", name:\"'"$REPO"'\") { pullRequest(number:'$PR') { commits(first:1) { nodes { commit { oid } } } } } }"}' \ |
| 43 | + https://api.github.com/graphql |
| 44 | + |
| 45 | +echo -e "\n" |
0 commit comments