-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete support for Releases API #177
Conversation
82d5455
to
bad95f4
Compare
Ah, glad I saw this. Had begun adapting this to contribute here |
GitHubCore.ps1
Outdated
@@ -130,6 +148,32 @@ function Invoke-GHRestMethod | |||
|
|||
Invoke-UpdateCheck | |||
|
|||
# Minor error checking around $InFile | |||
if ((-not [String]::IsNullOrWhiteSpace($InFile)) -and ($Method -ne 'Post')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for using [string]::IsNullOrWhitespace()
rather than $PSBoundParameter.ContainsKey()
?
My thinking is that a [ValidateNotNullOrEmpty()]
attribute will guarantee that some parameter value is passed, and checking $PSBoundParameters
is a better way to distinguish whether the parameter was set (rather than an empty value being passed in)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. I think my memory had flaked here on whether that could be used successfully on an optional parameter. I just verified that it would work fine. Will change.
function Invoke-NotNull {
[cmdletbinding()]
param(
[ValidateNotNullOrEmpty()]
[string] $Value
)
write-host "[$Value]"
}
Invoke-NotNull
[]
Invoke-NotNull -Value 'foo'
[foo]
Invoke-NotNull -Value $null
Invoke-NotNull : Cannot validate argument on parameter 'Value'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scenario I have specifically in my head is something like:
New-GitHubRelease ... -Label $myLabel
in a case where I forgot to set $myLabel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a case where I forgot to set
$myLabel
There is no Label
for that function, so I'll assume your example was supposed to be -Description $myDescription
.
Ah, so this is where it gets tricky. It's valid to have no description. I consider it a feature that earlier logic in your script might have determined that the description was $null
and now you're just blindly passing it in. We'll take that input and just ignore it because [String]::IsNullOrEmpty
. Is there a more consistent PowerShell philosophy in existing cmdlets where it doesn't work that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so this is where it gets tricky. It's valid to have no description. I consider it a feature that earlier logic in your script might have determined that the description was $null and now you're just blindly passing it in.
Yeah, that's exactly why I'd use [ValidateNotNullOrEmpty()]
on a non-mandatory parameter, to get this behaviour:
> function Test { param([ValidateNotNullOrEmpty()][Parameter()]$x) $x }
> Test
> Test -x $notSet
Test: Cannot validate argument on parameter 'x'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
> Test -x banana
banana
This way, it's perfectly valid to not specify the parameter, but if you do specify it, it shouldn't be the same as not specifying it.
The only issue there is that that means that more automated uses where the parameter is constructed, for example with splatting, have to be slightly more careful, since having a default value of null or empty string will cause a parameter binding failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, point is that it's totally philosophical, but just wanted to make sure it's a deliberate choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only issue there is that that means that more automated uses where the parameter is constructed, for example with splatting, have to be slightly more careful, since having a default value of null or empty string will cause a parameter binding failure.
That's the point I was trying to drive at. It seems like it's a positive feature to allow $null
to be sent in and thus have the parameter ignored. But I'm just a single user, and so I am interested in hearing from others if they feel similarly or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's a totally valid point.
My personal usage, especially of a module like this, is a lot more interactive, and tends to involve something like executing lines that I've already written. But if I get them out of order and it quietly goes ahead, I have to go and fix it on GitHub (perhaps the lesson is that I should use -WhatIf
...).
I don't feel that strongly about it. My real 2 cents are that it's less of a breaking change to turn it from an error into something that works later than to go the other way.
GitHubReleases.ps1
Outdated
$Path = Resolve-UnverifiedPath -Path $Path | ||
$file = Get-Item -Path $Path | ||
$fileName = $file.Name | ||
$fileNameEncoded = [System.Web.HTTPUtility]::UrlEncode($fileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHubReleases.ps1
Outdated
[Parameter(Mandatory)] | ||
[ValidateScript({if (Test-Path -Path $_ -PathType Leaf) { $true } else { throw "$_ does not exist or is inaccessible." }})] | ||
[string] $Path, | ||
|
||
[string] $Label, | ||
|
||
[string] $ContentType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many releases have multiple assets. Given that this is a separate function, this could maybe implement ValueByPipelineProperty
to allow sets of assets to be piped in
Tests/GitHubReleases.tests.ps1
Outdated
$release = New-GitHubRelease -Uri $repo.svn_url -TagName $script:defaultTagName | ||
$queried = Get-GitHubRelease -Uri $repo.svn_url -Release $release.id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think especially with the release of Pester 5, BeforeAll
and AfterAll
are highly recommended, rather than embedding setup and teardown directly in the testing block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pester 5 support is being tracked by #194. Definitely desiring to have that support added. I haven't yet looked into what's involved for that though.
I agree with you that this setup work belongs in BeforeAll
/AfterAll
. At the time, I forgot about those and specifically wanted to avoid BeforeEach
/AfterEach
due to the added time from unnecessary duplicated setup that they would incur. Will look into moving setup/teardown as appropriate.
Thanks.
@rjmholt - Thanks for all the feedback on this. Much appreciated! |
9639e81
to
10cb9aa
Compare
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
52a001a
to
86bba1f
Compare
/azp run PowerShellForGitHub-CI |
… paths on pipeline
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
Description
This completes the required work to support the set of Releases API's.
It adds the following functions:
New-GitHubRelease
Set-GitHubRelease
Remove-GitHubRelease
Get-GitHubReleaseAsset
New-GitHubReleaseAsset
Set-GitHubReleaseAsset
Remove-GitHubReleaseAsset
Invoke-GHRestMethod
has been updated to be able to upload a file (via the newInFile
parameter) and download a file (via theSave
switch which will cause it to return back aFileInfo
object of a temporary file which can then be renamed as seen fit by the caller).This also adds formatters for
GitHub.Release
andGitHub.ReleaseAsset
.Positional Binding has been set as
false
for the three functions, andPosition
attributes added to the function's mandatory parameters.Issues Fixed
Fixes #47
Fixes #110
References
GitHub Releases
Checklist
If desired, ensure your name is added to our Contributors list