Skip to content

Commit 5c04c79

Browse files
committed
Fix up all parameters
1 parent 51661db commit 5c04c79

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

GitHubMilestones.ps1

+14-22
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Get-GitHubMilestone
2929
How to sort the results, either due_on or completeness. Default: due_on
3030
3131
.PARAMETER Direction
32-
How to list the results, either asc or desc. Ignored without the sort parameter.
32+
How to list the results, either asc or desc. Ignored without the sort parameter. Default: asc
3333
3434
.PARAMETER State
3535
Only milestones with this state are returned, either open, closed, or all. Default: open
@@ -70,11 +70,11 @@ function Get-GitHubMilestone
7070
[Parameter(ParameterSetName='RepositoryUri')]
7171
[Parameter(ParameterSetName='RepositoryElements')]
7272
[ValidateSet('open', 'closed', 'all')]
73-
[DateTime] $State,
73+
[string] $State,
7474

7575
[Parameter(ParameterSetName='RepositoryUri')]
7676
[Parameter(ParameterSetName='RepositoryElements')]
77-
[ValidateSet('created', 'updated')]
77+
[ValidateSet('due_on', 'completeness')]
7878
[string] $Sort,
7979

8080
[Parameter(ParameterSetName='RepositoryUri')]
@@ -229,11 +229,6 @@ function New-GitHubMilestone
229229
$OwnerName = $elements.ownerName
230230
$RepositoryName = $elements.repositoryName
231231

232-
if ($null -ne $Due_On)
233-
{
234-
$DueOnFormattedTime = $Due_On.ToUniversalTime().ToString('o')
235-
}
236-
237232
$telemetryProperties = @{
238233
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
239234
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
@@ -246,17 +241,18 @@ function New-GitHubMilestone
246241

247242
if ($PSBoundParameters.ContainsKey('State'))
248243
{
249-
$hashBody += "state=$State"
244+
$hashBody.add('state', $State)
250245
}
251246

252247
if ($PSBoundParameters.ContainsKey('Description'))
253248
{
254-
$hashBody += "description=$Description"
249+
$hashBody.add('description', $Description)
255250
}
256251

257-
if ($PSBoundParameters.ContainsKey('Due_On'))
252+
if ($PSBoundParameters.ContainsKey('Due_On') -and $null -ne $Due_On)
258253
{
259-
$hashBody += "due_on=$DueOnFormattedTime"
254+
$DueOnFormattedTime = $Due_On.ToUniversalTime().ToString('o')
255+
$hashBody.add('due_on', $DueOnFormattedTime)
260256
}
261257

262258
$params = @{
@@ -277,7 +273,7 @@ function Set-GitHubMilestone
277273
{
278274
<#
279275
.DESCRIPTION
280-
Set an existing milestone for the given repository
276+
Update an existing milestone for the given repository
281277
282278
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
283279
@@ -370,11 +366,6 @@ function Set-GitHubMilestone
370366
$OwnerName = $elements.ownerName
371367
$RepositoryName = $elements.repositoryName
372368

373-
if ($null -ne $Due_On)
374-
{
375-
$DueOnFormattedTime = $Due_On.ToUniversalTime().ToString('o')
376-
}
377-
378369
$telemetryProperties = @{
379370
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
380371
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
@@ -388,17 +379,18 @@ function Set-GitHubMilestone
388379

389380
if ($PSBoundParameters.ContainsKey('State'))
390381
{
391-
$hashBody += "state=$State"
382+
$hashBody.add('state', $State)
392383
}
393384

394385
if ($PSBoundParameters.ContainsKey('Description'))
395386
{
396-
$hashBody += "description=$Description"
387+
$hashBody.add('description', $Description)
397388
}
398389

399-
if ($PSBoundParameters.ContainsKey('Due_On'))
390+
if ($PSBoundParameters.ContainsKey('Due_On') -and $null -ne $Due_On)
400391
{
401-
$hashBody += "due_on=$DueOnFormattedTime"
392+
$DueOnFormattedTime = $Due_On.ToUniversalTime().ToString('o')
393+
$hashBody.add('due_on', $DueOnFormattedTime)
402394
}
403395

404396
$params = @{

Tests/GitHubMilestones.tests.ps1

+19-6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ try
8282
defaultMilestoneTitle1 = "This is a test milestone title #1."
8383
defaultMilestoneTitle2 = "This is a test milestone title #2."
8484
defaultEditedMilestoneTitle = "This is an edited milestone title."
85+
defaultMilestoneDescription = "This is a test milestone description."
86+
defaultEditedMilestoneDescription = "This is an edited milestone description."
87+
defaultMilestoneDueOn = Get-Date -Date "2023-10-09T00:00:00"
8588
}.GetEnumerator() | ForEach-Object {
8689
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
8790
}
@@ -90,16 +93,24 @@ try
9093
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
9194

9295
Context 'For creating a new milestone' {
93-
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle1
96+
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle1 -State "closed" -Due_On $defaultMilestoneDueOn
9497
$existingMilestone = Get-GitHubMilestone -Uri $repo.svn_url -MilestoneNumber $newMilestone.number
9598

9699
It "Should have the expected title text" {
97100
$existingMilestone.title | Should be $defaultMilestoneTitle1
98101
}
102+
103+
It "Should have the expected state" {
104+
$existingMilestone.state | Should be "closed"
105+
}
106+
107+
It "Should have the expected due_on date" {
108+
Get-Date -Date $existingMilestone.due_on | Should be $defaultMilestoneDueOn
109+
}
99110
}
100111

101112
Context 'For getting milestones from a repo' {
102-
$existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url)
113+
$existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State "closed")
103114

104115
It 'Should have the expected number of milestones' {
105116
$existingMilestones.Count | Should be 1
@@ -111,20 +122,22 @@ try
111122
}
112123

113124
Context 'For editing a milestone' {
114-
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle2
115-
$editedMilestone = Set-GitHubMilestone -Uri $repo.svn_url -MilestoneNumber $newMilestone.number -Title $defaultEditedMilestoneTitle
125+
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle2 -Description $defaultMilestoneDescription
126+
$editedMilestone = Set-GitHubMilestone -Uri $repo.svn_url -MilestoneNumber $newMilestone.number -Title $defaultEditedMilestoneTitle -Description $defaultEditedMilestoneDescription
116127

117-
It 'Should have a title that is not equal to the original title' {
128+
It 'Should have a title/description that is not equal to the original title/description' {
118129
$editedMilestone.title | Should not be $newMilestone.title
130+
$editedMilestone.description | Should not be $newMilestone.description
119131
}
120132

121133
It 'Should have the edited content' {
122134
$editedMilestone.title | Should be $defaultEditedMilestoneTitle
135+
$editedMilestone.description | Should be $defaultEditedMilestoneDescription
123136
}
124137
}
125138

126139
Context 'For getting milestones from a repository and deleting them' {
127-
$existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url)
140+
$existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State "all" -Sort "completeness" -Direction "desc")
128141

129142
It 'Should have the expected number of milestones' {
130143
$existingMilestones.Count | Should be 2

0 commit comments

Comments
 (0)