gh-gei
gh-gei copied to clipboard
GitHub: An invalid PAT should surface a user friendly error
Description
If a GH PAT is not valid, an actionable user friendly error should be surfaced.
Reproduction Steps
export ADO_PAT="VALID_PAT"
export GH_PAT="1234"
gh ado2gh migrate-repo --ado-org "valet-testing" --ado-team-project "build-playground" --ado-repo "forecast-regression-test" --github-org "import-testing" --github-repo "build-playground-forecast-regression-test"
Will output the following:
[2023-10-12 10:29:39] [INFO] You are running the latest version of the ado2gh CLI [v1.2.0]
[2023-10-12 10:29:39] [INFO] ADO ORG: valet-testing
[2023-10-12 10:29:39] [INFO] ADO TEAM PROJECT: build-playground
[2023-10-12 10:29:39] [INFO] ADO REPO: forecast-regression-test
[2023-10-12 10:29:39] [INFO] GITHUB ORG: import-testing
[2023-10-12 10:29:39] [INFO] GITHUB REPO: build-playground-forecast-regression-test
[2023-10-12 10:29:39] [INFO] Migrating Repo...
[2023-10-12 10:29:40] [ERROR] Failed to lookup the Organization ID for organization 'import-testing'
A 401
error was surfaced in the logs:
2023-10-12 10:29:05] [ERROR] OctoshiftCLI.OctoshiftCliException: Failed to lookup the Organization ID for organization 'import-testing'
---> OctoshiftCLI.OctoshiftCliException: Unauthorized. Please check your token and try again
---> System.Net.Http.HttpRequestException: GitHub API error: {"message":"Bad credentials","documentation_url":"https://docs.github.com/graphql"}
---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
I haven't looked on how errors are surfaced in Octoshift, and I know each provider has its own set of error codes for different errors, but it would be really nice to surface a user friendly error that shows the correct perms needed!
Echoing this, I had to dig a little to find the verbose flag. I'll stick up a PR to at least suggest that on this failure.