diff --git a/.github/PSModule.yml b/.github/PSModule.yml index c1eb7bd1a..6d578178e 100644 --- a/.github/PSModule.yml +++ b/.github/PSModule.yml @@ -1,3 +1,3 @@ Test: CodeCoverage: - PercentTarget: 0 + PercentTarget: 50 diff --git a/src/classes/public/App/GitHubAppInstallation.ps1 b/src/classes/public/App/GitHubAppInstallation.ps1 index 5335e4830..96fd2831c 100644 --- a/src/classes/public/App/GitHubAppInstallation.ps1 +++ b/src/classes/public/App/GitHubAppInstallation.ps1 @@ -65,7 +65,7 @@ $this.Url = $Object.html_url } - GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [string] $HostName) { + GitHubAppInstallation([PSCustomObject] $Object, [string] $Target, [string] $Type, [GitHubContext] $Context) { $this.ID = $Object.id $this.App = [GitHubApp]::new( [PSCustomObject]@{ @@ -77,7 +77,7 @@ $this.Target = [GitHubOwner]@{ Name = $Target Type = $Type - Url = "https://$HostName/$Target" + Url = "https://$($Context.HostName)/$Target" } $this.Type = $Type $this.RepositorySelection = $Object.repository_selection @@ -88,6 +88,6 @@ $this.UpdatedAt = $Object.updated_at $this.SuspendedAt = $Object.suspended_at $this.SuspendedBy = [GitHubUser]::new($Object.suspended_by) - $this.Url = "https://$HostName/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)" + $this.Url = "https://$($Context.HostName)/$($Type.ToLower())s/$Target/settings/installations/$($Object.id)" } } diff --git a/src/classes/public/Artifacts/GitHubArtifact.ps1 b/src/classes/public/Artifacts/GitHubArtifact.ps1 index 3e654860e..988c09931 100644 --- a/src/classes/public/Artifacts/GitHubArtifact.ps1 +++ b/src/classes/public/Artifacts/GitHubArtifact.ps1 @@ -37,14 +37,14 @@ GitHubArtifact() {} - GitHubArtifact([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [string]$HostName) { + GitHubArtifact([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [GitHubContext]$Context) { $this.ID = $Object.id $this.NodeID = $Object.node_id $this.Name = $Object.name $this.Owner = $Owner $this.Repository = $Repository $this.Size = $Object.size_in_bytes - $this.Url = "https://$($HostName)/$Owner/$Repository/actions/runs/$($Object.workflow_run.id)/artifacts/$($Object.id)" + $this.Url = "https://$($Context.HostName)/$Owner/$Repository/actions/runs/$($Object.workflow_run.id)/artifacts/$($Object.id)" $this.ArchiveDownloadUrl = $Object.archive_download_url $this.Expired = $Object.expired $this.Digest = $Object.digest diff --git a/src/classes/public/Environment/GitHubEnvironment.ps1 b/src/classes/public/Environment/GitHubEnvironment.ps1 index 4da7639c7..799addd97 100644 --- a/src/classes/public/Environment/GitHubEnvironment.ps1 +++ b/src/classes/public/Environment/GitHubEnvironment.ps1 @@ -28,12 +28,13 @@ GitHubEnvironment() {} - GitHubEnvironment([PSCustomObject]$Object, [string]$Owner, [string]$Repository) { + GitHubEnvironment([PSCustomObject]$Object, [string]$Owner, [string]$Repository, [GitHubContext]$Context) { $this.ID = $Object.id $this.NodeID = $Object.node_id $this.Name = $Object.name $this.Owner = $Owner $this.Repository = $Repository + $this.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($Object.id)/edit" $this.CreatedAt = $Object.created_at $this.UpdatedAt = $Object.updated_at $this.AdminsCanBypass = $Object.can_admins_bypass diff --git a/src/classes/public/Owner/GitHubOwner.ps1 b/src/classes/public/Owner/GitHubOwner.ps1 index cc932ce1a..81efa24b0 100644 --- a/src/classes/public/Owner/GitHubOwner.ps1 +++ b/src/classes/public/Owner/GitHubOwner.ps1 @@ -19,41 +19,17 @@ # Example: User [string] $Type - # The company the account is affiliated with. - # Example: GitHub - [string] $Company - - # The blog URL of the account. - # Example: https://github.com/blog - [string] $Blog - # The location of the account. # Example: San Francisco [string] $Location - # The email of the account. - # Example: octocat@github.com - [string] $Email - - # The Twitter username. - # Example: monalisa - [string] $TwitterUsername - - # The number of public repositories. - # Example: 2 - [System.Nullable[uint]] $PublicRepos + # The description of the organization. + # Example: A great organization + [string] $Description - # The number of public gists. - # Example: 1 - [System.Nullable[uint]] $PublicGists - - # The number of followers. - # Example: 20 - [System.Nullable[uint]] $Followers - - # The number of accounts this account is following. - # Example: 0 - [System.Nullable[uint]] $Following + # The website URL of the account. + # Example: https://github.com/blog + [string] $Website # The creation date of the account. # Example: 2008-01-14T04:33:35Z @@ -63,10 +39,6 @@ # Example: 2008-01-14T04:33:35Z [System.Nullable[datetime]] $UpdatedAt - # The user's plan. - # Includes: Name, Collaborators, PrivateRepos, Space - [GitHubPlan] $Plan - GitHubOwner() {} GitHubOwner([PSCustomObject]$Object) { @@ -78,20 +50,13 @@ $this.Name = $Object.slug ?? $Object.login $this.DisplayName = $Object.name $this.AvatarUrl = $Object.avatar_url - $this.Url = $Object.html_url + $this.Url = $Object.html_url ?? $Object.url $this.Type = $Object.type - $this.Company = $Object.company - $this.Blog = $Object.website_url ?? $Object.blog $this.Location = $Object.location - $this.Email = $Object.email - $this.TwitterUsername = $Object.twitter_username - $this.PublicRepos = $Object.public_repos - $this.PublicGists = $Object.public_gists - $this.Followers = $Object.followers - $this.Following = $Object.following + $this.Description = $Object.description ?? $Object.bio + $this.Website = $Object.websiteUrl ?? $Object.blog $this.CreatedAt = $Object.created_at $this.UpdatedAt = $Object.updated_at - $this.Plan = [GitHubPlan]::New($Object.plan) } [string] ToString() { diff --git a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 index 790c19625..66fea40c4 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubEnterprise.ps1 @@ -1,19 +1,4 @@ class GitHubEnterprise : GitHubOwner { - # The description of the enterprise. - # Example: A great enterprise - [string] $Description - - # The description of the enterprise, as HTML. - # Example:
A great enterprise
- [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 @@ -22,6 +7,22 @@ # Example:

This is the readme for the enterprise

[string] $ReadmeHTML + static [hashtable] $PropertyToGraphQLMap = @{ + ID = 'databaseId' + NodeID = 'id' + Name = 'slug' + DisplayName = 'name' + AvatarUrl = 'avatarUrl' + Url = 'url' + Website = 'websiteUrl' + Location = 'location' + CreatedAt = 'createdAt' + UpdatedAt = 'updatedAt' + Description = 'description' + Readme = 'readme' + ReadmeHTML = 'readmeHTML' + } + GitHubEnterprise() {} GitHubEnterprise([PSCustomObject] $Object) { @@ -35,17 +36,13 @@ $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.Description = $Object.description + $this.Website = $Object.websiteUrl $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 } diff --git a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 index 5869a6367..48528dba2 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubOrganization.ps1 @@ -1,7 +1,31 @@ class GitHubOrganization : GitHubOwner { - # The description of the organization. - # Example: A great organization - [string] $Description + # The email of the account. + # Example: octocat@github.com + [string] $Email + + # The Twitter username. + # Example: monalisa + [string] $TwitterUsername + + # The user's plan. + # Includes: Name, Collaborators, PrivateRepos, Space + [GitHubPlan] $Plan + + # The number of public repositories. + # Example: 2 + [System.Nullable[uint]] $PublicRepos + + # The number of public gists. + # Example: 1 + [System.Nullable[uint]] $PublicGists + + # The number of followers. + # Example: 20 + [System.Nullable[uint]] $Followers + + # The number of accounts this account is following. + # Example: 0 + [System.Nullable[uint]] $Following # The number of private gists. # Example: 81 @@ -49,7 +73,7 @@ # Whether two-factor authentication is required for members. # Example: $true - [System.Nullable[bool]] $TwoFactorRequirementEnabled + [System.Nullable[bool]] $RequiresTwoFactorAuthentication # The type of repositories members can create. # Example: all @@ -134,54 +158,74 @@ # The date and time when the organization was archived, if applicable. [System.Nullable[datetime]] $ArchivedAt + static [hashtable] $PropertyToGraphQLMap = @{ + ArchivedAt = 'archivedAt' + AvatarUrl = 'avatarUrl' + CreatedAt = 'createdAt' + Description = 'description' + DisplayName = 'name' + Email = 'email' + ID = 'databaseId' + Location = 'location' + Name = 'login' + NodeID = 'id' + IsVerified = 'isVerified' + # MembersCanForkPrivateRepositories = 'membersCanForkPrivateRepositories' + # RequiresTwoFactorAuthentication = 'requiresTwoFactorAuthentication' + TwitterUsername = 'twitterUsername' + UpdatedAt = 'updatedAt' + Url = 'url' + # RequireWebCommitSignoff = 'webCommitSignoffRequired' + Website = 'websiteUrl' + } + GitHubOrganization() {} - GitHubOrganization([PSCustomObject] $Object, [string] $HostName) { + GitHubOrganization([PSCustomObject] $Object, [GitHubContext] $Context) { # From GitHubNode - $this.ID = $Object.id - $this.NodeID = $Object.node_id + $this.ID = $Object.databaseId ?? $Object.id + $this.NodeID = $Object.node_id ?? $Object.id # From GitHubOwner $this.Name = $Object.login $this.DisplayName = $Object.name - $this.AvatarUrl = $Object.avatar_url - $this.Url = $Object.html_url ?? "https://$($HostName)/$($Object.login)" - $this.Type = $Object.type - $this.Company = $Object.company - $this.Blog = $Object.blog + $this.AvatarUrl = $Object.avatar_url ?? $Object.avatarUrl + $this.Url = $Object.html_url ?? $Object.url ?? "https://$($Context.HostName)/$($Object.login)" + $this.Type = $Object.type ?? 'Organization' $this.Location = $Object.location + $this.Description = $Object.description + $this.Website = $Object.website ?? $Object.blog + $this.CreatedAt = $Object.created_at ?? $Object.createdAt + $this.UpdatedAt = $Object.updated_at ?? $Object.updatedAt + + # From GitHubOrganization $this.Email = $Object.email - $this.TwitterUsername = $Object.twitter_username + $this.TwitterUsername = $Object.twitter_username ?? $Object.twitterUsername + $this.Plan = [GitHubPlan]::New($Object.plan) $this.PublicRepos = $Object.public_repos $this.PublicGists = $Object.public_gists $this.Followers = $Object.followers $this.Following = $Object.following - $this.CreatedAt = $Object.created_at - $this.UpdatedAt = $Object.updated_at - $this.Plan = [GitHubPlan]::New($Object.plan) - - # From GitHubOrganization - $this.Description = $Object.description $this.PrivateGists = $Object.total_private_gists $this.TotalPrivateRepos = $Object.total_private_repos $this.OwnedPrivateRepos = $Object.owned_private_repos $this.DiskUsage = $Object.disk_usage $this.Collaborators = $Object.collaborators - $this.IsVerified = $Object.is_verified + $this.IsVerified = $Object.is_verified ?? $Object.isVerified $this.HasOrganizationProjects = $Object.has_organization_projects $this.HasRepositoryProjects = $Object.has_repository_projects $this.BillingEmail = $Object.billing_email $this.DefaultRepositoryPermission = $Object.default_repository_permission $this.MembersCanCreateRepositories = $Object.members_can_create_repositories - $this.TwoFactorRequirementEnabled = $Object.two_factor_requirement_enabled + $this.RequiresTwoFactorAuthentication = $Object.two_factor_requirement_enabled ?? $Object.requiresTwoFactorAuthentication $this.MembersAllowedRepositoryCreationType = $Object.members_allowed_repository_creation_type $this.MembersCanCreatePublicRepositories = $Object.members_can_create_public_repositories $this.MembersCanCreatePrivateRepositories = $Object.members_can_create_private_repositories $this.MembersCanCreateInternalRepositories = $Object.members_can_create_internal_repositories $this.MembersCanInviteCollaborators = $Object.members_can_invite_collaborators $this.MembersCanCreatePages = $Object.members_can_create_pages - $this.MembersCanForkPrivateRepositories = $Object.members_can_fork_private_repositories - $this.RequireWebCommitSignoff = $Object.web_commit_signoff_required + $this.MembersCanForkPrivateRepositories = $Object.members_can_fork_private_repositories ?? $Object.membersCanForkPrivateRepositories + $this.RequireWebCommitSignoff = $Object.web_commit_signoff_required ?? $Object.requiresTwoFactorAuthentication $this.DeployKeysEnabledForRepositories = $Object.deploy_keys_enabled_for_repositories $this.MembersCanCreatePublicPages = $Object.members_can_create_public_pages $this.MembersCanCreatePrivatePages = $Object.members_can_create_private_pages @@ -194,7 +238,7 @@ $this.SecretScanningPushProtectionCustomLinkEnabled = $Object.secret_scanning_push_protection_custom_link_enabled $this.SecretScanningPushProtectionCustomLink = $Object.secret_scanning_push_protection_custom_link $this.SecretScanningValidityChecksEnabled = $Object.secret_scanning_validity_checks_enabled - $this.ArchivedAt = $Object.archived_at + $this.ArchivedAt = $Object.archived_at ?? $Object.archivedAt } [string] ToString() { diff --git a/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 b/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 index b6b1d4664..a9e4e4abe 100644 --- a/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 +++ b/src/classes/public/Owner/GitHubOwner/GitHubUser.ps1 @@ -1,15 +1,43 @@ class GitHubUser : GitHubOwner { + # The email of the account. + # Example: octocat@github.com + [string] $Email + # Whether the user is hireable. [System.Nullable[bool]] $Hireable - # The user's biography. - # Example: There once was... - [string] $Bio + # The company the account is affiliated with. + # Example: GitHub + [string] $Company + + # The Twitter username. + # Example: monalisa + [string] $TwitterUsername + + # The number of public repositories. + # Example: 2 + [System.Nullable[uint]] $PublicRepos + + # The number of public gists. + # Example: 1 + [System.Nullable[uint]] $PublicGists + + # The number of followers. + # Example: 20 + [System.Nullable[uint]] $Followers + + # The number of accounts this account is following. + # Example: 0 + [System.Nullable[uint]] $Following # The notification email address of the user. # Example: octocat@github.com [string] $NotificationEmail + # The user's plan. + # Includes: Name, Collaborators, PrivateRepos, Space + [GitHubPlan] $Plan + GitHubUser() {} GitHubUser([PSCustomObject]$Object) { @@ -23,23 +51,23 @@ $this.AvatarUrl = $Object.avatar_url $this.Url = $Object.html_url $this.Type = $Object.type - $this.Company = $Object.company - $this.Blog = $Object.blog $this.Location = $Object.location + $this.Description = $Object.bio + $this.Website = $Object.blog + $this.CreatedAt = $Object.created_at + $this.UpdatedAt = $Object.updated_at + + # From GitHubUser $this.Email = $Object.email + $this.Hireable = $Object.hireable + $this.Company = $Object.company $this.TwitterUsername = $Object.twitter_username $this.PublicRepos = $Object.public_repos $this.PublicGists = $Object.public_gists $this.Followers = $Object.followers $this.Following = $Object.following - $this.CreatedAt = $Object.created_at - $this.UpdatedAt = $Object.updated_at - $this.Plan = [GitHubPlan]::New($Object.plan) - - # From GitHubUser - $this.Hireable = $Object.hireable - $this.Bio = $Object.bio $this.NotificationEmail = $Object.notification_email + $this.Plan = [GitHubPlan]::New($Object.plan) } [string] ToString() { diff --git a/src/formats/GitHubOwner.Format.ps1xml b/src/formats/GitHubOwner.Format.ps1xml index 34d050cd5..c1d8dcb3f 100644 --- a/src/formats/GitHubOwner.Format.ps1xml +++ b/src/formats/GitHubOwner.Format.ps1xml @@ -7,9 +7,13 @@ GitHubOwner GitHubUser GitHubOrganization + GitHubEnterprise + + + @@ -20,15 +24,15 @@ - - - - + + + DisplayName + if ($Host.UI.SupportsVirtualTerminal -and @@ -46,10 +50,7 @@ Type - Company - - - Plan + CreatedAt @@ -65,6 +66,9 @@ + + DisplayName + Name @@ -74,9 +78,6 @@ NodeID - - DisplayName - AvatarUrl @@ -86,9 +87,6 @@ Type - - Company - Location @@ -96,10 +94,10 @@ Email - TwitterUsername + Description - Blog + Website CreatedAt @@ -107,9 +105,6 @@ UpdatedAt - - Plan - diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 index 4d5017e44..5c03bfcfb 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallableOrganization.ps1 @@ -52,7 +52,7 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { foreach ($organization in $_.Response) { - [GitHubOrganization]::new($organization, $Context.HostName) + [GitHubOrganization]::new($organization, $Context) } } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 index f4dfcb18e..a4a218574 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppInstallationForAuthenticatedApp.ps1 @@ -47,8 +47,8 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { - [GitHubAppInstallation]::new($_) + foreach ($installation in $_.Response) { + [GitHubAppInstallation]::new($installation) } } } diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 index 133816e4f..9ac33c835 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubAppJSONWebToken.ps1 @@ -37,7 +37,6 @@ )] [CmdletBinding(DefaultParameterSetName = 'PrivateKey')] - [Alias('Get-GitHubAppJWT')] [OutputType([GitHubJsonWebToken])] param( # The client ID of the GitHub App. diff --git a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 index 4609f1fe1..ea19a3c4d 100644 --- a/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 +++ b/src/functions/private/Apps/GitHub Apps/Get-GitHubEnterpriseOrganizationAppInstallation.ps1 @@ -62,7 +62,7 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { foreach ($installation in $_.Response) { - [GitHubAppInstallation]::new($installation, $Organization, 'Organization', $context.HostName) + [GitHubAppInstallation]::new($installation, $Organization, 'Organization', $Context) } } } diff --git a/src/functions/private/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 b/src/functions/private/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 index 2291149ad..34369ff47 100644 --- a/src/functions/private/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 +++ b/src/functions/private/Apps/GitHub Apps/New-GitHubAppInstallationAccessToken.ps1 @@ -48,18 +48,15 @@ 'PSUseShouldProcessForStateChangingFunctions', '', Justification = 'No state is changed.' )] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', - Justification = 'The tokens are received as clear text. Mitigating exposure by removing variables and performing garbage collection.')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'The tokens are received as clear text. Mitigating exposure by removing variables and performing garbage collection.' + )] [CmdletBinding()] param( # The unique identifier of the installation. # Example: '12345678' - [Parameter( - Mandatory, - ValueFromPipeline, - ValueFromPipelineByPropertyName - )] - [Alias('installation_id', 'InstallationID')] + [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] [int] $ID, # The context to run the command in. Used to get the details for the API call. diff --git a/src/functions/private/Artifacts/Get-GitHubArtifactById.ps1 b/src/functions/private/Artifacts/Get-GitHubArtifactById.ps1 index 1d634fbbb..782667043 100644 --- a/src/functions/private/Artifacts/Get-GitHubArtifactById.ps1 +++ b/src/functions/private/Artifacts/Get-GitHubArtifactById.ps1 @@ -68,7 +68,7 @@ function Get-GitHubArtifactById { } Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubArtifact]::new($_.Response, $Owner, $Repository, $Context.HostName) + [GitHubArtifact]::new($_.Response, $Owner, $Repository, $Context) } } diff --git a/src/functions/private/Artifacts/Get-GitHubArtifactFromRepository.ps1 b/src/functions/private/Artifacts/Get-GitHubArtifactFromRepository.ps1 index d7f86c044..08087d229 100644 --- a/src/functions/private/Artifacts/Get-GitHubArtifactFromRepository.ps1 +++ b/src/functions/private/Artifacts/Get-GitHubArtifactFromRepository.ps1 @@ -88,7 +88,7 @@ function Get-GitHubArtifactFromRepository { } $artifacts | ForEach-Object { - [GitHubArtifact]::new($_, $Owner, $Repository, $Context.HostName) + [GitHubArtifact]::new($_, $Owner, $Repository, $Context) } } diff --git a/src/functions/private/Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 b/src/functions/private/Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 index a7b9b863b..7a54c1709 100644 --- a/src/functions/private/Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 +++ b/src/functions/private/Artifacts/Get-GitHubArtifactFromWorkflowRun.ps1 @@ -99,7 +99,7 @@ function Get-GitHubArtifactFromWorkflowRun { } $artifacts | ForEach-Object { - [GitHubArtifact]::new($_, $Owner, $Repository, $Context.HostName) + [GitHubArtifact]::new($_, $Owner, $Repository, $Context) } } diff --git a/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 index 4c93f5ddc..9b6f810d8 100644 --- a/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 +++ b/src/functions/private/Auth/Context/Remove-GitHubContext.ps1 @@ -23,7 +23,6 @@ param( # The name of the context. [Parameter(Mandatory)] - [Alias('Name')] [string] $Context ) diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 new file mode 100644 index 000000000..81d33aa5d --- /dev/null +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseByName.ps1 @@ -0,0 +1,74 @@ +function Get-GitHubEnterpriseByName { + <# + .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-GitHubEnterpriseByName -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. + #> + [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(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $graphQLFields = ([GitHubEnterprise]::PropertyToGraphQLMap).Values + + $enterpriseQuery = @{ + query = @" +query(`$Slug: String!) { + enterprise(slug: `$Slug) { + $graphQLFields + } +} +"@ + Variables = @{ + Slug = $Name + } + Context = $Context + } + $enterpriseResult = Invoke-GitHubGraphQLQuery @enterpriseQuery + [GitHubEnterprise]::new($enterpriseResult.enterprise) + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 new file mode 100644 index 000000000..cd2f890e4 --- /dev/null +++ b/src/functions/private/Enterprise/Get-GitHubEnterpriseList.ps1 @@ -0,0 +1,100 @@ +function Get-GitHubEnterpriseList { + <# + .SYNOPSIS + Retrieves a list of all GitHub Enterprise instances. + + .DESCRIPTION + This function retrieves detailed information about all GitHub Enterprise instances, including their avatars, billing details, storage usage, + creation dates, and other metadata. It returns an array of objects of type GitHubEnterprise populated with this information. + + .EXAMPLE + Get-GitHubEnterpriseList + + Output: + ```powershell + Name : My Enterprise + Slug : my-enterprise + URL : https://github.com/enterprises/my-enterprise + CreatedAt : 2022-01-01T00:00:00Z + + Name : Another Enterprise + Slug : another-enterprise + URL : https://github.com/enterprises/another-enterprise + CreatedAt : 2021-12-01T00:00:00Z + ``` + + Retrieves details about the GitHub Enterprise instance. + + .OUTPUTS + GitHubEnterprise[] + + .NOTES + An array of objects containing detailed information about the GitHub Enterprise instances, including billing info, URLs, and metadata. + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'hasNextPage', Scope = 'Function', + Justification = 'Unknown issue with var scoping in blocks.' + )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'after', Scope = 'Function', + Justification = 'Unknown issue with var scoping in blocks.' + )] + [OutputType([GitHubEnterprise[]])] + [CmdletBinding()] + param( + # 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(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $hasNextPage = $false + $after = $null + $perPageSetting = Resolve-GitHubContextSetting -Name 'PerPage' -Value $PerPage -Context $Context + + $graphQLFields = ([GitHubEnterprise]::PropertyToGraphQLMap).Values + + do { + $enterpriseQuery = @{ + query = @" +query(`$perPage: Int!, `$after: String) { + viewer { + enterprises(first: `$perPage, after: `$after) { + nodes { + $graphQLFields + } + pageInfo { + endCursor + hasNextPage + } + } + } +} +"@ + Variables = @{ + perPage = $perPageSetting + after = $after + } + Context = $Context + } + Invoke-GitHubGraphQLQuery @enterpriseQuery | ForEach-Object { + foreach ($enterprise in $_.viewer.enterprises.nodes) { + [GitHubEnterprise]::new($enterprise) + } + $hasNextPage = $_.viewer.enterprises.pageInfo.hasNextPage + $after = $_.viewer.enterprises.pageInfo.endCursor + } + } while ($hasNextPage) + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 b/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 index d4286cb88..0b9df7f01 100644 --- a/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 +++ b/src/functions/private/Environments/Get-GitHubEnvironmentByName.ps1 @@ -50,7 +50,6 @@ filter Get-GitHubEnvironmentByName { Mandatory, ValueFromPipelineByPropertyName )] - [Alias('Organization', 'User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. @@ -88,9 +87,7 @@ filter Get-GitHubEnvironmentByName { } try { Invoke-GitHubAPI @inputObject | ForEach-Object { - $environment = [GitHubEnvironment]::new($_.Response, $Owner, $Repository) - $environment.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($environment.ID)/edit" - $environment + [GitHubEnvironment]::new($_.Response, $Owner, $Repository, $Context) } } catch { return diff --git a/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 b/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 index 85d191c16..c4cd691bb 100644 --- a/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 +++ b/src/functions/private/Environments/Get-GitHubEnvironmentList.ps1 @@ -82,10 +82,8 @@ filter Get-GitHubEnvironmentList { } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response.environments | ForEach-Object { - $environment = [GitHubEnvironment]::new($_, $Owner, $Repository) - $environment.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($environment.ID)/edit" - $environment + foreach ($environment in $_.Response.environments) { + [GitHubEnvironment]::new($environment, $Owner, $Repository, $Context) } } } diff --git a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 index 98ffe0674..60f8aee2f 100644 --- a/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubAllOrganization.ps1 @@ -58,7 +58,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context.HostName) } + foreach ($organization in $_.Response) { + [GitHubOrganization]::new($organization, $Context) + } } } end { diff --git a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 b/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 deleted file mode 100644 index d11b5aebe..000000000 --- a/src/functions/private/Organization/Get-GitHubMyOrganization.ps1 +++ /dev/null @@ -1,63 +0,0 @@ -filter Get-GitHubMyOrganization { - <# - .SYNOPSIS - List organizations for the authenticated user - - .DESCRIPTION - List organizations for the authenticated user. - - **OAuth scope requirements** - - This only lists organizations that your authorization allows you to operate on - in some way (e.g., you can list teams with `read:org` scope, you can publicize your - organization membership with `user` scope, etc.). Therefore, this API requires at - least `user` or `read:org` scope. OAuth requests with insufficient scope receive a - `403 Forbidden` response. - - .EXAMPLE - Get-GitHubMyOrganization - - List organizations for the authenticated user. - - .OUTPUTS - GitHubOrganization - - .NOTES - [List organizations for the authenticated user](https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user) - #> - [OutputType([GitHubOrganization])] - [CmdletBinding()] - param( - # The number of results per page (max 100). - [Parameter()] - [System.Nullable[int]] $PerPage, - - # 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(Mandatory)] - [object] $Context - ) - - begin { - $stackPath = Get-PSCallStackPath - Write-Debug "[$stackPath] - Start" - Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT - } - - process { - $inputObject = @{ - Method = 'GET' - APIEndpoint = '/user/orgs' - PerPage = $PerPage - Context = $Context - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubOrganization]::new($_, $Context.HostName) } - } - } - - end { - Write-Debug "[$stackPath] - End" - } -} diff --git a/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 b/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 index 03595108f..aee398ab2 100644 --- a/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 +++ b/src/functions/private/Organization/Get-GitHubOrganizationByName.ps1 @@ -56,7 +56,7 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubOrganization]::new($_.Response, '') + [GitHubOrganization]::new($_.Response, $Context) } } end { diff --git a/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 b/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 new file mode 100644 index 000000000..a8024ee6b --- /dev/null +++ b/src/functions/private/Organization/Get-GitHubOrganizationListForAuthUser.ps1 @@ -0,0 +1,104 @@ +function Get-GitHubOrganizationListForAuthUser { + <# + .SYNOPSIS + Retrieves a list of all GitHub organizations for the authenticated user. + + .DESCRIPTION + This function retrieves detailed information about all GitHub organizations that the authenticated user belongs to, including their avatars, + creation dates, member counts, and other metadata. It returns an array of objects of type GitHubOrganization populated with this information. + + .EXAMPLE + Get-GitHubOrganizationListForAuthUser + + Output: + ```powershell + Name : MyOrganization + Login : my-org + URL : https://github.com/my-org + CreatedAt : 2022-01-01T00:00:00Z + + Name : Another Organization + Login : another-org + URL : https://github.com/another-org + CreatedAt : 2021-12-01T00:00:00Z + ``` + + Retrieves details about the GitHub organizations the authenticated user belongs to. + + .OUTPUTS + GitHubOrganization[] + + .NOTES + An array of objects containing detailed information about the GitHub organizations, including member info, URLs, and metadata. + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'hasNextPage', Scope = 'Function', + Justification = 'Unknown issue with var scoping in blocks.' + )] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseDeclaredVarsMoreThanAssignments', 'after', Scope = 'Function', + Justification = 'Unknown issue with var scoping in blocks.' + )] + [OutputType([GitHubOrganization[]])] + [CmdletBinding()] + param( + # The number of results per page (max 100). + [Parameter()] + [System.Nullable[int]] $PerPage, + + # 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(Mandatory)] + [object] $Context + ) + + begin { + $stackPath = Get-PSCallStackPath + Write-Debug "[$stackPath] - Start" + Assert-GitHubContext -Context $Context -AuthType IAT, PAT, UAT + } + + process { + $hasNextPage = $false + $after = $null + $perPageSetting = Resolve-GitHubContextSetting -Name 'PerPage' -Value $PerPage -Context $Context + + $graphQLFields = ([GitHubOrganization]::PropertyToGraphQLMap).Values + + do { + $organizationQuery = @{ + query = @" +query(`$perPage: Int!, `$after: String) { + viewer { + organizations(first: `$perPage, after: `$after) { + nodes { + $graphQLFields + } + pageInfo { + endCursor + hasNextPage + } + } + } +} +"@ + Variables = @{ + perPage = $perPageSetting + after = $after + } + Context = $Context + } + Invoke-GitHubGraphQLQuery @organizationQuery | ForEach-Object { + foreach ($organization in $_.viewer.organizations.nodes) { + [GitHubOrganization]::new($organization, $Context) + } + $hasNextPage = $_.viewer.organizations.pageInfo.hasNextPage + $after = $_.viewer.organizations.pageInfo.endCursor + } + } while ($hasNextPage) + } + + end { + Write-Debug "[$stackPath] - End" + } +} diff --git a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 index 6a8df5659..6cd3d6e9b 100644 --- a/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 +++ b/src/functions/private/Organization/Get-GitHubUserOrganization.ps1 @@ -55,8 +55,8 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - foreach ($org in $_.Response) { - [GitHubOrganization]::new($org, $Context.HostName) + foreach ($organization in $_.Response) { + [GitHubOrganization]::new($organization, $Context) } } } diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 b/src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 similarity index 94% rename from src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 rename to src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 index 0bce42cff..e614f7f10 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 +++ b/src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 @@ -24,8 +24,6 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Organization')] - [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. @@ -34,7 +32,6 @@ # The unique identifier of the rule suite result. To get this ID, you can use GET /repos/ { owner }/ { repo }/rulesets/rule-suites for repositories and GET /orgs/ { org }/rulesets/rule-suites for organizations. [Parameter(Mandatory)] - [Alias('RuleSuiteId')] [int] $ID, # The context to run the command in. Used to get the details for the API call. @@ -66,5 +63,3 @@ Write-Debug "[$stackPath] - End" } } - -#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 b/src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 similarity index 96% rename from src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 rename to src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 index d124a6b77..7843a405b 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 +++ b/src/functions/private/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 @@ -32,8 +32,6 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter(Mandatory)] - [Alias('Organization')] - [Alias('User')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. @@ -104,5 +102,3 @@ Write-Debug "[$stackPath] - End" } } - -#SkipTest:FunctionTest:Will add a test for this function in a future PR diff --git a/src/functions/private/Users/Get-GitHubAllUser.ps1 b/src/functions/private/Users/Get-GitHubAllUser.ps1 index 43d57fc63..ea8233a2e 100644 --- a/src/functions/private/Users/Get-GitHubAllUser.ps1 +++ b/src/functions/private/Users/Get-GitHubAllUser.ps1 @@ -58,13 +58,13 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { - if ($_.type -eq 'Organization') { - [GitHubOrganization]::New($_, '') - } elseif ($_.type -eq 'User') { - [GitHubUser]::New($_) + foreach ($account in $_.Response) { + if ($account.type -eq 'Organization') { + [GitHubOrganization]::New($account, $Context) + } elseif ($account.type -eq 'User') { + [GitHubUser]::New($account) } else { - [GitHubOwner]::New($_) + [GitHubOwner]::New($account) } } } diff --git a/src/functions/private/Users/Get-GitHubMyUser.ps1 b/src/functions/private/Users/Get-GitHubMyUser.ps1 index 7526a7837..6141d5043 100644 --- a/src/functions/private/Users/Get-GitHubMyUser.ps1 +++ b/src/functions/private/Users/Get-GitHubMyUser.ps1 @@ -44,7 +44,7 @@ Invoke-GitHubAPI @inputObject | ForEach-Object { if ($_.Response.type -eq 'Organization') { - [GitHubOrganization]::New($_.Response, $Context.HostName) + [GitHubOrganization]::New($_.Response, $Context) } elseif ($_.Response.type -eq 'User') { [GitHubUser]::New($_.Response) } else { diff --git a/src/functions/private/Users/Get-GitHubUserByName.ps1 b/src/functions/private/Users/Get-GitHubUserByName.ps1 index 701bca251..880b63e55 100644 --- a/src/functions/private/Users/Get-GitHubUserByName.ps1 +++ b/src/functions/private/Users/Get-GitHubUserByName.ps1 @@ -62,7 +62,7 @@ try { Invoke-GitHubAPI @inputObject | ForEach-Object { if ($_.Response.type -eq 'Organization') { - [GitHubOrganization]::New($_.Response, $Context.HostName) + [GitHubOrganization]::New($_.Response, $Context) } elseif ($_.Response.type -eq 'User') { [GitHubUser]::New($_.Response) } else { diff --git a/src/functions/public/Auth/Connect-GitHubApp.ps1 b/src/functions/public/Auth/Connect-GitHubApp.ps1 index c74caafba..1994c5082 100644 --- a/src/functions/public/Auth/Connect-GitHubApp.ps1 +++ b/src/functions/public/Auth/Connect-GitHubApp.ps1 @@ -122,7 +122,7 @@ $selectedInstallations | ForEach-Object { $installation = $_ Write-Verbose "Processing installation [$($installation.Target.Name)] [$($installation.id)]" - $token = New-GitHubAppInstallationAccessToken -Context $Context -InstallationID $installation.id + $token = New-GitHubAppInstallationAccessToken -Context $Context -ID $installation.id $contextParams = @{ AuthType = [string]'IAT' diff --git a/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 b/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 index 079a3a89b..20493743e 100644 --- a/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 +++ b/src/functions/public/Enterprise/Get-GitHubEnterprise.ps1 @@ -1,12 +1,30 @@ function Get-GitHubEnterprise { <# .SYNOPSIS - Retrieves details about a GitHub Enterprise instance by name (slug). + Retrieves GitHub Enterprise instance details for the authenticated user. .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. + Retrieves detailed information about GitHub Enterprise instances available to the authenticated user. + By default, the command lists all accessible instances, including metadata such as the enterprise name, slug, URL, and creation date. If a + specific enterprise name is provided, details about that single instance are returned. + + .EXAMPLE + Get-GitHubEnterprise + + Output: + ```powershell + Name : My Enterprise + Slug : my-enterprise + URL : https://github.com/enterprises/my-enterprise + CreatedAt : 2022-01-01T00:00:00Z + + Name : Another Enterprise + Slug : another-enterprise + URL : https://github.com/enterprises/another-enterprise + CreatedAt : 2022-01-01T00:00:00Z + ``` + + Retrieves details about all GitHub Enterprise instances for the user. .EXAMPLE Get-GitHubEnterprise -Name 'my-enterprise' @@ -17,7 +35,6 @@ 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'. @@ -32,10 +49,10 @@ https://psmodule.io/GitHub/Functions/Enterprise/Get-GitHubEnterprise/ #> [OutputType([GitHubEnterprise])] - [CmdletBinding()] + [CmdletBinding(DefaultParameterSetName = 'List enterprises for the authenticated user')] param( # The name (slug) of the GitHub Enterprise instance to retrieve. - [Parameter(Mandatory)] + [Parameter(Mandatory, ParameterSetName = 'Get enterprise by name')] [Alias('Slug')] [string] $Name, @@ -53,49 +70,16 @@ } 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 + Write-Debug "ParameterSet: $($PSCmdlet.ParameterSetName)" + switch ($PSCmdlet.ParameterSetName) { + 'Get enterprise by name' { + Get-GitHubEnterpriseByName -Name $Name -Context $Context + break + } + default { + Get-GitHubEnterpriseList -Context $Context } - Context = $Context } - $enterpriseResult = Invoke-GitHubGraphQLQuery @enterpriseQuery - [GitHubEnterprise]::new($enterpriseResult.enterprise) } end { diff --git a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 index 65c0b326c..b048f185e 100644 --- a/src/functions/public/Environments/Set-GitHubEnvironment.ps1 +++ b/src/functions/public/Environments/Set-GitHubEnvironment.ps1 @@ -182,9 +182,7 @@ if ($PSCmdlet.ShouldProcess("Environment [$Owner/$Repository/$Name]", 'Set')) { Invoke-GitHubAPI @inputObject | ForEach-Object { - $environment = [GitHubEnvironment]::new($_.Response, $Owner, $Repository) - $environment.Url = "https://$($Context.HostName)/$Owner/$Repository/settings/environments/$($environment.ID)/edit" - $environment + [GitHubEnvironment]::new($_.Response, $Owner, $Repository, $Context) } } } diff --git a/src/functions/public/Organization/Get-GitHubOrganization.ps1 b/src/functions/public/Organization/Get-GitHubOrganization.ps1 index cd490cd5d..526e66e74 100644 --- a/src/functions/public/Organization/Get-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Get-GitHubOrganization.ps1 @@ -114,7 +114,7 @@ Get-GitHubAllOrganization -Since $Since -PerPage $PerPage -Context $Context } 'List all organizations for the authenticated user' { - Get-GitHubMyOrganization -PerPage $PerPage -Context $Context + Get-GitHubOrganizationListForAuthUser -PerPage $PerPage -Context $Context } default { Write-Error "Invalid parameter set name: $($PSCmdlet.ParameterSetName)" diff --git a/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 b/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 index 75e9bc920..2354b1fb0 100644 --- a/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 +++ b/src/functions/public/Organization/Members/Get-GitHubOrganizationMember.ps1 @@ -67,7 +67,9 @@ } Invoke-GitHubAPI @inputObject | ForEach-Object { - $_.Response | ForEach-Object { [GitHubUser]::new($_) } + foreach ($user in $_.Response) { + [GitHubUser]::new($user) + } } } diff --git a/src/functions/public/Organization/Update-GitHubOrganization.ps1 b/src/functions/public/Organization/Update-GitHubOrganization.ps1 index bfea406da..9095cf593 100644 --- a/src/functions/public/Organization/Update-GitHubOrganization.ps1 +++ b/src/functions/public/Organization/Update-GitHubOrganization.ps1 @@ -8,9 +8,9 @@ profile and member privileges. .EXAMPLE - Update-GitHubOrganization -Organization 'GitHub' -Blog 'https://github.blog' + Update-GitHubOrganization -Organization 'GitHub' -Description 'The official GitHub organization.' - Sets the blog URL for the organization 'GitHub' to ''. + Sets the description for the organization 'GitHub' to 'The official GitHub organization.'. .EXAMPLE $param = @{ @@ -134,9 +134,9 @@ [Parameter(ValueFromPipelineByPropertyName)] [bool] $WebCommitSignoffRequired, - # Path to the organization's blog. + # Path to the organization's site. [Parameter(ValueFromPipelineByPropertyName)] - [string] $Blog, + [string] $Website, # Whether secret scanning push protection is automatically enabled for new repositories. # To use this parameter, you must have admin permissions for the repository or be an owner or security manager for @@ -171,7 +171,7 @@ $body = @{ name = $NewName billing_email = $BillingEmail - blog = $Blog + blog = $Website company = $Company description = $Description email = $Email @@ -204,7 +204,7 @@ if ($PSCmdlet.ShouldProcess("organization [$Name]", 'Set')) { Invoke-GitHubAPI @inputObject | ForEach-Object { - [GitHubOrganization]::new($_.Response, '') + [GitHubOrganization]::new($_.Response, $Context) } } } diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 index e5356b44d..c26043b60 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 @@ -19,7 +19,6 @@ .LINK https://psmodule.io/GitHub/Functions/Repositories/Repositories/Get-GitHubRepositorySecurityFix #> - [Alias('Get-GitHubRepoSecurityFixes')] [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param( diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 index d24ceb1e3..741f9e9b3 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 @@ -39,7 +39,6 @@ param( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [Alias('org')] [string] $Owner, # The name of the repository without the .git extension. The name is not case sensitive. diff --git a/src/functions/public/Users/Update-GitHubUser.ps1 b/src/functions/public/Users/Update-GitHubUser.ps1 index 69af9e3d2..7338bb66c 100644 --- a/src/functions/public/Users/Update-GitHubUser.ps1 +++ b/src/functions/public/Users/Update-GitHubUser.ps1 @@ -19,9 +19,9 @@ Update the authenticated user's location to 'San Francisco' .EXAMPLE - Update-GitHubUser -Hireable $true -Bio 'I love programming' + Update-GitHubUser -Hireable $true -Description 'I love programming' - Update the authenticated user's hiring availability to 'true' and their biography to 'I love programming' + Update the authenticated user's hiring availability to 'true' and their description to 'I love programming' .NOTES [Update the authenticated user](https://docs.github.com/rest/users/users#update-the-authenticated-user) @@ -40,9 +40,10 @@ [Parameter()] [string] $Email, - # The new blog URL of the user. + # The new site for the user. [Parameter()] - [string] $Blog, + [Alias('Blog')] + [string] $Website, # The new Twitter username of the user. [Parameter()] @@ -62,7 +63,8 @@ # The new short biography of the user. [Parameter()] - [string] $Bio, + [Alias('Bio')] + [string] $Description, # 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. @@ -81,12 +83,12 @@ $body = @{ name = $DisplayName email = $Email - blog = $Blog + blog = $Website twitter_username = $TwitterUsername company = $Company location = $Location hireable = $Hireable - bio = $Bio + bio = $Description } $body | Remove-HashtableEntry -NullOrEmptyValues diff --git a/src/types/GitHubUser.Types.ps1xml b/src/types/GitHubUser.Types.ps1xml index f81e6433f..275d10688 100644 --- a/src/types/GitHubUser.Types.ps1xml +++ b/src/types/GitHubUser.Types.ps1xml @@ -7,6 +7,14 @@ User $this.Name + + Bio + $this.Description + + + Blog + $this.Website + diff --git a/tests/Enterprise.ps1 b/tests/Enterprise.Tests.ps1 similarity index 66% rename from tests/Enterprise.ps1 rename to tests/Enterprise.Tests.ps1 index 9a4760271..b6b7a73dd 100644 --- a/tests/Enterprise.ps1 +++ b/tests/Enterprise.Tests.ps1 @@ -33,11 +33,9 @@ Describe 'Template' { Write-Host ($context | Format-List | Out-String) } if ($AuthType -eq 'APP') { - It 'Connect-GitHubApp - Connects as a GitHub App to ' { + LogGroup 'Context - Installation' { $context = Connect-GitHubApp @connectAppParams -PassThru -Default -Silent - LogGroup 'Context - Installation' { - Write-Host ($context | Format-List | Out-String) - } + Write-Host ($context | Format-List | Out-String) } } } @@ -46,7 +44,7 @@ Describe 'Template' { Write-Host ('-' * 60) } - It 'Get-GitHubEnterprise - Can get info about an enterprise' -Skip:($OwnerType -notlike 'enterprise') { + It 'Get-GitHubEnterprise - Can get info about an enterprise' -Skip:($OwnerType -ne 'enterprise') { $enterprise = Get-GitHubEnterprise -Name $Owner LogGroup 'Enterprise' { Write-Host ($enterprise | Select-Object * | Out-String) @@ -58,29 +56,15 @@ Describe 'Template' { $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 '

This is a test

' $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 '
This is the description
' $enterprise.Location | Should -Be 'Oslo, Norway' - $enterprise.Blog | Should -Be 'https://msx.no' + $enterprise.Website | Should -Be 'https://msx.no' } } } diff --git a/tests/Organizations.Tests.ps1 b/tests/Organizations.Tests.ps1 index 32ddb2b28..4136b6b53 100644 --- a/tests/Organizations.Tests.ps1 +++ b/tests/Organizations.Tests.ps1 @@ -94,7 +94,7 @@ Describe 'Organizations' { { Update-GitHubOrganization -Name $owner -Description 'Test Organization' } | Should -Not -Throw { Update-GitHubOrganization -Name $owner -DefaultRepositoryPermission read } | Should -Not -Throw { Update-GitHubOrganization -Name $owner -MembersCanCreateRepositories $true } | Should -Not -Throw - { Update-GitHubOrganization -Name $owner -Blog 'https://psmodule.io' } | Should -Not -Throw + { Update-GitHubOrganization -Name $owner -Website 'https://psmodule.io' } | Should -Not -Throw } } diff --git a/tests/Users.Tests.ps1 b/tests/Users.Tests.ps1 index 5dcd0ec18..f4cb7cc32 100644 --- a/tests/Users.Tests.ps1 +++ b/tests/Users.Tests.ps1 @@ -54,17 +54,21 @@ Describe 'Users' { $user = Get-GitHubUser { Update-GitHubUser -DisplayName 'Octocat' } | Should -Not -Throw { Update-GitHubUser -Blog 'https://psmodule.io' } | Should -Not -Throw + { Update-GitHubUser -Website 'https://psmodule.io' } | Should -Not -Throw { Update-GitHubUser -TwitterUsername 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Company 'PSModule' } | Should -Not -Throw { Update-GitHubUser -Location 'USA' } | Should -Not -Throw { Update-GitHubUser -Bio 'I love programming' } | Should -Not -Throw + { Update-GitHubUser -Description 'I love programming' } | Should -Not -Throw $tmpUser = Get-GitHubUser $tmpUser.DisplayName | Should -Be 'Octocat' $tmpUser.Blog | Should -Be 'https://psmodule.io' + $tmpUser.Website | Should -Be 'https://psmodule.io' $tmpUser.TwitterUsername | Should -Be 'PSModule' $tmpUser.Company | Should -Be 'PSModule' $tmpUser.Location | Should -Be 'USA' $tmpUser.Bio | Should -Be 'I love programming' + $tmpUser.Description | Should -Be 'I love programming' # Flaky tests # { Update-GitHubUser -Hireable $true } | Should -Not -Throw