@@ -13,12 +13,54 @@ org="$1"
1313repo=" $2 "
1414return_only_id=${3:- false}
1515
16- migrations=$( gh api -X GET /orgs/$org /migrations -F per_page=100 --jq ' .[] | {id: .id, repositories: .repositories.[].full_name, state: .state, created_at: .created_at}' )
16+ # Make the API call with error handling
17+ migrations=$( gh api -X GET /orgs/$org /migrations -F per_page=100 --jq ' .[] | {id: .id, repositories: .repositories.[].full_name, state: .state, created_at: .created_at}' 2>&1 )
18+ exit_code=$?
19+
20+ if [ $exit_code -ne 0 ]; then
21+ if echo " $migrations " | grep -q " Authorization failed\|HTTP 403" ; then
22+ echo " Error: Authorization failed (HTTP 403)" >&2
23+ echo " " >&2
24+ echo " This endpoint requires a classic Personal Access Token (PAT) instead of OAuth CLI token." >&2
25+ echo " Please export your classic PAT as GH_TOKEN:" >&2
26+ echo " export GH_TOKEN=your_classic_personal_access_token" >&2
27+ echo " " >&2
28+ echo " For more information, visit:" >&2
29+ echo " https://docs.github.com/migrations/using-ghe-migrator/exporting-migration-data-from-githubcom" >&2
30+ exit 1
31+ elif echo " $migrations " | grep -q " Not Found\|HTTP 404" ; then
32+ echo " Error: Organization not found or no access to migrations (HTTP 404)" >&2
33+ echo " " >&2
34+ echo " This could mean:" >&2
35+ echo " - The organization '$org ' doesn't exist" >&2
36+ echo " - You don't have access to view migrations for this organization" >&2
37+ echo " " >&2
38+ echo " Note: This endpoint requires a classic Personal Access Token (PAT)." >&2
39+ echo " Make sure you have exported your classic PAT as GH_TOKEN:" >&2
40+ echo " export GH_TOKEN=your_classic_personal_access_token" >&2
41+ exit 1
42+ else
43+ echo " Error: Failed to retrieve migrations" >&2
44+ echo " $migrations " >&2
45+ exit 1
46+ fi
47+ fi
1748
1849if [ " $return_only_id " = " false" ]; then
1950 most_recent_migration=$( echo " $migrations " | jq -s -r --arg repo " $org /$repo " ' map(select(.repositories == $repo)) | sort_by(.created_at) | last' )
2051else
2152 most_recent_migration=$( echo " $migrations " | jq -s -r --arg repo " $org /$repo " ' map(select(.repositories == $repo)) | sort_by(.created_at) | last | .id' )
2253fi
2354
55+ # Check if we found a migration for this repository
56+ if [ " $most_recent_migration " = " null" ] || [ -z " $most_recent_migration " ]; then
57+ echo " Error: No migrations found for repository $org /$repo " >&2
58+ echo " " >&2
59+ echo " This could mean:" >&2
60+ echo " - No migrations exist for this repository" >&2
61+ echo " - The repository name is incorrect" >&2
62+ echo " - You don't have access to migrations for this repository" >&2
63+ exit 1
64+ fi
65+
2466echo " $most_recent_migration "
0 commit comments