Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Here are some general guidelines
## Adding New Configuration Properties

If you want to add a new configuration value to the module, you must modify the following:
* In `Restore-GitHubConfiguration`, update `$config` to declare the new property along with
* In `Import-GitHubConfiguration`, update `$config` to declare the new property along with
it's default value, being sure that PowerShell will understand what its type is.
* Update `Get-GitHubConfiguration` and add the new property name to the `ValidateSet` list
so that tab-completion and documentation gets auto-updated. You shouldn't have to add anything
Expand Down
19 changes: 17 additions & 2 deletions GitHubConfiguration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ function Set-GitHubConfiguration
created/updated and the specified configuration changes will only remain in memory/effect
for the duration of this PowerShell session.

.PARAMETER GitHubBaseUrl
The base URL of the GitHub instance to communicate with. Defaults to 'github.com'. Provide
a different URL when using a GitHub Enterprise server. The server must respond to the
standard API interface, for instance, api.github.contoso.com.

.EXAMPLE
Set-GitHubConfiguration -WebRequestTimeoutSec 120 -SuppressNoTokenWarning

Expand All @@ -158,6 +163,12 @@ function Set-GitHubConfiguration

Disables the logging of any activity to the logfile specified in LogPath, but for this
session only.

.EXAMPLE
Set-GitHubConfiguration -GitHubBaseUrl "github.contoso.com"

Sets all requests to connect to a GitHub Enterprise server running at
api.github.contoso.com.
#>
[CmdletBinding(SupportsShouldProcess)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
Expand Down Expand Up @@ -197,7 +208,9 @@ function Set-GitHubConfiguration
[ValidateRange(0, 3600)]
[int] $WebRequestTimeoutSec,

[switch] $SessionOnly
[switch] $SessionOnly,

[string] $GitHubBaseUrl
)

$persistedConfig = $null
Expand Down Expand Up @@ -273,7 +286,8 @@ function Get-GitHubConfiguration
'RetryDelaySeconds',
'SuppressNoTokenWarning',
'SuppressTelemetryReminder',
'WebRequestTimeoutSec')]
'WebRequestTimeoutSec',
'GitHubBaseUrl')]
[string] $Name
)

Expand Down Expand Up @@ -606,6 +620,7 @@ function Import-GitHubConfiguration
'suppressNoTokenWarning' = $false
'suppressTelemetryReminder' = $false
'webRequestTimeoutSec' = 0
'gitHubBaseUrl' = 'github.com'
}

$jsonObject = Read-GitHubConfiguration -Path $Path
Expand Down
13 changes: 7 additions & 6 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# Licensed under the MIT License.

@{
gitHubApiUrl = 'https://api.github.com'
gitHubApiReposUrl = 'https://api.github.com/repos'
gitHubApiOrgsUrl = 'https://api.github.com/orgs'
defaultAcceptHeader = 'application/vnd.github.v3+json'
mediaTypeVersion = 'v3'
squirrelAcceptHeader = 'application/vnd.github.squirrel-girl-preview'
Expand Down Expand Up @@ -154,7 +151,9 @@ function Invoke-GHRestMethod
# we'll just always continue the existing one...
$stopwatch.Start()

$url = "$script:gitHubApiUrl/$UriFragment"
$gitHubApiUrl = "https://api.$(Get-GitHubConfiguration -Name "GitHubBaseUrl")"

$url = "$gitHubApiUrl/$UriFragment"

# It's possible that we are directly calling the "nextLink" from a previous command which
# provides the full URI. If that's the case, we'll just use exactly what was provided to us.
Expand Down Expand Up @@ -735,8 +734,10 @@ function Split-GitHubUri
repositoryName = [String]::Empty
}

if (($Uri -match '^https?://(?:www.)?github.com/([^/]+)/?([^/]+)?(?:/.*)?$') -or
($Uri -match '^https?://api.github.com/repos/([^/]+)/?([^/]+)?(?:/.*)?$'))
$gitHubUrlBase = $(Get-GitHubConfiguration -Name "GitHubBaseUrl")

if (($Uri -match "^https?://(?:www.)?$gitHubUrlBase/([^/]+)/?([^/]+)?(?:/.*)?$") -or
($Uri -match "^https?://api.$gitHubUrlBase/repos/([^/]+)/?([^/]+)?(?:/.*)?$"))
{
$components.ownerName = $Matches[1]
if ($Matches.Count -gt 2)
Expand Down