Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Coding Standards for `GitHub`

Start by reading the general coding standards for [`PSModule`](https://psmodule.io/docs) which is the basis for all modules in the framework.
Additions or adjustments to those defaults are covered in this document to ensure that the modules drive consistancy for all developers.
Additions or adjustments to those defaults are covered in this document to ensure that the modules drive consistency for all developers.

## General Coding Standards

Expand Down Expand Up @@ -173,7 +173,7 @@ All function documentation follows standard PowerShell help conventions, with so
- Remove any properties that are purely β€œAPI wrapper” fields (e.g., raw HTTP artifacts that aren’t relevant to the user).
- Cl

- Classes should have ID as the main resource ID, this is the databaseID. The node_id is spesifically in the NodeID property.
- Classes should have ID as the main resource ID, this is the databaseID. The node_id is specifically in the NodeID property.
- Classes that use nodeid and databaseid should extend the class called GitHubNode.
- Objects that belong inside another scope, has the parts of the scope in properties of the class, i.e. Enterprise, Owner/Organization/Account,
Repository, Environment, etc.
Expand Down
6 changes: 3 additions & 3 deletions examples/Connecting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ Connect-GitHub

# Log on to a specific instance of GitHub (enterprise)
Connect-GitHub -Host 'msx.ghe.com'
Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' # Contexts are selectable/overrideable on any call
Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' # Contexts are selectable/overridable on any call

# Connect to GitHub interactively using OAuth App and Device Flow.
Connect-GitHub -Mode 'OAuthApp' -Scope 'gist read:org repo workflow'

# Connect to GitHub interactively using less desired PAT flow, supports both fine-grained and classic PATs
Connect-GitHub -UseAccessToken

# Connect to GitHub programatically (GitHub App Installation Access Token or PAT)
# Connect to GitHub programmatically (GitHub App Installation Access Token or PAT)
Connect-GitHub -Token ***********

# Connect to GitHub programatically (GitHub Actions)
# Connect to GitHub programmatically (GitHub Actions)
Connect-GitHub # Looks for the GITHUB_TOKEN variable

# Connect using a GitHub App and its private key (local signing of JWT)
Expand Down
2 changes: 1 addition & 1 deletion src/classes/public/Releases/GitHubRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Example: "## What's Changed\n### Other Changes\n* Fix: Enhance repository deletion feedback and fix typo..."
[string] $Notes

# Specifies the commitish value that determines where the Git tag is created from
# Specifies the committish value that determines where the Git tag is created from
# Example: "main"
[string] $Target

Expand Down
17 changes: 15 additions & 2 deletions src/classes/public/Repositories/GitHubRepository.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
MergeCommitMessage = 'mergeCommitMessage'
TemplateRepository = 'templateRepository { id databaseId name owner { login } }'
ForkRepository = 'parent { id databaseId name owner { login } }'
CustomProperties = ''
CustomProperties = 'repositoryCustomPropertyValues(first: 100) { nodes { propertyName value } }'
CloneUrl = 'url'
SshUrl = 'sshUrl'
GitUrl = 'url'
Expand Down Expand Up @@ -298,7 +298,12 @@
$this.SquashMergeCommitTitle = $Object.squash_merge_commit_title
$this.MergeCommitMessage = $Object.merge_commit_message
$this.MergeCommitTitle = $Object.merge_commit_title
$this.CustomProperties = $Object.custom_properties
$this.CustomProperties = $Object.custom_properties | ForEach-Object {
[PSCustomObject]@{
Name = $_.property_name
Value = $_.value
}
}
$this.TemplateRepository = $null -ne $Object.template_repository ? [GitHubRepository]::New($Object.template_repository) : $null
$this.ForkRepository = $null -ne $Object.parent ? [GitHubRepository]::New($Object.parent) : $null
$this.CloneUrl = $Object.clone_url
Expand Down Expand Up @@ -353,6 +358,14 @@
$this.SquashMergeCommitMessage = $Object.squashMergeCommitMessage
$this.MergeCommitTitle = $Object.mergeCommitTitle
$this.MergeCommitMessage = $Object.mergeCommitMessage
if ($null -ne $Object.repositoryCustomPropertyValues -and $null -ne $Object.repositoryCustomPropertyValues.nodes) {
$this.CustomProperties = $Object.repositoryCustomPropertyValues.nodes | ForEach-Object {
[PSCustomObject]@{
Name = $_.propertyName
Value = $_.value
}
}
}
$this.TemplateRepository = $null -ne $Object.templateRepository ? [GitHubRepository]::New($Object.templateRepository) : $null
$this.ForkRepository = $null -ne $Object.parent ? [GitHubRepository]::New($Object.parent) : $null
$this.CloneUrl = -not [string]::IsNullOrEmpty($Object.url) ? $Object.url + '.git' : $null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingConvertToSecureStringWithPlainText', '',
Justification = 'The tokens are recieved as clear text. Mitigating exposure by removing variables and performing garbage collection.'
Justification = 'The tokens are received as clear text. Mitigating exposure by removing variables and performing garbage collection.'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidLongLines', '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ query(`$Slug: String!) {
Context = $Context
}
$enterpriseResult = Invoke-GitHubGraphQLQuery @enterpriseQuery
[GitHubEnterprise]::new($enterpriseResult.enterprise)
if ($enterpriseResult.enterprise) {
[GitHubEnterprise]::new($enterpriseResult.enterprise)
}
}

end {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ query(`$owner: String!, `$repository: String!, `$tag: String!, `$perPage: Int, `

Invoke-GitHubGraphQLQuery @apiParams | ForEach-Object {
$release = $_.repository.release
$assets = $release.releaseAssets
foreach ($asset in $assets.nodes) {
[GitHubReleaseAsset]::new($asset)
if ($release) {
$assets = $release.releaseAssets
foreach ($asset in $assets.nodes) {
[GitHubReleaseAsset]::new($asset)
}
$hasNextPage = $assets.pageInfo.hasNextPage
$after = $assets.pageInfo.endCursor
}
$hasNextPage = $assets.pageInfo.hasNextPage
$after = $assets.pageInfo.endCursor
}
} while ($hasNextPage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ query(`$owner: String!, `$repository: String!, `$perPage: Int, `$after: String)

Invoke-GitHubGraphQLQuery @apiParams | ForEach-Object {
$release = $_.repository.latestRelease
$assets = $release.releaseAssets
foreach ($asset in $assets.nodes) {
[GitHubReleaseAsset]::new($asset)
if ($release) {
$assets = $release.releaseAssets
foreach ($asset in $assets.nodes) {
[GitHubReleaseAsset]::new($asset)
}
$hasNextPage = $assets.pageInfo.hasNextPage
$after = $assets.pageInfo.endCursor
}
$hasNextPage = $assets.pageInfo.hasNextPage
$after = $assets.pageInfo.endCursor
}
} while ($hasNextPage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
'MergeCommitMessage',
'TemplateRepository',
'ForkRepository',
'CustomProperties',
'CloneUrl',
'SshUrl',
'GitUrl'
Expand Down Expand Up @@ -128,7 +127,10 @@ $graphQLFields
}

Invoke-GitHubGraphQLQuery @apiParams | ForEach-Object {
[GitHubRepository]::new($_.viewer.repository)
$repository = $_.viewer.repository
if ($repository) {
[GitHubRepository]::new($repository)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
'MergeCommitMessage',
'TemplateRepository',
'ForkRepository',
'CustomProperties',
'CloneUrl',
'SshUrl',
'GitUrl'
Expand Down Expand Up @@ -135,7 +134,10 @@ $graphQLFields
}

Invoke-GitHubGraphQLQuery @apiParams | ForEach-Object {
[GitHubRepository]::new($_.repositoryOwner.repository)
$repository = $_.repositoryOwner.repository
if ($repository) {
[GitHubRepository]::new($repository)
}
}
}

Expand Down
50 changes: 31 additions & 19 deletions src/functions/public/API/Invoke-GitHubGraphQLQuery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,44 @@
$graphQLResponse = $apiResponse.Response
# Handle GraphQL-specific errors (200 OK with errors in response)
if ($graphQLResponse.errors) {
$errorMessages = @()
$queryLines = $Query -split "`n" | ForEach-Object { $_.Trim() }
foreach ($errorItem in $graphQLResponse.errors) {
$errorMessages += @"
# Partial success: data was returned alongside errors (per GraphQL spec).
# Emit warnings for the partial errors and return the data.
if ($null -ne $graphQLResponse.data) {
foreach ($errorItem in $graphQLResponse.errors) {
$warningMessage = @"
GraphQL partial errors occurred
Type: $($errorItem.type)
Message: $($errorItem.message)
Path: $($errorItem.path -join '/')

"@
Write-Warning $warningMessage
}
} else {
# Full failure: no data returned, only errors.
$errorMessages = @()
foreach ($errorItem in $graphQLResponse.errors) {
$errorMessages += @"
GraphQL terminating errors occurred
Type: $($errorItem.type)
Message: $($errorItem.message)
Path: $($errorItem.path -join '/')

GraphQL errors occurred:
Full Error:
$($errorItem | ConvertTo-Json -Depth 10 | Out-String)

GraphQL Error [$($errorItem.type)]:
Message: $($errorItem.message)
Path: $($errorItem.path -join '/')
Locations:
$($errorItem.locations | ForEach-Object { " - [$($_.line):$($_.column)] - $($queryLines[$_.line - 1])" })

"@

}
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
[System.Exception]::new($errorMessages),
'GraphQLError',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$graphQLResponse
}
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
[System.Exception]::new($errorMessages),
'GraphQLError',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$graphQLResponse
)
)
)
}
}

$graphQLResponse.data
Expand Down
4 changes: 2 additions & 2 deletions src/functions/public/Actions/Data/Get-GitHubRunnerData.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ο»Ώfunction Get-GitHubRunnerData {
<#
.SYNOPSIS
Gets data about the runner thats running the workflow.
Gets data about the runner that's running the workflow.

.DESCRIPTION
Gets data about the runner thats running the workflow.
Gets data about the runner that's running the workflow.

.EXAMPLE
```powershell
Expand Down
2 changes: 1 addition & 1 deletion src/functions/public/Commands/Set-GitHubLogGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.DESCRIPTION
DSL approach for GitHub Action commands.
Allows for colapsing of code in IDE for code that belong together.
Allows for collapsing of code in IDE for code that belong together.

.EXAMPLE
```powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.DESCRIPTION
DSL approach for GitHub Action commands.
Allows for colapsing of code in IDE for code that belong together.
Allows for collapsing of code in IDE for code that belong together.

.EXAMPLE
```powershell
Expand Down
2 changes: 1 addition & 1 deletion src/functions/public/Releases/New-GitHubRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
[string] $DiscussionCategoryName,

# Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise,
# a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes.
# a name will be automatically generated. If body is specified, the body will be prepended to the automatically generated notes.
[Parameter()]
[switch] $GenerateReleaseNotes,

Expand Down
2 changes: 1 addition & 1 deletion src/functions/public/Releases/New-GitHubReleaseNote.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string] $Tag,

# Specifies the commitish value that will be the target for the release's tag.
# Specifies the committish value that will be the target for the release's tag.
# Required if the supplied tag_name does not reference an existing tag.
# Ignored if the tag_name already exists.
[Parameter()]
Expand Down
2 changes: 1 addition & 1 deletion src/functions/public/Releases/Set-GitHubRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
[string] $DiscussionCategoryName,

# Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise,
# a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes.
# a name will be automatically generated. If body is specified, the body will be prepended to the automatically generated notes.
[Parameter()]
[switch] $GenerateReleaseNotes,

Expand Down
4 changes: 2 additions & 2 deletions src/functions/public/Releases/Update-GitHubRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
[Parameter()]
[string] $Tag,

# Specifies the commitish value that determines where the Git tag is created from.
# Specifies the committish value that determines where the Git tag is created from.
# Can be any branch or commit SHA. Unused if the Git tag already exists.
# API Default: the repository's default branch.
[Parameter()]
Expand Down Expand Up @@ -100,7 +100,7 @@
[string] $DiscussionCategoryName,

# Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise,
# a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes.
# a name will be automatically generated. If body is specified, the body will be prepended to the automatically generated notes.
[Parameter()]
[switch] $GenerateReleaseNotes,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
[Parameter(Mandatory)]
[string] $Name,

# Wether to include anonymous contributors in results.
# Whether to include anonymous contributors in results.
[Parameter()]
[switch] $Anon,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

.DESCRIPTION
Scheduled maintenances are planned outages, upgrades, or general notices that you're working
on infrastructure and disruptions may occurr. A close sibling of Incidents, each usually goes
on infrastructure and disruptions may occur. A close sibling of Incidents, each usually goes
through a progression of statuses listed below, with an impact calculated from a blend of
component statuses (or an optional override).

Expand Down
2 changes: 1 addition & 1 deletion tests/Enterprise.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
param()

BeforeAll {
# DEFAULTS ACCROSS ALL TESTS
# DEFAULTS ACROSS ALL TESTS
}

Describe 'Template' {
Expand Down
4 changes: 2 additions & 2 deletions tests/GitHub.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ Describe 'API' {
}
$licenseList | Should -Not -BeNullOrEmpty
}
It 'Get-GitHubLicense - Gets a spesific license' {
It 'Get-GitHubLicense - Gets a specific license' {
$mitLicense = Get-GitHubLicense -Name 'mit'
LogGroup 'MIT License' {
Write-Host ($mitLicense | Format-Table | Out-String)
Expand Down Expand Up @@ -766,7 +766,7 @@ Describe 'API' {
}
$markdown | Should -Not -BeNullOrEmpty
}
It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formated Markdown' {
It 'Get-GitHubMarkdown - Gets the rendered markdown for provided text using GitHub Formatted Markdown' {
$gfmMarkdown = Get-GitHubMarkdown -Text 'Hello, World!' -Mode gfm
LogGroup 'GFM Markdown' {
Write-Host ($gfmMarkdown | Format-Table | Out-String)
Expand Down
2 changes: 1 addition & 1 deletion tests/Secrets.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Describe 'Secrets' {
}
}

It 'Set-GitHubSecret - should ensure existance of a organization secret' {
It 'Set-GitHubSecret - should ensure existence of a organization secret' {
$name = "$secretName`_TestSecret"
LogGroup "Secret - [$name]" {
$param = @{
Expand Down
2 changes: 1 addition & 1 deletion tests/TEMPLATE.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
param()

BeforeAll {
# DEFAULTS ACCROSS ALL TESTS
# DEFAULTS ACROSS ALL TESTS
}

Describe 'Template' {
Expand Down
2 changes: 1 addition & 1 deletion tests/Variables.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Describe 'Variables' {
Owner = $owner
}
}
It 'Set-GitHubVariable - should ensure existance of a organization variable' {
It 'Set-GitHubVariable - should ensure existence of a organization variable' {
$name = "$variableName`TestVariable"
LogGroup "Variable - [$name]" {
$param = @{
Expand Down
Loading