Skip to content

Commit ca8fe16

Browse files
committed
Applying CR feedback and adding additional tests
1 parent 0f9278b commit ca8fe16

File tree

3 files changed

+188
-40
lines changed

3 files changed

+188
-40
lines changed

GitHubCore.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ function Invoke-GHRestMethod
127127

128128
[string] $AcceptHeader = $script:defaultAcceptHeader,
129129

130+
[ValidateNotNullOrEmpty()]
130131
[string] $InFile,
131132

132133
[string] $ContentType = $script:defaultJsonBodyContentType,
@@ -149,14 +150,14 @@ function Invoke-GHRestMethod
149150
Invoke-UpdateCheck
150151

151152
# Minor error checking around $InFile
152-
if ((-not [String]::IsNullOrWhiteSpace($InFile)) -and ($Method -ne 'Post'))
153+
if ($PSBoundParameters.ContainsKey('InFile') -and ($Method -ne 'Post'))
153154
{
154155
$message = '-InFile may only be specified with Post requests.'
155156
Write-Log -Message $message -Level Error
156157
throw $message
157158
}
158159

159-
if ((-not [String]::IsNullOrWhiteSpace($InFile)) -and (-not [String]::IsNullOrWhiteSpace($Body)))
160+
if ($PSBoundParameters.ContainsKey('InFile') -and (-not [String]::IsNullOrWhiteSpace($Body)))
160161
{
161162
$message = 'Cannot specify BOTH InFile and Body'
162163
Write-Log -Message $message -Level Error
@@ -233,6 +234,8 @@ function Invoke-GHRestMethod
233234
if ($PSBoundParameters.ContainsKey('InFile') -and [String]::IsNullOrWhiteSpace($ContentType))
234235
{
235236
$file = Get-Item -Path $InFile
237+
$localTelemetryProperties['FileExtension'] = $file.Extension
238+
236239
if ($script:extensionToContentType.ContainsKey($file.Extension))
237240
{
238241
$ContentType = $script:extensionToContentType[$file.Extension]

GitHubReleases.ps1

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
function Get-GitHubRelease
4+
filter Get-GitHubRelease
55
{
66
<#
77
.SYNOPSIS
@@ -26,7 +26,7 @@ function Get-GitHubRelease
2626
them individually.
2727
2828
.PARAMETER Release
29-
Specific releaseId of a release.
29+
Specific Release ID of a release.
3030
This is an optional parameter which can limit the results to a single release.
3131
3232
.PARAMETER Latest
@@ -127,9 +127,11 @@ function Get-GitHubRelease
127127

128128
[Parameter(
129129
Mandatory,
130+
ValueFromPipelineByPropertyName,
130131
ParameterSetName='Elements-ReleaseId')]
131132
[Parameter(
132133
Mandatory,
134+
ValueFromPipelineByPropertyName,
133135
ParameterSetName='Uri-ReleaseId')]
134136
[Alias('ReleaseId')]
135137
[int64] $Release,
@@ -199,7 +201,7 @@ function Get-GitHubRelease
199201
'AccessToken' = $AccessToken
200202
'TelemetryEventName' = $MyInvocation.MyCommand.Name
201203
'TelemetryProperties' = $telemetryProperties
202-
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -BoundParameters $PSBoundParameters -Name NoStatus -ConfigValueName DefaultNoStatus)
204+
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
203205
}
204206

205207
$multipleResult = Invoke-GHRestMethodMultipleResult @params
@@ -213,7 +215,7 @@ function Get-GitHubRelease
213215
return $multipleResult
214216
}
215217

216-
function New-GitHubRelease
218+
filter New-GitHubRelease
217219
{
218220
<#
219221
.SYNOPSIS
@@ -291,7 +293,7 @@ function New-GitHubRelease
291293
Mandatory,
292294
ValueFromPipelineByPropertyName,
293295
ParameterSetName='Uri')]
294-
[Alias('html_url')]
296+
[Alias('RepositoryUrl')]
295297
[string] $Uri,
296298

297299
[Parameter(Mandatory)]
@@ -357,7 +359,7 @@ function New-GitHubRelease
357359
return $result
358360
}
359361

360-
function Set-GitHubRelease
362+
filter Set-GitHubRelease
361363
{
362364
<#
363365
.SYNOPSIS
@@ -435,7 +437,7 @@ function Set-GitHubRelease
435437
Mandatory,
436438
ValueFromPipelineByPropertyName,
437439
ParameterSetName='Uri')]
438-
[Alias('html_url')]
440+
[Alias('RepositoryUrl')]
439441
[string] $Uri,
440442

441443
[Parameter(
@@ -505,7 +507,7 @@ function Set-GitHubRelease
505507
return $result
506508
}
507509

508-
function Remove-GitHubRelease
510+
filter Remove-GitHubRelease
509511
{
510512
<#
511513
.SYNOPSIS
@@ -570,7 +572,7 @@ function Remove-GitHubRelease
570572
Mandatory,
571573
ValueFromPipelineByPropertyName,
572574
ParameterSetName='Uri')]
573-
[Alias('html_url')]
575+
[Alias('ReositoryUrl')]
574576
[string] $Uri,
575577

576578
[Parameter(
@@ -611,7 +613,7 @@ function Remove-GitHubRelease
611613
}
612614
}
613615

614-
function Get-GitHubReleaseAsset
616+
filter Get-GitHubReleaseAsset
615617
{
616618
<#
617619
.SYNOPSIS
@@ -635,6 +637,9 @@ function Get-GitHubReleaseAsset
635637
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
636638
them individually.
637639
640+
.PARAMETER Release
641+
The ID of a specific release to see the assets for.
642+
638643
.PARAMETER Asset
639644
The ID of the specific asset to download.
640645
@@ -655,10 +660,15 @@ function Get-GitHubReleaseAsset
655660
If not supplied here, the DefaultNoStatus configuration property value will be used.
656661
657662
.EXAMPLE
658-
Remove-GitHubRelease -OwnerName microsoft -RepositoryName PowerShellForGitHub -Release 1234567890
663+
Get-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Release 1234567890
659664
660-
.NOTES
661-
Requires push access to the repository.
665+
Gets a list of all the assets associated with this release
666+
667+
.EXAMPLE
668+
Get-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Asset 1234567890 -Path 'c:\users\PowerShellForGitHub\downloads\asset.zip' -Force
669+
670+
Downloads the asset 1234567890 to 'c:\users\PowerShellForGitHub\downloads\asset.zip' and
671+
overwrites the file that may already be there.
662672
#>
663673
[CmdletBinding(
664674
SupportsShouldProcess,
@@ -678,35 +688,47 @@ function Get-GitHubReleaseAsset
678688

679689
[Parameter(
680690
Mandatory,
691+
ValueFromPipelineByPropertyName,
681692
ParameterSetName='Uri-Info')]
682693
[Parameter(
683694
Mandatory,
695+
ValueFromPipelineByPropertyName,
684696
ParameterSetName='Uri-Download')]
685697
[Parameter(
686698
Mandatory,
699+
ValueFromPipelineByPropertyName,
687700
ParameterSetName='Uri-List')]
701+
[Alias('RepositoryUrl')]
688702
[string] $Uri,
689703

690704
[Parameter(
691705
Mandatory,
706+
ValueFromPipelineByPropertyName,
692707
ParameterSetName='Elements-List')]
693708
[Parameter(
694709
Mandatory,
710+
ValueFromPipelineByPropertyName,
695711
ParameterSetName='Uri-List')]
712+
[Alias('ReleaseId')]
696713
[int64] $Release,
697714

698715
[Parameter(
699716
Mandatory,
717+
ValueFromPipelineByPropertyName,
700718
ParameterSetName='Elements-Info')]
701719
[Parameter(
702720
Mandatory,
721+
ValueFromPipelineByPropertyName,
703722
ParameterSetName='Elements-Download')]
704723
[Parameter(
705724
Mandatory,
725+
ValueFromPipelineByPropertyName,
706726
ParameterSetName='Uri-Info')]
707727
[Parameter(
708728
Mandatory,
729+
ValueFromPipelineByPropertyName,
709730
ParameterSetName='Uri-Download')]
731+
[Alias('AssetId')]
710732
[int64] $Asset,
711733

712734
[Parameter(
@@ -786,7 +808,7 @@ function Get-GitHubReleaseAsset
786808
}
787809
}
788810

789-
function New-GitHubReleaseAsset
811+
filter New-GitHubReleaseAsset
790812
{
791813
<#
792814
.SYNOPSIS
@@ -838,7 +860,7 @@ function New-GitHubReleaseAsset
838860
If not supplied here, the DefaultNoStatus configuration property value will be used.
839861
840862
.EXAMPLE
841-
New-GitHubRelease -OwnerName microsoft -RepositoryName PowerShellForGitHub -TagName 0.12.0
863+
New-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -TagName 0.12.0
842864
843865
.NOTES
844866
GitHub renames asset filenames that have special characters, non-alphanumeric characters,
@@ -861,15 +883,20 @@ function New-GitHubReleaseAsset
861883

862884
[Parameter(
863885
Mandatory,
886+
ValueFromPipelineByPropertyName,
864887
ParameterSetName='Uri')]
888+
[Alias('RepositoryUrl')]
865889
[string] $Uri,
866890

867891
[Parameter(
868892
Mandatory,
893+
ValueFromPipelineByPropertyName,
869894
ParameterSetName='Elements')]
870895
[Parameter(
871896
Mandatory,
897+
ValueFromPipelineByPropertyName,
872898
ParameterSetName='Uri')]
899+
[Alias('ReleaseId')]
873900
[int64] $Release,
874901

875902
[Parameter(
@@ -942,7 +969,7 @@ function New-GitHubReleaseAsset
942969
return Invoke-GHRestMethod @params
943970
}
944971

945-
function Set-GitHubReleaseAsset
972+
filter Set-GitHubReleaseAsset
946973
{
947974
<#
948975
.SYNOPSIS
@@ -973,7 +1000,7 @@ function Set-GitHubReleaseAsset
9731000
The new filename of the asset.
9741001
9751002
.PARAMETER Label
976-
An alternate short description o fthe asset. Used in place of the filename.
1003+
An alternate short description of the asset. Used in place of the filename.
9771004
9781005
.PARAMETER AccessToken
9791006
If provided, this will be used as the AccessToken for authentication with the
@@ -988,6 +1015,8 @@ function Set-GitHubReleaseAsset
9881015
.EXAMPLE
9891016
Set-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Asset 123456 -Name bar.zip
9901017
1018+
Renames the asset 123456 to be 'bar.zip'.
1019+
9911020
.NOTES
9921021
Requires push access to the repository.
9931022
#>
@@ -1005,10 +1034,15 @@ function Set-GitHubReleaseAsset
10051034

10061035
[Parameter(
10071036
Mandatory,
1037+
ValueFromPipelineByPropertyName,
10081038
ParameterSetName='Uri')]
1039+
[Alias('RepositoryUrl')]
10091040
[string] $Uri,
10101041

1011-
[Parameter(Mandatory)]
1042+
[Parameter(
1043+
Mandatory,
1044+
ValueFromPipelineByPropertyName)]
1045+
[Alias('AssetId')]
10121046
[int64] $Asset,
10131047

10141048
[string] $Name,
@@ -1051,7 +1085,7 @@ function Set-GitHubReleaseAsset
10511085
return Invoke-GHRestMethod @params
10521086
}
10531087

1054-
function Remove-GitHubReleaseAsset
1088+
filter Remove-GitHubReleaseAsset
10551089
{
10561090
<#
10571091
.SYNOPSIS
@@ -1089,10 +1123,10 @@ function Remove-GitHubReleaseAsset
10891123
If not supplied here, the DefaultNoStatus configuration property value will be used.
10901124
10911125
.EXAMPLE
1092-
Remove-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Release 1234567890
1126+
Remove-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Asset 1234567890
10931127
10941128
.EXAMPLE
1095-
Remove-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Release 1234567890 -Confirm:$false
1129+
Remove-GitHubReleaseAsset -OwnerName microsoft -RepositoryName PowerShellForGitHub -Asset 1234567890 -Confirm:$false
10961130
10971131
Will not prompt for confirmation, as -Confirm:$false was specified.
10981132
#>
@@ -1111,10 +1145,15 @@ function Remove-GitHubReleaseAsset
11111145

11121146
[Parameter(
11131147
Mandatory,
1148+
ValueFromPipelineByPropertyName,
11141149
ParameterSetName='Uri')]
1150+
[Alias('RepositoryUrl')]
11151151
[string] $Uri,
11161152

1117-
[Parameter(Mandatory)]
1153+
[Parameter(
1154+
Mandatory,
1155+
ValueFromPipelineByPropertyName)]
1156+
[Alias('AssetId')]
11181157
[int64] $Asset,
11191158

11201159
[string] $AccessToken,

0 commit comments

Comments
 (0)