Closed Liturgist closed 2 years ago
Hey @Liturgist,
Sorry to hear you're running into issues here. Thanks for the report.
From what you've provided, it looks like you're leveraging GitHub Enterprise, and accessing a GitHub instance running on your company's own servers. While this project has support for GitHub Enterprise (thanks to @Cellivar and @v2kiran), I've never personally used it, so I don't have any experience with it. So, I'm going to shoot in the dark here just a little bit:
PowerShell
in your GitHub Enterprise instance?Get-Error
reported back that the server was GitHub.com
, given that everything else was accessing your company's instance instead. Not sure what to take from that.Get-GitHubUser -Current
)?@HowardWolosky, you are right. I did not notice that. We do have a GitHub Enterprise Server to which it appears to be connecting. How can I tell it to connect to the public github.com?
I removed the GH_HOST environment variable.
I used the EXAMPLE 5 command, but it still appears to be connecting to our GitHub Enterprise Server. The Personal Access Token used was created on the public github.com.
PS C:\Users\pwatson2> Get-GitHubRepository -Uri https://github.com/microsoft/PowerShellForGitHub
Invoke-WebRequest: C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1:313
Line |
313 | $result = Invoke-WebRequest @params
| ~~~~~~~~~~~~~~~~~~~~~~~~~
| Response status code does not indicate success: 400 (Bad Request).
How can I tell it to connect to the public github.com?
The README talks about how to configure GitHub Enterprise. You'll probably want to run this:
Set-GitHubConfiguration -ApiHostName 'github.com'
That should reset it to use public GitHub instead of GitHub Enterprise. Alternatively, you can run this:
Reset-GitHubConfiguration
and that will get you back to the out-of-the-box state (in case you might have messed with other configuration properties accidentally).
I removed the GH_HOST environment variable.
This project doesn't use any environment nor global variables. Everything is self-contained in the module configuration.
I used the EXAMPLE 5 command, but it still appears to be connecting to our GitHub Enterprise Server
Yeah, that wouldn't work. When you use the Uri
parameter, it just parses the OwnerName
and RepositoryName
from the Uri
, and then operates against the configured GitHub host to get the requested info. If you want to operate against the public GitHub.com, you need to fix your ApiHostName
.
@HowardWolosky, yes, I can see how the ApiHostName would be a problem. I have reset it as yo recommended. It now appears to be github.com
. I still have the same failure, but only github.com
is mentioned and not out GitHub Enterprise Server. What am I missing?
This does work as expected on my personal machine that is not on the corporate network.
PS C:\Users\lit\bin> Reset-GitHubConfiguration
PS C:\Users\lit\bin> Get-GitHubConfiguration ApiHostName
github.com
PS C:\Users\lit\bin> Get-GitHubRepository -Uri https://github.com/microsoft/PowerShellForGitHub
Invoke-WebRequest: C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1:313
Line |
313 | $result = Invoke-WebRequest @params
| ~~~~~~~~~~~~~~~~~~~~~~~~~
| Response status code does not indicate success: 400 (Bad Request).
PS C:\Users\lit\bin> Get-Error
Exception :
Type : Microsoft.PowerShell.Commands.HttpResponseException
Response : StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
Server: GitHub.com
Date: Thu, 29 Sep 2022 03:24:08 GMT
Transfer-Encoding: chunked
Vary: Accept-Encoding, Accept, X-Requested-With
X-GitHub-Request-Id: 2A87:5227:4EEC460:A101E33:63350FD8
}
TargetSite :
Name : ThrowTerminatingError
DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation, Version=7.2.6.500, Culture=neutral,
PublicKeyToken=31bf3856ad364e35
MemberType : Method
Module : System.Management.Automation.dll
Message : Response status code does not indicate success: 400 (Bad Request).
Source : System.Management.Automation
HResult : -2146233088
StackTrace :
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
TargetObject : Method: GET, RequestUri: 'https://api.github.com/repos/microsoft/PowerShellForGitHub?', Version: 1.1, Content: <null>, Headers:
{
Authorization: token ▬
User-Agent: PowerShellForGitHub
Accept: application/vnd.github.nebula-preview+json
Accept: application/vnd.github.baptiste-preview+json
Accept: application/vnd.github.mercy-preview+json
}
CategoryInfo : InvalidOperation: (Method: GET, Reques…rcy-preview+json
}:HttpRequestMessage) [Invoke-WebRequest], HttpResponseException
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
InvocationInfo :
MyCommand : Invoke-WebRequest
ScriptLineNumber : 313
OffsetInLine : 23
HistoryId : 47
ScriptName : C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1
Line : $result = Invoke-WebRequest @params
PositionMessage : At C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1:313 char:23
+ $result = Invoke-WebRequest @params
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot : C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1
PSCommandPath : C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1
InvocationName : Invoke-WebRequest
CommandOrigin : Internal
ScriptStackTrace : at Invoke-GHRestMethod, C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1: line 313
at Invoke-GHRestMethodMultipleResult, C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubCore.ps1: line 703
at Get-GitHubRepository, C:\Users\lit\Documents\PowerShell\Modules\PowerShellForGitHub\0.16.1\GitHubRepositories.ps1: line 860
at <ScriptBlock>, <No file>: line 1
I still have the same failure, but only
github.com
is mentioned and not out GitHub Enterprise Server. What am I missing?This does work as expected on my personal machine that is not on the corporate network.
All I can suggest is a complete reset of everything:
Reset-GitHubConfiguration
Clear-GitHubAuthentication
and then trying an unauthenticated command
Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub
That request will work unauthenticated (just verified again). If it still doesn't work, and it's working fine on your personal machine, then that means that your corporate machine is running through a proxy that is modifying the REST request and causing it to fail. If that does work, then you can try adding back in your token and we can further debug what's happening from there.
Many thanks @HowardWolosky. It is working now. Although, I do not understand why it did not work when I used Reset-GitHubConfigration
before. I will press on. Thanks.
Issue Details
This is probably just a getting started problem. What about this request is "bad"?
Steps to reproduce the issue
Verbose logs showing the problem
Suggested solution to the issue
Requested Assignment
Operating System
PowerShell Version
Module Version