Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 .github/PSModule.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Test:
CodeCoverage:
PercentTarget: 50
PercentTarget: 0
27 changes: 27 additions & 0 deletions src/classes/public/GitHubBillingInfo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class GitHubBillingInfo {
[int]$AllLicensableUsersCount
[int]$AssetPacks
[int]$BandwidthQuota
[int]$BandwidthUsage
[int]$BandwidthUsagePercentage
[int]$StorageQuota
[int]$StorageUsage
[int]$StorageUsagePercentage
[int]$TotalAvailableLicenses
[int]$TotalLicenses

GitHubBillingInfo() {}

GitHubBillingInfo([PSCustomObject] $Object) {
$this.AllLicensableUsersCount = $Object.allLicensableUsersCount
$this.AssetPacks = $Object.assetPacks
$this.BandwidthQuota = $Object.bandwidthQuota
$this.BandwidthUsage = $Object.bandwidthUsage
$this.BandwidthUsagePercentage = $Object.bandwidthUsagePercentage
$this.StorageQuota = $Object.storageQuota
$this.StorageUsage = $Object.storageUsage
$this.StorageUsagePercentage = $Object.storageUsagePercentage
$this.TotalAvailableLicenses = $Object.totalAvailableLicenses
$this.TotalLicenses = $Object.totalLicenses
}
}
56 changes: 56 additions & 0 deletions src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class GitHubEnterprise : GitHubOwner {
# The description of the enterprise.
# Example: A great enterprise
[string] $Description

# The description of the enterprise, as HTML.
# Example: <div>A great enterprise</div>
[string] $DescriptionHTML

# The billing information for the organization.
[GitHubBillingInfo] $BillingInfo

# The billing email address for the organization.
# Example: org@example.com
[string] $BillingEmail

# The readme of the enterprise.
# Example: This is the readme for the enterprise
[string] $Readme

# The readme of the enterprise, as HTML.
# Example: <p>This is the readme for the enterprise</p>
[string] $ReadmeHTML

GitHubEnterprise() {}

GitHubEnterprise([PSCustomObject] $Object) {
# From GitHubNode
$this.ID = $Object.databaseId
$this.NodeID = $Object.id

# From GitHubOwner
$this.Name = $Object.slug
$this.DisplayName = $Object.name
$this.AvatarUrl = $Object.avatarUrl
$this.Url = $Object.url
$this.Type = $Object.type ?? 'Enterprise'
$this.Company = $Object.company
$this.Blog = $Object.websiteUrl
$this.Location = $Object.location
$this.CreatedAt = $Object.createdAt
$this.UpdatedAt = $Object.updatedAt

# From GitHubEnterprise
$this.Description = $Object.description
$this.DescriptionHTML = $Object.descriptionHTML
$this.BillingEmail = $Object.billingEmail
$this.BillingInfo = [GitHubBillingInfo]::new($Object.billingInfo)
$this.Readme = $Object.readme
$this.ReadmeHTML = $Object.readmeHTML
}

[string] ToString() {
return $this.Name
}
}
104 changes: 104 additions & 0 deletions src/functions/public/Enterprise/Get-GitHubEnterprise.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
function Get-GitHubEnterprise {
<#
.SYNOPSIS
Retrieves details about a GitHub Enterprise instance by name (slug).

.DESCRIPTION
This function retrieves detailed information about a GitHub Enterprise instance, including its avatar, billing details, storage usage,
creation date, and other metadata based on the provided name (slug). It returns an object of type GitHubEnterprise populated with this
information.

.EXAMPLE
Get-GitHubEnterprise -Name 'my-enterprise'

Output:
```powershell
Name : My Enterprise
Slug : my-enterprise
URL : https://github.com/enterprises/my-enterprise
CreatedAt : 2022-01-01T00:00:00Z
ViewerIsAdmin : True
```

Retrieves details about the GitHub Enterprise instance named 'my-enterprise'.

.OUTPUTS
GitHubEnterprise

.NOTES
An object containing detailed information about the GitHub Enterprise instance, including billing info, URLs, and metadata.

.LINK
https://psmodule.io/GitHub/Functions/Enterprise/Get-GitHubEnterprise/
#>
[OutputType([GitHubEnterprise])]
[CmdletBinding()]
param(
# The name (slug) of the GitHub Enterprise instance to retrieve.
[Parameter(Mandatory)]
[Alias('Slug')]
[string] $Name,

# The context to run the command in. Used to get the details for the API call.
# Can be either a string or a GitHubContext object.
[Parameter()]
[object] $Context
)

begin {
$stackPath = Get-PSCallStackPath
Write-Debug "[$stackPath] - Start"
$Context = Resolve-GitHubContext -Context $Context
Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT
}

process {
$enterpriseQuery = @{
query = @'
query($Slug: String!) {
enterprise(slug: $Slug) {
avatarUrl
billingEmail
billingInfo {
allLicensableUsersCount
assetPacks
bandwidthQuota
bandwidthUsage
bandwidthUsagePercentage
storageQuota
storageUsage
storageUsagePercentage
totalAvailableLicenses
totalLicenses
}
createdAt
databaseId
description
descriptionHTML
id
location
name
readme
readmeHTML
resourcePath
slug
updatedAt
url
viewerIsAdmin
websiteUrl
}
}
'@
Variables = @{
Slug = $Name
}
Context = $Context
}
$enterpriseResult = Invoke-GitHubGraphQLQuery @enterpriseQuery
[GitHubEnterprise]::new($enterpriseResult.enterprise)
}

end {
Write-Debug "[$stackPath] - End"
}
}
62 changes: 31 additions & 31 deletions tests/Data/AuthCases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,36 @@
Organization = 'psmodule-test-org'
}
}
)
@{
AuthType = 'App'
Type = 'a GitHub App from an Enterprise'
Case = 'PEM + IAT'
TokenType = 'APP_ENT'
Target = 'organization account'
Owner = 'psmodule-test-org3'
OwnerType = 'organization'
ConnectParams = @{
ClientID = $env:TEST_APP_ENT_CLIENT_ID
PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY
}
ConnectAppParams = @{
Organization = 'psmodule-test-org3'
}
}
@{
AuthType = 'App'
Type = 'a GitHub App from an Enterprise'
Case = 'PEM + IAT'
TokenType = 'APP_ENT'
Target = 'enterprise account'
Owner = 'msx'
OwnerType = 'enterprise'
ConnectParams = @{
ClientID = $env:TEST_APP_ENT_CLIENT_ID
PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY
@{
AuthType = 'App'
Type = 'a GitHub App from an Enterprise'
Case = 'PEM + IAT'
TokenType = 'APP_ENT'
Target = 'organization account'
Owner = 'psmodule-test-org3'
OwnerType = 'organization'
ConnectParams = @{
ClientID = $env:TEST_APP_ENT_CLIENT_ID
PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY
}
ConnectAppParams = @{
Organization = 'psmodule-test-org3'
}
}
ConnectAppParams = @{
Enterprise = 'msx'
@{
AuthType = 'App'
Type = 'a GitHub App from an Enterprise'
Case = 'PEM + IAT'
TokenType = 'APP_ENT'
Target = 'enterprise account'
Owner = 'msx'
OwnerType = 'enterprise'
ConnectParams = @{
ClientID = $env:TEST_APP_ENT_CLIENT_ID
PrivateKey = $env:TEST_APP_ENT_PRIVATE_KEY
}
ConnectAppParams = @{
Enterprise = 'msx'
}
}
}
)
86 changes: 86 additions & 0 deletions tests/Enterprise.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#Requires -Modules @{ ModuleName = 'Pester'; RequiredVersion = '5.7.1' }

[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseDeclaredVarsMoreThanAssignments', '',
Justification = 'Pester grouping syntax: known issue.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingConvertToSecureStringWithPlainText', '',
Justification = 'Used to create a secure string for testing.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '',
Justification = 'Log outputs to GitHub Actions logs.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidLongLines', '',
Justification = 'Long test descriptions and skip switches'
)]
[CmdletBinding()]
param()

BeforeAll {
# DEFAULTS ACCROSS ALL TESTS
}

Describe 'Template' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"

Context 'As <Type> using <Case> on <Target>' -ForEach $authCases {
BeforeAll {
$context = Connect-GitHubAccount @connectParams -PassThru -Silent
LogGroup 'Context' {
Write-Host ($context | Format-List | Out-String)
}
if ($AuthType -eq 'APP') {
It 'Connect-GitHubApp - Connects as a GitHub App to <Owner>' {
$context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent
LogGroup 'Context - Installation' {
Write-Host ($context | Format-List | Out-String)
}
}
}
}
AfterAll {
Get-GitHubContext -ListAvailable | Disconnect-GitHubAccount -Silent
Write-Host ('-' * 60)
}

It 'Get-GitHubEnterprise - Can get info about an enterprise' -Skip:($OwnerType -notlike 'enterprise') {
$enterprise = Get-GitHubEnterprise -Name $Owner
LogGroup 'Enterprise' {
Write-Host ($enterprise | Select-Object * | Out-String)
}
$enterprise | Should -Not -BeNullOrEmpty
$enterprise | Should -BeOfType 'GitHubEnterprise'
$enterprise.Name | Should -Be 'msx'
$enterprise.DisplayName | Should -Be 'MSX'
$enterprise.ID | Should -Be 15567
$enterprise.NodeID | Should -Be 'E_kgDNPM8'
$enterprise.AvatarUrl | Should -Be 'https://avatars.githubusercontent.com/b/15567?v=4'
$enterprise.BillingEmail | Should -Be 'marstor@hotmail.com'
$enterprise.Url | Should -Be 'https://github.com/enterprises/msx'
$enterprise.Type | Should -Be 'Enterprise'
$enterprise.BillingInfo | Should -BeOfType 'GitHubBillingInfo'
$enterprise.BillingInfo.AllLicensableUsersCount | Should -Be 1
$enterprise.BillingInfo.AssetPacks | Should -Be 0
$enterprise.BillingInfo.BandwidthQuota | Should -Be 5
$enterprise.BillingInfo.BandwidthUsage | Should -Be 0
$enterprise.BillingInfo.BandwidthUsagePercentage | Should -Be 0
$enterprise.BillingInfo.StorageQuota | Should -Be 5
$enterprise.BillingInfo.StorageUsage | Should -Be 0
$enterprise.BillingInfo.StorageUsagePercentage | Should -Be 0
$enterprise.BillingInfo.TotalAvailableLicenses | Should -Be 0
$enterprise.BillingInfo.TotalLicenses | Should -Be 1
$enterprise.Readme | Should -Be 'This is a test'
$enterprise.ReadmeHTML | Should -Be '<p>This is a test</p>'
$enterprise.CreatedAt | Should -BeOfType 'DateTime'
$enterprise.CreatedAt | Should -Be (Get-Date '18.09.2022 19:53:09')
$enterprise.UpdatedAt | Should -BeOfType 'DateTime'
$enterprise.Description | Should -Be 'This is the description'
$enterprise.DescriptionHTML | Should -Be '<div>This is the description</div>'
$enterprise.Location | Should -Be 'Oslo, Norway'
$enterprise.Blog | Should -Be 'https://msx.no'
}
}
}