Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
16 changes: 16 additions & 0 deletions GitHubConfiguration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ function Set-GitHubConfiguration

The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub

.PARAMETER ApiHostName
The hostname of the GitHub instance to communicate with. Defaults to 'github.com'. Provide a
different hostname when using a GitHub Enterprise server. Do not include the HTTP/S prefix,
and do not include 'api'. For example, use "github.contoso.com".

.PARAMETER ApplicationInsightsKey
Change the Application Insights instance that telemetry will be reported to (if telemetry
hasn't been disabled via DisableTelemetry).
Expand Down Expand Up @@ -158,10 +163,19 @@ function Set-GitHubConfiguration

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

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

Sets all requests to connect to a GitHub Enterprise server running at
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.")]
param(
[ValidatePattern('^(?!https?:)(?!api\.)(?!www\.).*')]
[string] $ApiHostName,

[string] $ApplicationInsightsKey,

[string] $AssemblyPath,
Expand Down Expand Up @@ -257,6 +271,7 @@ function Get-GitHubConfiguration
param(
[Parameter(Mandatory)]
[ValidateSet(
'ApiHostName',
'ApplicationInsightsKey',
'AssemblyPath',
'DefaultNoStatus',
Expand Down Expand Up @@ -589,6 +604,7 @@ function Import-GitHubConfiguration
}

$config = [PSCustomObject]@{
'apiHostName' = 'github.com'
'applicationInsightsKey' = '66d83c52-3070-489b-886b-09860e05e78a'
'assemblyPath' = [String]::Empty
'disableLogging' = ([String]::IsNullOrEmpty($logPath))
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"
$hostName = $(Get-GitHubConfiguration -Name "ApiHostName")

$url = "https://api.$hostname/$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/([^/]+)/?([^/]+)?(?:/.*)?$'))
$hostName = $(Get-GitHubConfiguration -Name "ApiHostName")

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