Skip to content

Commit 51661db

Browse files
committed
Fix up tests and API
1 parent 7ff7d0c commit 51661db

File tree

2 files changed

+53
-18
lines changed

2 files changed

+53
-18
lines changed

GitHubMilestones.ps1

+47-13
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ function New-GitHubMilestone
207207

208208
[Parameter(ParameterSetName='Uri')]
209209
[Parameter(ParameterSetName='Elements')]
210+
[ValidateSet('open', 'closed')]
210211
[string] $State,
211212

212213
[Parameter(ParameterSetName='Uri')]
@@ -215,7 +216,7 @@ function New-GitHubMilestone
215216

216217
[Parameter(ParameterSetName='Uri')]
217218
[Parameter(ParameterSetName='Elements')]
218-
[string] $Due_On,
219+
[DateTime] $Due_On,
219220

220221
[string] $AccessToken,
221222

@@ -230,7 +231,7 @@ function New-GitHubMilestone
230231

231232
if ($null -ne $Due_On)
232233
{
233-
$DueOnFormattedTime = $Since.ToUniversalTime().ToString('o')
234+
$DueOnFormattedTime = $Due_On.ToUniversalTime().ToString('o')
234235
}
235236

236237
$telemetryProperties = @{
@@ -241,9 +242,21 @@ function New-GitHubMilestone
241242

242243
$hashBody = @{
243244
'title' = $Title
244-
'state' = $State
245-
'description' = $Description
246-
'due_on' = $DueOnFormattedTime
245+
}
246+
247+
if ($PSBoundParameters.ContainsKey('State'))
248+
{
249+
$hashBody += "state=$State"
250+
}
251+
252+
if ($PSBoundParameters.ContainsKey('Description'))
253+
{
254+
$hashBody += "description=$Description"
255+
}
256+
257+
if ($PSBoundParameters.ContainsKey('Due_On'))
258+
{
259+
$hashBody += "due_on=$DueOnFormattedTime"
247260
}
248261

249262
$params = @{
@@ -281,6 +294,9 @@ function Set-GitHubMilestone
281294
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
282295
them individually.
283296
297+
.PARAMETER MilestoneNumber
298+
The number of a specific milestone to get.
299+
284300
.PARAMETER Title
285301
The title of the milestone.
286302
@@ -304,7 +320,7 @@ function Set-GitHubMilestone
304320
If not supplied here, the DefaultNoStatus configuration property value will be used.
305321
306322
.EXAMPLE
307-
Set-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Title "Testing this API"
323+
Set-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -MilestoneNumber 1 -Title "Testing this API"
308324
309325
Update an existing milestone for the PowerShell\PowerShellForGitHub project.
310326
#>
@@ -322,12 +338,17 @@ function Set-GitHubMilestone
322338
[Parameter(Mandatory, ParameterSetName='Uri')]
323339
[string] $Uri,
324340

341+
[Parameter(Mandatory, ParameterSetName='Uri')]
342+
[Parameter(Mandatory, ParameterSetName='Elements')]
343+
[string] $MilestoneNumber,
344+
325345
[Parameter(Mandatory, ParameterSetName='Uri')]
326346
[Parameter(Mandatory, ParameterSetName='Elements')]
327347
[string] $Title,
328348

329349
[Parameter(ParameterSetName='Uri')]
330350
[Parameter(ParameterSetName='Elements')]
351+
[ValidateSet('open', 'closed')]
331352
[string] $State,
332353

333354
[Parameter(ParameterSetName='Uri')]
@@ -336,7 +357,7 @@ function Set-GitHubMilestone
336357

337358
[Parameter(ParameterSetName='Uri')]
338359
[Parameter(ParameterSetName='Elements')]
339-
[string] $Due_On,
360+
[DateTime] $Due_On,
340361

341362
[string] $AccessToken,
342363

@@ -351,27 +372,40 @@ function Set-GitHubMilestone
351372

352373
if ($null -ne $Due_On)
353374
{
354-
$DueOnFormattedTime = $Since.ToUniversalTime().ToString('o')
375+
$DueOnFormattedTime = $Due_On.ToUniversalTime().ToString('o')
355376
}
356377

357378
$telemetryProperties = @{
358379
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
359380
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
360381
'Title' = (Get-PiiSafeString -PlainText $Title)
382+
'MilestoneNumber' = (Get-PiiSafeString -PlainText $MilestoneNumber)
361383
}
362384

363385
$hashBody = @{
364386
'title' = $Title
365-
'state' = $State
366-
'description' = $Description
367-
'due_on' = $DueOnFormattedTime
387+
}
388+
389+
if ($PSBoundParameters.ContainsKey('State'))
390+
{
391+
$hashBody += "state=$State"
392+
}
393+
394+
if ($PSBoundParameters.ContainsKey('Description'))
395+
{
396+
$hashBody += "description=$Description"
397+
}
398+
399+
if ($PSBoundParameters.ContainsKey('Due_On'))
400+
{
401+
$hashBody += "due_on=$DueOnFormattedTime"
368402
}
369403

370404
$params = @{
371-
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones"
405+
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$MilestoneNumber"
372406
'Body' = (ConvertTo-Json -InputObject $hashBody)
373407
'Method' = 'Patch'
374-
'Description' = "Creating milestone for $RepositoryName"
408+
'Description' = "Setting milestone $MilestoneNumber for $RepositoryName"
375409
'AccessToken' = $AccessToken
376410
'TelemetryEventName' = $MyInvocation.MyCommand.Name
377411
'TelemetryProperties' = $telemetryProperties

Tests/GitHubMilestones.tests.ps1

+6-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ try
7979
# Define Script-scoped, readonly, hidden variables.
8080

8181
@{
82-
defaultMilestoneTitle = "This is a test milestone title."
82+
defaultMilestoneTitle1 = "This is a test milestone title #1."
83+
defaultMilestoneTitle2 = "This is a test milestone title #2."
8384
defaultEditedMilestoneTitle = "This is an edited milestone title."
8485
}.GetEnumerator() | ForEach-Object {
8586
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
@@ -89,11 +90,11 @@ try
8990
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
9091

9192
Context 'For creating a new milestone' {
92-
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle
93+
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle1
9394
$existingMilestone = Get-GitHubMilestone -Uri $repo.svn_url -MilestoneNumber $newMilestone.number
9495

9596
It "Should have the expected title text" {
96-
$existingMilestone.title | Should be $defaultMilestoneTitle
97+
$existingMilestone.title | Should be $defaultMilestoneTitle1
9798
}
9899
}
99100

@@ -105,12 +106,12 @@ try
105106
}
106107

107108
It 'Should have the expected body text on the first milestone' {
108-
$existingMilestones[0].title | Should be $defaultMilestoneTitle
109+
$existingMilestones[0].title | Should be $defaultMilestoneTitle1
109110
}
110111
}
111112

112113
Context 'For editing a milestone' {
113-
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle
114+
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle2
114115
$editedMilestone = Set-GitHubMilestone -Uri $repo.svn_url -MilestoneNumber $newMilestone.number -Title $defaultEditedMilestoneTitle
115116

116117
It 'Should have a title that is not equal to the original title' {

0 commit comments

Comments
 (0)