Add support for milestones (#62)
Added support for the [Milestone](https://developer.github.com/v3/issues/milestones/) API's for GitHub Issues.
This commit is contained in:
Родитель
cd175712e6
Коммит
2bd244768d
|
@ -29,10 +29,10 @@ function Get-GitHubComment
|
|||
Issue number to get comments for. If not supplied, will return back all comments for this repository.
|
||||
|
||||
.PARAMETER Sort
|
||||
How to sort the results, either created or updated. Default: created
|
||||
How to sort the results.
|
||||
|
||||
.PARAMETER Direction
|
||||
How to list the results, either asc or desc. Ignored without the sort parameter.
|
||||
How to list the results. Ignored without the sort parameter.
|
||||
|
||||
.PARAMETER Since
|
||||
Only comments updated at or after this time are returned.
|
||||
|
@ -117,6 +117,8 @@ function Get-GitHubComment
|
|||
$elements = Resolve-RepositoryElements
|
||||
$OwnerName = $elements.ownerName
|
||||
$RepositoryName = $elements.repositoryName
|
||||
$uriFragment = [String]::Empty
|
||||
$description = [String]::Empty
|
||||
|
||||
if ($null -ne $Since)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,509 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
function Get-GitHubMilestone
|
||||
{
|
||||
<#
|
||||
.DESCRIPTION
|
||||
Get the milestones for a given Github repository.
|
||||
|
||||
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
||||
|
||||
.PARAMETER OwnerName
|
||||
Owner of the repository.
|
||||
If not supplied here, the DefaultOwnerName configuration property value will be used.
|
||||
|
||||
.PARAMETER RepositoryName
|
||||
Name of the repository.
|
||||
If not supplied here, the DefaultRepositoryName configuration property value will be used.
|
||||
|
||||
.PARAMETER Uri
|
||||
Uri for the repository.
|
||||
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
|
||||
them individually.
|
||||
|
||||
.PARAMETER Milestone
|
||||
The number of a specific milestone to get. If not supplied, will return back all milestones for this repository.
|
||||
|
||||
.PARAMETER Sort
|
||||
How to sort the results.
|
||||
|
||||
.PARAMETER Direction
|
||||
How to list the results. Ignored without the sort parameter.
|
||||
|
||||
.PARAMETER State
|
||||
Only milestones with this state are returned.
|
||||
|
||||
.PARAMETER AccessToken
|
||||
If provided, this will be used as the AccessToken for authentication with the
|
||||
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
|
||||
|
||||
.PARAMETER NoStatus
|
||||
If this switch is specified, long-running commands will run on the main thread
|
||||
with no commandline status update. When not specified, those commands run in
|
||||
the background, enabling the command prompt to provide status information.
|
||||
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
||||
|
||||
.EXAMPLE
|
||||
Get-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub
|
||||
Get the milestones for the PowerShell\PowerShellForGitHub project.
|
||||
|
||||
.EXAMPLE
|
||||
Get-GitHubMilestone -Uri 'https://github.com/PowerShell/PowerShellForGitHub' -Milestone 1
|
||||
Get milestone number 1 for the PowerShell\PowerShellForGitHub project.
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess,
|
||||
DefaultParametersetName='RepositoryElements')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
||||
param(
|
||||
[Parameter(Mandatory, ParameterSetName='MilestoneElements')]
|
||||
[Parameter(Mandatory, ParameterSetName='RepositoryElements')]
|
||||
[string] $OwnerName,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='MilestoneElements')]
|
||||
[Parameter(Mandatory, ParameterSetName='RepositoryElements')]
|
||||
[string] $RepositoryName,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='MilestoneUri')]
|
||||
[Parameter(Mandatory, ParameterSetName='RepositoryUri')]
|
||||
[string] $Uri,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='MilestoneUri')]
|
||||
[Parameter(Mandatory, ParameterSetName='MilestoneElements')]
|
||||
[int] $Milestone,
|
||||
|
||||
[Parameter(ParameterSetName='RepositoryUri')]
|
||||
[Parameter(ParameterSetName='RepositoryElements')]
|
||||
[ValidateSet('Open', 'Closed', 'All')]
|
||||
[string] $State,
|
||||
|
||||
[Parameter(ParameterSetName='RepositoryUri')]
|
||||
[Parameter(ParameterSetName='RepositoryElements')]
|
||||
[ValidateSet('DueOn', 'Completeness')]
|
||||
[string] $Sort,
|
||||
|
||||
[Parameter(ParameterSetName='RepositoryUri')]
|
||||
[Parameter(ParameterSetName='RepositoryElements')]
|
||||
[ValidateSet('Ascending', 'Descending')]
|
||||
[string] $Direction,
|
||||
|
||||
[string] $AccessToken,
|
||||
|
||||
[switch] $NoStatus
|
||||
)
|
||||
|
||||
Write-InvocationLog
|
||||
|
||||
$elements = Resolve-RepositoryElements
|
||||
$OwnerName = $elements.ownerName
|
||||
$RepositoryName = $elements.repositoryName
|
||||
$uriFragment = [String]::Empty
|
||||
$description = [String]::Empty
|
||||
|
||||
$telemetryProperties = @{
|
||||
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
|
||||
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
|
||||
'ProvidedMilestone' = $PSBoundParameters.ContainsKey('Milestone')
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Milestone'))
|
||||
{
|
||||
$uriFragment = "repos/$OwnerName/$RepositoryName/milestones/$Milestone"
|
||||
$description = "Getting milestone $Milestone for $RepositoryName"
|
||||
}
|
||||
else
|
||||
{
|
||||
$getParams = @()
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Sort'))
|
||||
{
|
||||
if ($Sort -eq "Completeness")
|
||||
{
|
||||
$getParams += "sort=completeness"
|
||||
}
|
||||
elseif ($Sort -eq "DueOn")
|
||||
{
|
||||
$getParams += "sort=due_on"
|
||||
}
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Direction'))
|
||||
{
|
||||
if ($Direction -eq "Ascending")
|
||||
{
|
||||
$getParams += "direction=asc"
|
||||
}
|
||||
elseif ($Direction -eq "Descending")
|
||||
{
|
||||
$getParams += "direction=desc"
|
||||
}
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('State'))
|
||||
{
|
||||
$State = $State.ToLower()
|
||||
$getParams += "state=$State"
|
||||
}
|
||||
|
||||
$uriFragment = "repos/$OwnerName/$RepositoryName/milestones`?" + ($getParams -join '&')
|
||||
$description = "Getting milestones for $RepositoryName"
|
||||
}
|
||||
|
||||
$params = @{
|
||||
'UriFragment' = $uriFragment
|
||||
'Description' = $description
|
||||
'AccessToken' = $AccessToken
|
||||
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
||||
'TelemetryProperties' = $telemetryProperties
|
||||
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
||||
}
|
||||
|
||||
return Invoke-GHRestMethodMultipleResult @params
|
||||
}
|
||||
|
||||
function New-GitHubMilestone
|
||||
{
|
||||
<#
|
||||
.DESCRIPTION
|
||||
Creates a new Github milestone for the given repository
|
||||
|
||||
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
||||
|
||||
.PARAMETER OwnerName
|
||||
Owner of the repository.
|
||||
If not supplied here, the DefaultOwnerName configuration property value will be used.
|
||||
|
||||
.PARAMETER RepositoryName
|
||||
Name of the repository.
|
||||
If not supplied here, the DefaultRepositoryName configuration property value will be used.
|
||||
|
||||
.PARAMETER Uri
|
||||
Uri for the repository.
|
||||
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
|
||||
them individually.
|
||||
|
||||
.PARAMETER Title
|
||||
The title of the milestone.
|
||||
|
||||
.PARAMETER State
|
||||
The state of the milestone.
|
||||
|
||||
.PARAMETER Description
|
||||
A description of the milestone.
|
||||
|
||||
.PARAMETER DueOn
|
||||
The milestone due date.
|
||||
|
||||
.PARAMETER AccessToken
|
||||
If provided, this will be used as the AccessToken for authentication with the
|
||||
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
|
||||
|
||||
.PARAMETER NoStatus
|
||||
If this switch is specified, long-running commands will run on the main thread
|
||||
with no commandline status update. When not specified, those commands run in
|
||||
the background, enabling the command prompt to provide status information.
|
||||
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
||||
|
||||
.EXAMPLE
|
||||
New-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Title "Testing this API"
|
||||
|
||||
Creates a new Github milestone for the PowerShell\PowerShellForGitHub project.
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess,
|
||||
DefaultParametersetName='Elements')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
||||
param(
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $OwnerName,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $RepositoryName,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Uri')]
|
||||
[string] $Uri,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Uri')]
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $Title,
|
||||
|
||||
[ValidateSet('Open', 'Closed')]
|
||||
[string] $State,
|
||||
|
||||
[string] $Description,
|
||||
|
||||
[DateTime] $DueOn,
|
||||
|
||||
[string] $AccessToken,
|
||||
|
||||
[switch] $NoStatus
|
||||
)
|
||||
|
||||
Write-InvocationLog
|
||||
|
||||
$elements = Resolve-RepositoryElements
|
||||
$OwnerName = $elements.ownerName
|
||||
$RepositoryName = $elements.repositoryName
|
||||
|
||||
$telemetryProperties = @{
|
||||
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
|
||||
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
|
||||
'Title' = (Get-PiiSafeString -PlainText $Title)
|
||||
}
|
||||
|
||||
$hashBody = @{
|
||||
'title' = $Title
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('State'))
|
||||
{
|
||||
$State = $State.ToLower()
|
||||
$hashBody.add('state', $State)
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Description'))
|
||||
{
|
||||
$hashBody.add('description', $Description)
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('DueOn'))
|
||||
{
|
||||
$DueOnFormattedTime = $DueOn.ToUniversalTime().ToString('o')
|
||||
$hashBody.add('due_on', $DueOnFormattedTime)
|
||||
}
|
||||
|
||||
$params = @{
|
||||
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones"
|
||||
'Body' = (ConvertTo-Json -InputObject $hashBody)
|
||||
'Method' = 'Post'
|
||||
'Description' = "Creating milestone for $RepositoryName"
|
||||
'AccessToken' = $AccessToken
|
||||
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
||||
'TelemetryProperties' = $telemetryProperties
|
||||
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
||||
}
|
||||
|
||||
return Invoke-GHRestMethod @params
|
||||
}
|
||||
|
||||
function Set-GitHubMilestone
|
||||
{
|
||||
<#
|
||||
.DESCRIPTION
|
||||
Update an existing milestone for the given repository
|
||||
|
||||
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
||||
|
||||
.PARAMETER OwnerName
|
||||
Owner of the repository.
|
||||
If not supplied here, the DefaultOwnerName configuration property value will be used.
|
||||
|
||||
.PARAMETER RepositoryName
|
||||
Name of the repository.
|
||||
If not supplied here, the DefaultRepositoryName configuration property value will be used.
|
||||
|
||||
.PARAMETER Uri
|
||||
Uri for the repository.
|
||||
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
|
||||
them individually.
|
||||
|
||||
.PARAMETER Milestone
|
||||
The number of a specific milestone to get.
|
||||
|
||||
.PARAMETER Title
|
||||
The title of the milestone.
|
||||
|
||||
.PARAMETER State
|
||||
The state of the milestone.
|
||||
|
||||
.PARAMETER Description
|
||||
A description of the milestone.
|
||||
|
||||
.PARAMETER DueOn
|
||||
The milestone due date.
|
||||
|
||||
.PARAMETER AccessToken
|
||||
If provided, this will be used as the AccessToken for authentication with the
|
||||
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
|
||||
|
||||
.PARAMETER NoStatus
|
||||
If this switch is specified, long-running commands will run on the main thread
|
||||
with no commandline status update. When not specified, those commands run in
|
||||
the background, enabling the command prompt to provide status information.
|
||||
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
||||
|
||||
.EXAMPLE
|
||||
Set-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API"
|
||||
|
||||
Update an existing milestone for the PowerShell\PowerShellForGitHub project.
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess,
|
||||
DefaultParametersetName='Elements')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
||||
param(
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $OwnerName,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $RepositoryName,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Uri')]
|
||||
[string] $Uri,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Uri')]
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[int] $Milestone,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Uri')]
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $Title,
|
||||
|
||||
[ValidateSet('Open', 'Closed')]
|
||||
[string] $State,
|
||||
|
||||
[string] $Description,
|
||||
|
||||
[DateTime] $DueOn,
|
||||
|
||||
[string] $AccessToken,
|
||||
|
||||
[switch] $NoStatus
|
||||
)
|
||||
|
||||
Write-InvocationLog
|
||||
|
||||
$elements = Resolve-RepositoryElements
|
||||
$OwnerName = $elements.ownerName
|
||||
$RepositoryName = $elements.repositoryName
|
||||
|
||||
$telemetryProperties = @{
|
||||
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
|
||||
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
|
||||
'Title' = (Get-PiiSafeString -PlainText $Title)
|
||||
'Milestone' = (Get-PiiSafeString -PlainText $Milestone)
|
||||
}
|
||||
|
||||
$hashBody = @{
|
||||
'title' = $Title
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('State'))
|
||||
{
|
||||
$State = $State.ToLower()
|
||||
$hashBody.add('state', $State)
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('Description'))
|
||||
{
|
||||
$hashBody.add('description', $Description)
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('DueOn'))
|
||||
{
|
||||
$DueOnFormattedTime = $DueOn.ToUniversalTime().ToString('o')
|
||||
$hashBody.add('due_on', $DueOnFormattedTime)
|
||||
}
|
||||
|
||||
$params = @{
|
||||
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone"
|
||||
'Body' = (ConvertTo-Json -InputObject $hashBody)
|
||||
'Method' = 'Patch'
|
||||
'Description' = "Setting milestone $Milestone for $RepositoryName"
|
||||
'AccessToken' = $AccessToken
|
||||
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
||||
'TelemetryProperties' = $telemetryProperties
|
||||
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
||||
}
|
||||
|
||||
return Invoke-GHRestMethod @params
|
||||
}
|
||||
|
||||
function Remove-GitHubMilestone
|
||||
{
|
||||
<#
|
||||
.DESCRIPTION
|
||||
Deletes a Github milestone for the given repository
|
||||
|
||||
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
||||
|
||||
.PARAMETER OwnerName
|
||||
Owner of the repository.
|
||||
If not supplied here, the DefaultOwnerName configuration property value will be used.
|
||||
|
||||
.PARAMETER RepositoryName
|
||||
Name of the repository.
|
||||
If not supplied here, the DefaultRepositoryName configuration property value will be used.
|
||||
|
||||
.PARAMETER Uri
|
||||
Uri for the repository.
|
||||
The OwnerName and RepositoryName will be extracted from here instead of needing to provide
|
||||
them individually.
|
||||
|
||||
.PARAMETER Milestone
|
||||
The number of a specific milestone to delete.
|
||||
|
||||
.PARAMETER AccessToken
|
||||
If provided, this will be used as the AccessToken for authentication with the
|
||||
REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
|
||||
|
||||
.PARAMETER NoStatus
|
||||
If this switch is specified, long-running commands will run on the main thread
|
||||
with no commandline status update. When not specified, those commands run in
|
||||
the background, enabling the command prompt to provide status information.
|
||||
If not supplied here, the DefaultNoStatus configuration property value will be used.
|
||||
|
||||
.EXAMPLE
|
||||
Remove-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Milestone 1
|
||||
|
||||
Deletes a Github milestone from the PowerShell\PowerShellForGitHub project.
|
||||
#>
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess,
|
||||
DefaultParametersetName='Elements')]
|
||||
[Alias('Delete-GitHubMilestone')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
|
||||
param(
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $OwnerName,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $RepositoryName,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Uri')]
|
||||
[string] $Uri,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName='Uri')]
|
||||
[Parameter(Mandatory, ParameterSetName='Elements')]
|
||||
[string] $Milestone,
|
||||
|
||||
[string] $AccessToken,
|
||||
|
||||
[switch] $NoStatus
|
||||
)
|
||||
|
||||
Write-InvocationLog
|
||||
|
||||
$elements = Resolve-RepositoryElements
|
||||
$OwnerName = $elements.ownerName
|
||||
$RepositoryName = $elements.repositoryName
|
||||
|
||||
$telemetryProperties = @{
|
||||
'OwnerName' = (Get-PiiSafeString -PlainText $OwnerName)
|
||||
'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName)
|
||||
'Milestone' = (Get-PiiSafeString -PlainText $Milestone)
|
||||
}
|
||||
|
||||
$params = @{
|
||||
'UriFragment' = "repos/$OwnerName/$RepositoryName/milestones/$Milestone"
|
||||
'Method' = 'Delete'
|
||||
'Description' = "Removing milestone $Milestone for $RepositoryName"
|
||||
'AccessToken' = $AccessToken
|
||||
'TelemetryEventName' = $MyInvocation.MyCommand.Name
|
||||
'TelemetryProperties' = $telemetryProperties
|
||||
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
|
||||
}
|
||||
|
||||
return Invoke-GHRestMethod @params
|
||||
}
|
|
@ -27,6 +27,7 @@
|
|||
'GitHubEvents.ps1',
|
||||
'GitHubIssues.ps1',
|
||||
'GitHubLabels.ps1',
|
||||
'GitHubMilestones.ps1',
|
||||
'GitHubMiscellaneous.ps1',
|
||||
'GitHubOrganizations.ps1',
|
||||
'GitHubPullRequests.ps1',
|
||||
|
@ -58,6 +59,7 @@
|
|||
'Get-GitHubIssueTimeline',
|
||||
'Get-GitHubLabel',
|
||||
'Get-GitHubLicense',
|
||||
'Get-GitHubMilestone',
|
||||
'Get-GitHubOrganizationMember',
|
||||
'Get-GitHubPathTraffic',
|
||||
'Get-GitHubPullRequest',
|
||||
|
@ -86,11 +88,13 @@
|
|||
'New-GitHubComment',
|
||||
'New-GitHubIssue',
|
||||
'New-GitHubLabel',
|
||||
'New-GitHubMilestone',
|
||||
'New-GitHubRepository',
|
||||
'New-GitHubRepositoryFork',
|
||||
'Remove-GithubAssignee',
|
||||
'Remove-GitHubComment',
|
||||
'Remove-GitHubLabel',
|
||||
'Remove-GitHubMilestone',
|
||||
'Remove-GitHubRepository',
|
||||
'Reset-GitHubConfiguration',
|
||||
'Restore-GitHubConfiguration',
|
||||
|
@ -98,6 +102,7 @@
|
|||
'Set-GitHubComment',
|
||||
'Set-GitHubConfiguration',
|
||||
'Set-GitHubLabel',
|
||||
'Set-GitHubMilestone',
|
||||
'Set-GitHubRepositoryTopic',
|
||||
'Split-GitHubUri',
|
||||
'Test-GitHubAssignee',
|
||||
|
@ -112,6 +117,7 @@
|
|||
AliasesToExport = @(
|
||||
'Delete-GitHubComment',
|
||||
'Delete-GitHubLabel',
|
||||
'Delete-GitHubMilestone',
|
||||
'Delete-GitHubRepository',
|
||||
'Get-GitHubBranch',
|
||||
'Transfer-GitHubRepositoryOwnership'
|
||||
|
|
|
@ -0,0 +1,178 @@
|
|||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Tests for GitHubMilestones.ps1 module
|
||||
#>
|
||||
|
||||
$root = Split-Path -Parent $PSScriptRoot
|
||||
. (Join-Path -Path $root -ChildPath 'Tests\Config\Settings.ps1')
|
||||
Import-Module -Name $root -Force
|
||||
|
||||
function Initialize-AppVeyor
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Configures the tests to run with the authentication information stored in AppVeyor
|
||||
(if that information exists in the environment).
|
||||
|
||||
.DESCRIPTION
|
||||
Configures the tests to run with the authentication information stored in AppVeyor
|
||||
(if that information exists in the environment).
|
||||
|
||||
The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub
|
||||
|
||||
.NOTES
|
||||
Internal-only helper method.
|
||||
|
||||
The only reason this exists is so that we can leverage CodeAnalysis.SuppressMessageAttribute,
|
||||
which can only be applied to functions.
|
||||
|
||||
We call this immediately after the declaration so that AppVeyor initialization can happen
|
||||
(if applicable).
|
||||
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "", Justification="Needed to configure with the stored, encrypted string value in AppVeyor.")]
|
||||
param()
|
||||
|
||||
if ($env:AppVeyor)
|
||||
{
|
||||
$secureString = $env:avAccessToken | ConvertTo-SecureString -AsPlainText -Force
|
||||
$cred = New-Object System.Management.Automation.PSCredential "<username is ignored>", $secureString
|
||||
Set-GitHubAuthentication -Credential $cred
|
||||
|
||||
$script:ownerName = $env:avOwnerName
|
||||
$script:organizationName = $env:avOrganizationName
|
||||
|
||||
$message = @(
|
||||
'This run is executed in the AppVeyor environment.',
|
||||
'The GitHub Api Token won''t be decrypted in PR runs causing some tests to fail.',
|
||||
'403 errors possible due to GitHub hourly limit for unauthenticated queries.',
|
||||
'Use Set-GitHubAuthentication manually. modify the values in Tests\Config\Settings.ps1,',
|
||||
'and run tests on your machine first.')
|
||||
Write-Warning -Message ($message -join [Environment]::NewLine)
|
||||
}
|
||||
}
|
||||
|
||||
Initialize-AppVeyor
|
||||
|
||||
$script:accessTokenConfigured = Test-GitHubAuthenticationConfigured
|
||||
if (-not $script:accessTokenConfigured)
|
||||
{
|
||||
$message = @(
|
||||
'GitHub API Token not defined, some of the tests will be skipped.',
|
||||
'403 errors possible due to GitHub hourly limit for unauthenticated queries.')
|
||||
Write-Warning -Message ($message -join [Environment]::NewLine)
|
||||
}
|
||||
|
||||
# Backup the user's configuration before we begin, and ensure we're at a pure state before running
|
||||
# the tests. We'll restore it at the end.
|
||||
$configFile = New-TemporaryFile
|
||||
try
|
||||
{
|
||||
Backup-GitHubConfiguration -Path $configFile
|
||||
Reset-GitHubConfiguration
|
||||
Set-GitHubConfiguration -DisableTelemetry # We don't want UT's to impact telemetry
|
||||
|
||||
# Define Script-scoped, readonly, hidden variables.
|
||||
|
||||
@{
|
||||
defaultIssueTitle = "This is a test issue."
|
||||
defaultMilestoneTitle1 = "This is a test milestone title #1."
|
||||
defaultMilestoneTitle2 = "This is a test milestone title #2."
|
||||
defaultEditedMilestoneTitle = "This is an edited milestone title."
|
||||
defaultMilestoneDescription = "This is a test milestone description."
|
||||
defaultEditedMilestoneDescription = "This is an edited milestone description."
|
||||
defaultMilestoneDueOn = (Get-Date).AddYears(1).Date
|
||||
}.GetEnumerator() | ForEach-Object {
|
||||
Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value
|
||||
}
|
||||
|
||||
Describe 'Creating, modifying and deleting milestones' {
|
||||
$repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit
|
||||
$issue = New-GitHubIssue -Uri $repo.svn_url -Title $defaultIssueTitle
|
||||
|
||||
Context 'For creating a new milestone' {
|
||||
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle1 -State "Closed" -DueOn $defaultMilestoneDueOn
|
||||
$existingMilestone = Get-GitHubMilestone -Uri $repo.svn_url -Milestone $newMilestone.number
|
||||
|
||||
It "Should have the expected title text" {
|
||||
$existingMilestone.title | Should be $defaultMilestoneTitle1
|
||||
}
|
||||
|
||||
It "Should have the expected state" {
|
||||
$existingMilestone.state | Should be "closed"
|
||||
}
|
||||
|
||||
It "Should have the expected due_on date" {
|
||||
Get-Date -Date $existingMilestone.due_on | Should be $defaultMilestoneDueOn
|
||||
}
|
||||
|
||||
It "Should allow the addition of an existing issue" {
|
||||
Update-GitHubIssue -Uri $repo.svn_url -Issue $issue.number -Milestone $existingMilestone.number
|
||||
}
|
||||
}
|
||||
|
||||
Context 'For getting milestones from a repo' {
|
||||
$existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State "Closed")
|
||||
$issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number
|
||||
|
||||
It 'Should have the expected number of milestones' {
|
||||
$existingMilestones.Count | Should be 1
|
||||
}
|
||||
|
||||
It 'Should have the expected title text on the first milestone' {
|
||||
$existingMilestones[0].title | Should be $defaultMilestoneTitle1
|
||||
}
|
||||
|
||||
It 'Should have the expected issue in the first milestone' {
|
||||
$existingMilestones[0].open_issues | should be 1
|
||||
$issue.milestone.number | Should be 1
|
||||
}
|
||||
}
|
||||
|
||||
Context 'For editing a milestone' {
|
||||
$newMilestone = New-GitHubMilestone -Uri $repo.svn_url -Title $defaultMilestoneTitle2 -Description $defaultMilestoneDescription
|
||||
$editedMilestone = Set-GitHubMilestone -Uri $repo.svn_url -Milestone $newMilestone.number -Title $defaultEditedMilestoneTitle -Description $defaultEditedMilestoneDescription
|
||||
|
||||
It 'Should have a title/description that is not equal to the original title/description' {
|
||||
$editedMilestone.title | Should not be $newMilestone.title
|
||||
$editedMilestone.description | Should not be $newMilestone.description
|
||||
}
|
||||
|
||||
It 'Should have the edited content' {
|
||||
$editedMilestone.title | Should be $defaultEditedMilestoneTitle
|
||||
$editedMilestone.description | Should be $defaultEditedMilestoneDescription
|
||||
}
|
||||
}
|
||||
|
||||
Context 'For getting milestones from a repository and deleting them' {
|
||||
$existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url -State "All" -Sort "Completeness" -Direction "Descending")
|
||||
|
||||
It 'Should have the expected number of milestones' {
|
||||
$existingMilestones.Count | Should be 2
|
||||
}
|
||||
|
||||
foreach($milestone in $existingMilestones) {
|
||||
Remove-GitHubMilestone -Uri $repo.svn_url -Milestone $milestone.number
|
||||
}
|
||||
|
||||
$existingMilestones = @(Get-GitHubMilestone -Uri $repo.svn_url)
|
||||
$issue = Get-GitHubIssue -Uri $repo.svn_url -Issue $issue.number
|
||||
|
||||
It 'Should have no milestones' {
|
||||
$existingMilestones.Count | Should be 0
|
||||
$issue.milestone | Should be $null
|
||||
}
|
||||
}
|
||||
|
||||
Remove-GitHubRepository -Uri $repo.svn_url
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
# Restore the user's configuration to its pre-test state
|
||||
Restore-GitHubConfiguration -Path $configFile
|
||||
}
|
37
USAGE.md
37
USAGE.md
|
@ -42,10 +42,17 @@
|
|||
* [Adding a new comment to an issue](#adding-a-new-comment-to-an-issue)
|
||||
* [Editing an existing comment](#editing-an-existing-comment)
|
||||
* [Removing a comment](#removing-a-comment)
|
||||
* [Milestones](#milestones)
|
||||
* [Get milestones from a repository](#get-milestones-from-a-repository)
|
||||
* [Get a single milestone](#get-a-single-milestone)
|
||||
* [Adding a new milestone](#adding-a-new-milestone)
|
||||
* [Editing an existing milestone](#editing-an-existing-milestone)
|
||||
* [Removing a milestone](#removing-a-milestone)
|
||||
* [Events](#Events)
|
||||
* [Get events from a repository](#get-events-from-a-repository)
|
||||
* [Get events from an issue](#get-events-from-an-issue)
|
||||
* [Get a single event](#get-a-single-event])
|
||||
|
||||
----------
|
||||
|
||||
## Logging
|
||||
|
@ -418,6 +425,36 @@ Remove-GitHubComment -OwnerName Powershell -RepositoryName PowerShellForGitHub -
|
|||
|
||||
----------
|
||||
|
||||
### Milestones
|
||||
|
||||
#### Get milestones from a repository
|
||||
```powershell
|
||||
Get-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Sort "due_on" -Direction "asc" -DueOn '2011-04-14T16:00:49Z'
|
||||
```
|
||||
|
||||
#### Get a single milestone
|
||||
```powershell
|
||||
Get-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Milestone 1
|
||||
```
|
||||
|
||||
#### Assign an existing issue to a new milestone
|
||||
```powershell
|
||||
New-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Title "Testing this API"
|
||||
Update-GitHubIssue -OwnerName PowerShell -RepositoryName PowerShellForGitHub -Issue 2 -Milestone 1
|
||||
```
|
||||
|
||||
#### Editing an existing milestone
|
||||
```powershell
|
||||
Set-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Milestone 1 -Title "Testing this API edited"
|
||||
```
|
||||
|
||||
#### Removing a milestone
|
||||
```powershell
|
||||
Remove-GitHubMilestone -OwnerName Powershell -RepositoryName PowerShellForGitHub -Milestone 1
|
||||
```
|
||||
|
||||
----------
|
||||
|
||||
### Events
|
||||
|
||||
#### Get events from a repository
|
||||
|
|
Загрузка…
Ссылка в новой задаче