Skip to content

Commit 25832f9

Browse files
🩹 [Patch]: Fix and align argument completers (#508)
This pull request introduces several improvements and refactors across argument completer scripts, license and gitignore handling, and data formatting. The main goals are to standardize completer parameter usage, enhance context-awareness and filtering, improve data sorting and output, and clarify the license data model. - Fixes #486 **Key changes:** ### Argument Completer Improvements and Refactoring * Updated all argument completers to use `$fakeBoundParameters` instead of `$fakeBoundParameter`, ensuring consistency and enabling context-aware completions across the module. Added filtering and context parameters where appropriate. [[1]](diffhunk://#diff-22b2affe76b37eaa2b3cdee057e05020af8aa4890e0966e676e4a936d828e4e4L2-R3) [[2]](diffhunk://#diff-22b2affe76b37eaa2b3cdee057e05020af8aa4890e0966e676e4a936d828e4e4L15-R18) [[3]](diffhunk://#diff-775e15ad0206292ebf4f5d7659e274c2384326d9b0e9821b96280186769ba4d8L2-R3) [[4]](diffhunk://#diff-ba8339f3d5f55d7346080dc2bd24097cc8d0bc87fc027a237bfa53617224b25eL1-R26) [[5]](diffhunk://#diff-7d92b4f19fe6156533814de81d6618281c98a1914b85a2373be2638b660f0a96L5-R37) [[6]](diffhunk://#diff-dc5710dd4a873f6fe7a26f241fd8261acdb594962c405f48982396275d6a530fR1-R12) [[7]](diffhunk://#diff-eb8a0b19f6f2c88ecc3a09e6544d51dc0c5d8c61ad4f8fe40d544fc182c0ac91R1-R12) [[8]](diffhunk://#diff-792b150421507ebd45a85f5eedf88b6fc3ead29405ceff31779746e5cd5bf7c7R1-R39) * Moved and refactored several completers (for `Get-GitHubLicense`, `Get-GitHubGitignore`, and `Connect-GitHubApp`) into their own dedicated `completers.ps1` files, and removed the old implementations. [[1]](diffhunk://#diff-de6b8171283593a8a3424849e06ab22a6d6ead1c9a677db2f91ffa2225759363L87-L94) [[2]](diffhunk://#diff-349ba6d13800f374dc911b94db55e01a2e50be26859901f1eccf6a94d85ee05cL70-L77) [[3]](diffhunk://#diff-2fcb088cf090e075faa3b356b6d08d341de9167e4e69d5270f34f7faf46e6cd7L1-L27) ### License Model and Formatting Updates * Changed the `GitHubLicense` class to clarify property names: `Key` is now `Name`, and `Name` is now `DisplayName`, with corresponding updates to the constructor and format file. [[1]](diffhunk://#diff-98f2ef3a26cb403b39286027e24110885695960c6c8b26853bd2af0c62e9f15eL26-R32) [[2]](diffhunk://#diff-98f2ef3a26cb403b39286027e24110885695960c6c8b26853bd2af0c62e9f15eL81-R82) [[3]](diffhunk://#diff-f3cb0ef91f12f89dc4c0b19bb042e6e2c4a71bb4040b46a853e4c71916c43e98L11-L32) [[4]](diffhunk://#diff-f3cb0ef91f12f89dc4c0b19bb042e6e2c4a71bb4040b46a853e4c71916c43e98L44-L85) * Updated the license format table to display the new property names and removed less relevant columns for a cleaner output. [[1]](diffhunk://#diff-f3cb0ef91f12f89dc4c0b19bb042e6e2c4a71bb4040b46a853e4c71916c43e98L11-L32) [[2]](diffhunk://#diff-f3cb0ef91f12f89dc4c0b19bb042e6e2c4a71bb4040b46a853e4c71916c43e98L44-L85) ### Context and Filtering Enhancements * Improved context handling and filtering for completers, ensuring that completions are accurate with respect to the current context and user input. [[1]](diffhunk://#diff-22b2affe76b37eaa2b3cdee057e05020af8aa4890e0966e676e4a936d828e4e4L15-R18) [[2]](diffhunk://#diff-7d92b4f19fe6156533814de81d6618281c98a1914b85a2373be2638b660f0a96L5-R37) [[3]](diffhunk://#diff-ba8339f3d5f55d7346080dc2bd24097cc8d0bc87fc027a237bfa53617224b25eL1-R26) [[4]](diffhunk://#diff-dc5710dd4a873f6fe7a26f241fd8261acdb594962c405f48982396275d6a530fR1-R12) [[5]](diffhunk://#diff-eb8a0b19f6f2c88ecc3a09e6544d51dc0c5d8c61ad4f8fe40d544fc182c0ac91R1-R12) * Added support for `App` authentication to `Get-GitHubLicense`, and ensured that if the context is an App, it falls back to anonymous. ### Data Sorting and Output Consistency * Ensured that results from `Get-GitHubAppInstallation` are sorted by `Type` and `Target` for more predictable output. [[1]](diffhunk://#diff-9ca965372ef6314e8f8759ce87dedff3c8a0d216fe06fda41e0fb38b89722dfeL60-R60) [[2]](diffhunk://#diff-9ca965372ef6314e8f8759ce87dedff3c8a0d216fe06fda41e0fb38b89722dfeR81) ### Miscellaneous * Commented out an unused `Accept` header in the gitignore API call, likely to prevent issues with response formatting. These changes collectively improve the maintainability, usability, and consistency of the module's command-line experience. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: MariusStorhaug <[email protected]> Co-authored-by: Marius Storhaug <[email protected]>
1 parent 8972167 commit 25832f9

File tree

23 files changed

+203
-200
lines changed

23 files changed

+203
-200
lines changed

src/classes/public/GitHubLicense.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323

2424

2525
class GitHubLicense {
26-
# The license key, used as an identifier.
27-
# Example: 'mit'
28-
[string] $Key
26+
# The license name, used as an identifier.
27+
# Example: 'MIT'
28+
[string] $Name
2929

30-
# The full name of the license.
30+
# The display name of the license.
3131
# Example: 'MIT License'
32-
[string] $Name
32+
[string] $DisplayName
3333

34-
# Customary short name if applicable (e.g, GPLv3).
35-
# Example: 'MIT'
36-
[string] $NickName
34+
# The license key.
35+
# Example: 'mit'
36+
[string] $Key
3737

3838
# The SPDX identifier of the license, or $null.
3939
# Example: 'MIT'
@@ -78,9 +78,9 @@ class GitHubLicense {
7878
GitHubLicense() {}
7979

8080
GitHubLicense([PSCustomObject]$Object) {
81+
$this.Name = $Object.spdx_id ?? $Object.spdxId
82+
$this.DisplayName = $Object.name
8183
$this.Key = $Object.key
82-
$this.Name = $Object.name
83-
$this.NickName = $Object.nickname
8484
$this.SpdxId = $Object.spdx_id ?? $Object.spdxId
8585
$this.NodeID = $Object.node_id ?? $Object.id
8686
$this.Url = $Object.html_url ?? $Object.url

src/classes/public/Repositories/GitHubRepository.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
IsArchived = 'isArchived'
219219
IsTemplate = 'isTemplate'
220220
IsFork = 'isFork'
221-
License = 'licenseInfo { name }'
221+
License = 'licenseInfo { name key spdxId }'
222222
AllowForking = 'forkingAllowed'
223223
RequireWebCommitSignoff = 'webCommitSignoffRequired'
224224
Topics = 'repositoryTopics(first: 20) { nodes { topic { name } } }'

src/completers.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Register-ArgumentCompleter -CommandName Connect-GitHubApp -ParameterName User -ScriptBlock {
2+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
3+
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
4+
5+
$params = @{
6+
Context = $fakeBoundParameters.Context
7+
Verbose = $false
8+
Debug = $false
9+
}
10+
Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'User' -and $_.Target.Name -like "$wordToComplete*" } | ForEach-Object {
11+
[System.Management.Automation.CompletionResult]::new($_.Target.Name, $_.Target.Name, 'ParameterValue', $_.Target.Name)
12+
}
13+
}
14+
Register-ArgumentCompleter -CommandName Connect-GitHubApp -ParameterName Organization -ScriptBlock {
15+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
16+
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
17+
18+
$params = @{
19+
Context = $fakeBoundParameters.Context
20+
Verbose = $false
21+
Debug = $false
22+
}
23+
Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'Organization' -and $_.Target.Name -like "$wordToComplete*" } | ForEach-Object {
24+
[System.Management.Automation.CompletionResult]::new($_.Target.Name, $_.Target.Name, 'ParameterValue', $_.Target.Name)
25+
}
26+
}
27+
Register-ArgumentCompleter -CommandName Connect-GitHubApp -ParameterName Enterprise -ScriptBlock {
28+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
29+
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
30+
31+
$params = @{
32+
Context = $fakeBoundParameters.Context
33+
Verbose = $false
34+
Debug = $false
35+
}
36+
Get-GitHubAppInstallation @params | Where-Object { $_.Type -eq 'Enterprise' -and $_.Target.Name -like "$wordToComplete*" } | ForEach-Object {
37+
[System.Management.Automation.CompletionResult]::new($_.Target.Name, $_.Target.Name, 'ParameterValue', $_.Target.Name)
38+
}
39+
}

src/formats/GitHubLicense.Format.ps1xml

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,16 @@
88
</ViewSelectedBy>
99
<TableControl>
1010
<TableHeaders>
11-
<TableColumnHeader>
12-
<Label>Key</Label>
13-
</TableColumnHeader>
1411
<TableColumnHeader>
1512
<Label>Name</Label>
1613
</TableColumnHeader>
1714
<TableColumnHeader>
18-
<Label>SpdxId</Label>
19-
</TableColumnHeader>
20-
<TableColumnHeader>
21-
<Label>ApiUrl</Label>
22-
</TableColumnHeader>
23-
<TableColumnHeader>
24-
<Label>NodeID</Label>
15+
<Label>DisplayName</Label>
2516
</TableColumnHeader>
2617
</TableHeaders>
2718
<TableRowEntries>
2819
<TableRowEntry>
2920
<TableColumnItems>
30-
<TableColumnItem>
31-
<PropertyName>Key</PropertyName>
32-
</TableColumnItem>
3321
<TableColumnItem>
3422
<ScriptBlock>
3523
if ($Host.UI.SupportsVirtualTerminal -and
@@ -41,47 +29,12 @@
4129
</ScriptBlock>
4230
</TableColumnItem>
4331
<TableColumnItem>
44-
<PropertyName>SpdxId</PropertyName>
45-
</TableColumnItem>
46-
<TableColumnItem>
47-
<PropertyName>ApiUrl</PropertyName>
48-
</TableColumnItem>
49-
<TableColumnItem>
50-
<PropertyName>NodeID</PropertyName>
32+
<PropertyName>DisplayName</PropertyName>
5133
</TableColumnItem>
5234
</TableColumnItems>
5335
</TableRowEntry>
5436
</TableRowEntries>
5537
</TableControl>
5638
</View>
57-
<View>
58-
<Name>GitHubLicenseListView</Name>
59-
<ViewSelectedBy>
60-
<TypeName>GitHubLicense</TypeName>
61-
</ViewSelectedBy>
62-
<ListControl>
63-
<ListEntries>
64-
<ListEntry>
65-
<ListItems>
66-
<ListItem>
67-
<PropertyName>Key</PropertyName>
68-
</ListItem>
69-
<ListItem>
70-
<PropertyName>Name</PropertyName>
71-
</ListItem>
72-
<ListItem>
73-
<PropertyName>SpdxId</PropertyName>
74-
</ListItem>
75-
<ListItem>
76-
<PropertyName>ApiUrl</PropertyName>
77-
</ListItem>
78-
<ListItem>
79-
<PropertyName>NodeID</PropertyName>
80-
</ListItem>
81-
</ListItems>
82-
</ListEntry>
83-
</ListEntries>
84-
</ListControl>
85-
</View>
8639
</ViewDefinitions>
8740
</Configuration>

src/functions/private/Gitignore/Get-GitHubGitignoreByName.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
$apiParams = @{
3838
Method = 'GET'
3939
APIEndpoint = "/gitignore/templates/$Name"
40-
Accept = 'application/vnd.github.raw+json'
40+
# Accept = 'application/vnd.github.raw+json'
4141
Context = $Context
4242
}
4343

src/functions/public/Apps/GitHub App Installations/Get-GitHubAppInstallation.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
Context = $Context
5858
}
5959
Write-Debug "ParamSet: $($PSCmdlet.ParameterSetName)"
60-
switch ($PSCmdlet.ParameterSetName) {
60+
$installations = switch ($PSCmdlet.ParameterSetName) {
6161
'List installations on an Enterprise' {
6262
$params += @{
6363
Enterprise = $Enterprise
@@ -78,6 +78,7 @@
7878
}
7979

8080
end {
81+
$installations | Sort-Object -Property Type, Target
8182
Write-Debug "[$stackPath] - End"
8283
}
8384
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) -ParameterName Context -ScriptBlock {
2-
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
3-
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter
2+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
3+
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
44

55
$contexts = @()
66
$hasAnonymousParameter = $false
@@ -12,9 +12,9 @@
1212
$contexts += 'Anonymous'
1313
}
1414

15-
$contexts += (Get-GitHubContext -ListAvailable -Verbose:$false -Debug:$false).Name
16-
$contexts = $contexts | Sort-Object -Unique
17-
$contexts | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
18-
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
15+
$contexts += Get-GitHubContext -ListAvailable -Verbose:$false -Debug:$false
16+
$contexts = $contexts | Sort-Object -Property Name
17+
$contexts | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object {
18+
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name)
1919
}
2020
}

src/functions/public/Auth/completer.ps1

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/functions/public/Config/completers.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Register-ArgumentCompleter -CommandName Set-GitHubConfig, Get-GitHubConfig, Remove-GitHubConfig -ParameterName Name -ScriptBlock {
2-
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
3-
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter
4-
2+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
3+
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
54
([GitHubConfig]).GetProperties().Name | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
65
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_ )
76
}

src/functions/public/Environments/completers.ps1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Complete the Name parameter for all *GitHubEnvironment commands
2-
Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport |
1+
Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport |
32
Where-Object { $_ -like '*GitHubEnvironment' }) -ParameterName Name -ScriptBlock {
4-
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
5-
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter
6-
3+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
4+
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
75
$params = @{
8-
Owner = $fakeBoundParameter.Owner
9-
Repository = $fakeBoundParameter.Repository
10-
Context = $fakeBoundParameter.Context
6+
Owner = $fakeBoundParameters.Owner
7+
Repository = $fakeBoundParameters.Repository
8+
Context = $fakeBoundParameters.Context
9+
Verbose = $false
10+
Debug = $false
1111
}
1212
$params | Remove-HashtableEntry -NullOrEmptyValues
1313
Get-GitHubEnvironment @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object {
1414
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name)
1515
}
1616
}
1717

18-
# Complete the Environment parameter for all functions in the module
1918
Register-ArgumentCompleter -CommandName ($script:PSModuleInfo.FunctionsToExport) -ParameterName Environment -ScriptBlock {
20-
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
21-
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter
22-
19+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
20+
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
2321
$params = @{
24-
Owner = $fakeBoundParameter.Owner
25-
Repository = $fakeBoundParameter.Repository
26-
Context = $fakeBoundParameter.Context
22+
Owner = $fakeBoundParameters.Owner
23+
Repository = $fakeBoundParameters.Repository
24+
Context = $fakeBoundParameters.Context
25+
Verbose = $false
26+
Debug = $false
2727
}
2828
$params | Remove-HashtableEntry -NullOrEmptyValues
2929
Get-GitHubEnvironment @params | Where-Object { $_.Name -like "$wordToComplete*" } | ForEach-Object {

0 commit comments

Comments
 (0)