From 4f3d6e3413dafc686f40b2e885000298834cf226 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 8 Jun 2020 10:47:39 -0700 Subject: [PATCH 1/6] Standardize verb usage within the module (*Breaking change*) This attempts to rectify some improper verb usage in the module based on the explanations of intended verb usage from [previous PowerShell documentation](https://web.archive.org/web/20171222220053/https://msdn.microsoft.com/en-us/library/windows/desktop/ms714428(v=vs.85).aspx). * We're standardizing on the following pattern for most object actions: `Get` / `Set` / `New` / `Remove` * We will continue to alias `Remove-*` as `Delete-*`. * When possible, this change attempts to avoid breaking changes by re-aliasing the newly named functions with their previous names. This was not possible in one instance, hence this is still a breaking change (although based on telemetry, it should be minimally impacting). Result: * `Update-GitHubCurrentUser` -> `Set-GitHubProfile` `[Alias('Update-GitHubCurrentUser')]` * `Update-GitHubIssue` -> `Set-GitHubIssue` `[Alias('Update-GitHubIssue')]` * `Update-GitHubRepository` -> `Set-GitHubRepository` `[Alias('Update-GitHubRepository')]` * [breaking] `Update-GitHubLabel` -> `Set-GitHubLabel` `[Alias('Update-GitHubLabel')]` * [breaking] `Set-GitHubLabel` -> `Restore-GitHubLabel` `` Changing an existing label has much more regular usage than replacing all of the labels in a repository, hence allowing the _new_ `Set-GitHubLabel` to keep the alias of `Update-GitHubLabel`. Our usage of the `Set-*` verb in general is a bit arguable based on the documentation ... in theory `Edit-*` might be a better fit since we're _editing_ aspects of an object as opposed to _replacing_ the entire content of an object. However, I think `Set-*` _feels_ ok in this module. We're _setting_ the state of these objects. Again...arguable, but this is a much smaller breaking change to get to a consistent terminology state. --- GitHubIssues.ps1 | 9 ++-- GitHubLabels.ps1 | 15 +++---- GitHubRepositories.ps1 | 13 +++--- GitHubUsers.ps1 | 9 ++-- PowerShellForGitHub.psd1 | 8 ++++ Tests/GitHubEvents.tests.ps1 | 10 ++--- Tests/GitHubIssues.tests.ps1 | 10 ++--- Tests/GitHubLabels.tests.ps1 | 66 +++++++++++++----------------- Tests/GitHubMilestones.tests.ps1 | 6 +-- Tests/GitHubRepositories.tests.ps1 | 24 +++++++---- USAGE.md | 15 ++++--- 11 files changed, 101 insertions(+), 84 deletions(-) diff --git a/GitHubIssues.ps1 b/GitHubIssues.ps1 index 46931a43..1010b19a 100644 --- a/GitHubIssues.ps1 +++ b/GitHubIssues.ps1 @@ -654,14 +654,14 @@ filter New-GitHubIssue return (Invoke-GHRestMethod @params | Add-GitHubIssueAdditionalProperties) } -filter Update-GitHubIssue +filter Set-GitHubIssue { <# .SYNOPSIS - Create a new Issue on GitHub. + Updates an Issue on GitHub. .DESCRIPTION - Create a new Issue on GitHub. + Updates an Issue on GitHub. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -744,12 +744,13 @@ filter Update-GitHubIssue GitHub.Issue .EXAMPLE - Update-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -State Closed + Set-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 4 -Title 'Test Issue' -State Closed #> [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubIssueTypeName})] + [Alias('Update-GitHubIssue')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 41d306f5..245f20b2 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -486,7 +486,7 @@ filter Remove-GitHubLabel } } -filter Update-GitHubLabel +filter Set-GitHubLabel { <# .SYNOPSIS @@ -555,7 +555,7 @@ filter Update-GitHubLabel GitHub.Label .EXAMPLE - Update-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -NewName NewTestLabel -Color BBBB00 + Set-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label TestLabel -NewName NewTestLabel -Color BBBB00 Updates the existing label called TestLabel in the PowerShellForGitHub project to be called 'NewTestLabel' and be colored yellow. @@ -564,6 +564,7 @@ filter Update-GitHubLabel SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubLabelTypeName})] + [Alias('Update-GitHubLabel')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] @@ -637,15 +638,15 @@ filter Update-GitHubLabel return (Invoke-GHRestMethod @params | Add-GitHubLabelAdditionalProperties) } -filter Set-GitHubLabel +filter Restore-GitHubLabel { <# .SYNOPSIS - Sets the entire set of Labels on the given GitHub repository to match the provided list + Replaces the entire set of Labels on the given GitHub repository to match the provided list of Labels. .DESCRIPTION - Sets the entire set of Labels on the given GitHub repository to match the provided list + Replaces the entire set of Labels on the given GitHub repository to match the provided list of Labels. Will update the color/description for any Labels already in the repository that match the @@ -697,7 +698,7 @@ filter Set-GitHubLabel GitHub.Repository .EXAMPLE - Set-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label @(@{'name' = 'TestLabel'; 'color' = 'EEEEEE'}, @{'name' = 'critical'; 'color' = 'FF000000'; 'description' = 'Needs immediate attention'}) + Restore-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label @(@{'name' = 'TestLabel'; 'color' = 'EEEEEE'}, @{'name' = 'critical'; 'color' = 'FF000000'; 'description' = 'Needs immediate attention'}) Removes any labels not in this Label array, ensure the current assigned color and descriptions match what's in the array for the labels that do already exist, and then creates new labels @@ -769,7 +770,7 @@ filter Set-GitHubLabel else { # Update label's color if it already exists - $null = Update-GitHubLabel -Label $labelToConfigure.name -NewName $labelToConfigure.name -Color $labelToConfigure.color @commonParams + $null = Set-GitHubLabel -Label $labelToConfigure.name -NewName $labelToConfigure.name -Color $labelToConfigure.color @commonParams } } diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 7a2c2e04..8bc58389 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -1015,11 +1015,11 @@ filter Rename-GitHubRepository ) # This method was created by mistake and is now retained to avoid a breaking change. - # Update-GitHubRepository is able to handle this scenario just fine. - return Update-GitHubRepository @PSBoundParameters + # Set-GitHubRepository is able to handle this scenario just fine. + return Set-GitHubRepository @PSBoundParameters } -filter Update-GitHubRepository +filter Set-GitHubRepository { <# .SYNOPSIS @@ -1125,18 +1125,18 @@ filter Update-GitHubRepository GitHub.Repository .EXAMPLE - Update-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub -Description 'The best way to automate your GitHub interactions' + Set-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub -Description 'The best way to automate your GitHub interactions' Changes the description of the specified repository. .EXAMPLE - Update-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -Private:$false + Set-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -Private:$false Changes the visibility of the specified repository to be public. .EXAMPLE Get-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub | - Update-GitHubRepository -NewName 'PoShForGitHub' -Force + Set-GitHubRepository -NewName 'PoShForGitHub' -Force Renames the repository without any user confirmation prompting. This is identical to using Rename-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -NewName 'PoShForGitHub' -Confirm:$false @@ -1146,6 +1146,7 @@ filter Update-GitHubRepository DefaultParameterSetName='Elements', ConfirmImpact='High')] [OutputType({$script:GitHubRepositoryTypeName})] + [Alias('Update-GitHubRepository')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [Parameter(ParameterSetName='Elements')] diff --git a/GitHubUsers.ps1 b/GitHubUsers.ps1 index 1ed37ccc..16019b45 100644 --- a/GitHubUsers.ps1 +++ b/GitHubUsers.ps1 @@ -300,14 +300,14 @@ filter Get-GitHubUserContextualInformation return $result } -function Update-GitHubCurrentUser +function Set-GitHubProfile { <# .SYNOPSIS - Updates information about the current authenticated user on GitHub. + Updates profile information for the current authenticated user on GitHub. .DESCRIPTION - Updates information about the current authenticated user on GitHub. + Updates profile information for the current authenticated user on GitHub. The Git repo for this module can be found here: http://aka.ms/PowerShellForGitHub @@ -347,13 +347,14 @@ function Update-GitHubCurrentUser GitHub.User .EXAMPLE - Update-GitHubCurrentUser -Location 'Seattle, WA' -Hireable:$false + Set-GitHubProfile -Location 'Seattle, WA' -Hireable:$false Updates the current user to indicate that their location is "Seattle, WA" and that they are not currently hireable. #> [CmdletBinding(SupportsShouldProcess)] [OutputType({$script:GitHubUserTypeName})] + [Alias('Update-GitHubCurrentUser')] # Non-standard usage of the Update verb, but done to avoid a breaking change post 0.14.0 [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] param( [string] $Name, diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index b49ff1f0..7c7d0149 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -133,16 +133,20 @@ 'Rename-GitHubRepository', 'Reset-GitHubConfiguration', 'Restore-GitHubConfiguration', + 'Restore-GitHubLabel', 'Set-GitHubAuthentication', 'Set-GitHubConfiguration', 'Set-GitHubContent', + 'Set-GitHubIssue', 'Set-GitHubIssueComment', 'Set-GitHubIssueLabel', 'Set-GitHubLabel', 'Set-GitHubMilestone', + 'Set-GitHubProfile', 'Set-GitHubProject', 'Set-GitHubProjectCard', 'Set-GitHubProjectColumn', + 'Set-GitHubRepository' 'Set-GitHubRepositoryTopic', 'Split-GitHubUri', 'Test-GitHubAssignee', @@ -171,6 +175,10 @@ 'Remove-GitHubComment', 'Set-GitHubComment', 'Transfer-GitHubRepositoryOwnership' + 'Update-GitHubIssue', + 'Update-GitHubLabel', + 'Update-GitHubCurrentUser', + 'Update-GitHubRepository' ) # Cmdlets to export from this module diff --git a/Tests/GitHubEvents.tests.ps1 b/Tests/GitHubEvents.tests.ps1 index 43390e7a..963cd9b1 100644 --- a/Tests/GitHubEvents.tests.ps1 +++ b/Tests/GitHubEvents.tests.ps1 @@ -45,7 +45,7 @@ try Context 'For getting Issue events from a repository' { $issue = $repo | New-GitHubIssue -Title 'New Issue' - $issue = $issue | Update-GitHubIssue -State Closed + $issue = $issue | Set-GitHubIssue -State Closed $events = @($repo | Get-GitHubEvent) It 'Should have an event from closing an issue' { @@ -82,8 +82,8 @@ try } Context 'For getting events from an issue' { - $issue = $issue | Update-GitHubIssue -State Closed - $issue = $issue | Update-GitHubIssue -State Open + $issue = $issue | Set-GitHubIssue -State Closed + $issue = $issue | Set-GitHubIssue -State Open $events = @(Get-GitHubEvent -OwnerName $ownerName -RepositoryName $repositoryName) It 'Should have two events from closing and opening the issue' { @@ -98,8 +98,8 @@ try $repositoryName = [Guid]::NewGuid() $repo = New-GitHubRepository -RepositoryName $repositoryName $issue = $repo | New-GitHubIssue -Title 'New Issue' - $issue = $issue | Update-GitHubIssue -State Closed - $issue = $issue | Update-GitHubIssue -State Open + $issue = $issue | Set-GitHubIssue -State Closed + $issue = $issue | Set-GitHubIssue -State Open $events = @($repo | Get-GitHubEvent) } diff --git a/Tests/GitHubIssues.tests.ps1 b/Tests/GitHubIssues.tests.ps1 index 21b4dd30..ed5c4d88 100644 --- a/Tests/GitHubIssues.tests.ps1 +++ b/Tests/GitHubIssues.tests.ps1 @@ -164,8 +164,8 @@ try Start-Sleep -Seconds 1 # Needed to ensure that there is a unique creation timestamp between issues } - $newIssues[0] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed - $newIssues[-1] = Update-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[-1].number -State Closed + $newIssues[0] = Set-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[0].number -State Closed + $newIssues[-1] = Set-GitHubIssue -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $newIssues[-1].number -State Closed $existingOpenIssues = @($existingIssues | Where-Object { $_.state -eq 'open' }) $newOpenIssues = @($newIssues | Where-Object { $_.state -eq 'open' }) @@ -316,7 +316,7 @@ try 'MediaType' = 'Raw' } - $updated = Update-GitHubIssue @params + $updated = Set-GitHubIssue @params It 'Should have the expected property values' { $updated.id | Should -Be $issue.id $updated.number | Should -Be $issue.number @@ -364,7 +364,7 @@ try 'MediaType' = 'Raw' } - $updated = $repo | Update-GitHubIssue @params + $updated = $repo | Set-GitHubIssue @params It 'Should have the expected property values' { $updated.id | Should -Be $issue.id $updated.number | Should -Be $issue.number @@ -411,7 +411,7 @@ try 'MediaType' = 'Raw' } - $updated = $issue | Update-GitHubIssue @params + $updated = $issue | Set-GitHubIssue @params It 'Should have the expected property values' { $updated.id | Should -Be $issue.id $updated.number | Should -Be $issue.number diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index e2807442..a986313c 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -81,7 +81,7 @@ try $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels + Restore-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels } AfterAll { @@ -376,7 +376,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newColor = 'AAAAAA' - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Color $newColor + $result = Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Color $newColor It 'Label should have different color' { $result.name | Should -Be $label.name @@ -396,7 +396,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newColor = '#AAAAAA' - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Color $newColor + $result = Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Color $newColor It 'Label should have different color' { $result.name | Should -Be $label.name @@ -416,7 +416,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newName = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -NewName $newName + $result = Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -NewName $newName It 'Label should have different name' { $result.name | Should -Be $newName @@ -436,7 +436,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' -Description 'test description' $newDescription = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Description $newDescription + $result = Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -Description $newDescription It 'Label should have different name' { $result.name | Should -Be $label.name @@ -458,7 +458,7 @@ try $newName = [Guid]::NewGuid().Guid $newColor = 'AAAAAA' $newDescription = [Guid]::NewGuid().Guid - $result = Update-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -NewName $newName -Color $newColor -Description $newDescription + $result = Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $label.name -NewName $newName -Color $newColor -Description $newDescription It 'Label should have different everything' { $result.name | Should -Be $newName @@ -480,7 +480,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newColor = 'AAAAAA' - $result = $repo | Update-GitHubLabel -Label $label.name -Color $newColor + $result = $repo | Set-GitHubLabel -Label $label.name -Color $newColor It 'Label should have different color' { $result.name | Should -Be $label.name @@ -500,7 +500,7 @@ try $label = $repo | New-GitHubLabel -Label ([Guid]::NewGuid().Guid) -Color 'BBBBBB' $newName = [Guid]::NewGuid().Guid - $result = $label | Update-GitHubLabel -NewName $newName + $result = $label | Set-GitHubLabel -NewName $newName It 'Label should have different name' { $result.name | Should -Be $newName @@ -522,7 +522,7 @@ try $newName = [Guid]::NewGuid().Guid $newColor = 'AAAAAA' $newDescription = [Guid]::NewGuid().Guid - $result = $label | Update-GitHubLabel -NewName $newName -Color $newColor -Description $newDescription + $result = $label | Set-GitHubLabel -NewName $newName -Color $newColor -Description $newDescription It 'Label should have different everything' { $result.name | Should -Be $newName @@ -550,7 +550,7 @@ try } Context 'Applying a default set of labels' { - Set-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels + Restore-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels $labels = @($repo | Get-GitHubLabel) @@ -578,7 +578,7 @@ try ) $originalLabels = @($repo | Get-GitHubLabel) - $null = $repo | Set-GitHubLabel -Label $newLabels + $null = $repo | Restore-GitHubLabel -Label $newLabels $labels = @($repo | Get-GitHubLabel) It 'Should return the expected number of labels' { @@ -595,37 +595,29 @@ try } It 'Should have retained the ID''s of the pre-existing labels' { - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[0].name } - $label = $labels | Where-Object { $_.name -eq $newLabels[0].name } - $label.id | Should -Be $originalLabel.id - - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[1].name } - $label = $labels | Where-Object { $_.name -eq $newLabels[1].name } - $label.id | Should -Be $originalLabel.id - - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[2].name } - $label = $labels | Where-Object { $_.name -eq $newLabels[2].name } - $label.id | Should -Be $originalLabel.id - - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[3].name } - $label = $labels | Where-Object { $_.name -eq $newLabels[3].name } - $originalLabel | Should -BeNullOrEmpty - $label | Should -Not -BeNullOrEmpty + for ($i = 0; $i -le 2; $i++) + { + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[$i].name } + $label = $labels | Where-Object { $_.name -eq $newLabels[$i].name } + $label.id | Should -Be $originalLabel.id + } - $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[4].name } - $label = $labels | Where-Object { $_.name -eq $newLabels[4].name } - $originalLabel | Should -BeNullOrEmpty - $label | Should -Not -BeNullOrEmpty + for ($i = 3; $i -le 4; $i++) + { + $originalLabel = $originalLabels | Where-Object { $_.name -eq $newLabels[$i].name } + $label = $labels | Where-Object { $_.name -eq $newLabels[$i].name } + $originalLabel | Should -BeNullOrEmpty + $label | Should -Not -BeNullOrEmpty + } } } - } Describe 'Adding labels to an issue' { BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Set-GitHubLabel -Label $defaultLabels + $repo | Restore-GitHubLabel -Label $defaultLabels } AfterAll { @@ -853,7 +845,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Set-GitHubLabel -Label $defaultLabels + $repo | Restore-GitHubLabel -Label $defaultLabels } AfterAll { @@ -919,7 +911,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Set-GitHubLabel -Label $defaultLabels + $repo | Restore-GitHubLabel -Label $defaultLabels } AfterAll { @@ -1086,7 +1078,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Set-GitHubLabel -Label $defaultLabels + $repo | Restore-GitHubLabel -Label $defaultLabels } AfterAll { @@ -1235,7 +1227,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Set-GitHubLabel -Label $defaultLabels + $repo | Restore-GitHubLabel -Label $defaultLabels $milestone = $repo | New-GitHubMilestone -Title 'test milestone' diff --git a/Tests/GitHubMilestones.tests.ps1 b/Tests/GitHubMilestones.tests.ps1 index 048e5dac..cc6c2b89 100644 --- a/Tests/GitHubMilestones.tests.ps1 +++ b/Tests/GitHubMilestones.tests.ps1 @@ -182,21 +182,21 @@ try $milestone.open_issues | Should -Be 0 } - $issue = $issue | Update-GitHubIssue -Milestone $milestone.MilestoneNumber + $issue = $issue | Set-GitHubIssue -Milestone $milestone.MilestoneNumber $milestone = $milestone | Get-GitHubMilestone It "Should be associated to the milestone now" { $issue.milestone.number | Should -Be $milestone.MilestoneNumber $milestone.open_issues | Should -Be 1 } - $issue = $issue | Update-GitHubIssue -Milestone 0 + $issue = $issue | Set-GitHubIssue -Milestone 0 $milestone = $milestone | Get-GitHubMilestone It 'Should no longer be associated to the milestone' { $issue.milestone | Should -BeNullOrEmpty $milestone.open_issues | Should -Be 0 } - $issue = $issue | Update-GitHubIssue -Milestone $milestone.MilestoneNumber + $issue = $issue | Set-GitHubIssue -Milestone $milestone.MilestoneNumber $milestone = $milestone | Get-GitHubMilestone It "Should be associated to the milestone again" { $issue.milestone.number | Should -Be $milestone.MilestoneNumber diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 37bd6983..d6a98953 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -662,8 +662,8 @@ try $renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' } - It "Should be possible to rename with Update-GitHubRepository too" { - $renamedRepo = $repo | Update-GitHubRepository -NewName $newRepoName -Confirm:$false + It "Should be possible to rename with Set-GitHubRepository too" { + $renamedRepo = $repo | Set-GitHubRepository -NewName $newRepoName -Confirm:$false $renamedRepo.name | Should -Be $newRepoName $renamedRepo.PSObject.TypeNames[0] | Should -Be 'GitHub.Repository' } @@ -674,7 +674,7 @@ try } } - Describe 'GitHubRepositories\Update-GitHubRepository' { + Describe 'GitHubRepositories\Set-GitHubRepository' { Context -Name 'When updating a public repository' -Fixture { BeforeAll -ScriptBlock { @@ -699,7 +699,7 @@ try DeleteBranchOnMerge = $true IsTemplate = $true } - $updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms + $updatedRepo = Set-GitHubRepository @updateGithubRepositoryParms } It 'Should return an object of the correct type' { @@ -731,7 +731,7 @@ try DisallowMergeCommit = $false DisallowRebaseMerge = $true } - $updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms + $updatedRepo = Set-GitHubRepository @updateGithubRepositoryParms } It 'Should return an object of the correct type' { @@ -753,7 +753,7 @@ try RepositoryName = $repoName Archived = $true } - $updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms + $updatedRepo = Set-GitHubRepository @updateGithubRepositoryParms } It 'Should return an object of the correct type' { @@ -784,7 +784,7 @@ try RepositoryName = $repoName Private = $false } - $updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms + $updatedRepo = Set-GitHubRepository @updateGithubRepositoryParms } It 'Should return an object of the correct type' { @@ -794,6 +794,16 @@ try It 'Should return the correct properties' { $updatedRepo.name | Should -Be $repoName $updatedRepo.private | Should -BeFalse + + It 'Should have the new updated description' { + $modifiedRepoDesc = $defaultRepoDesc + "_modified" + $updatedRepo = Set-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Description $modifiedRepoDesc + $updatedRepo.description | Should -Be $modifiedRepoDesc + } + + It 'Should have the new updated homepage url' { + $updatedRepo = Set-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Homepage $defaultRepoHomePage + $updatedRepo.homepage | Should -Be $defaultRepoHomePage } AfterAll -ScriptBlock { diff --git a/USAGE.md b/USAGE.md index 2b275c61..9e0bdcdd 100644 --- a/USAGE.md +++ b/USAGE.md @@ -395,13 +395,16 @@ Remove-GitHubIssueLabel -OwnerName microsoft -RepositoryName DesiredStateConfigu #### Updating a Label With a New Name and Color ```powershell -Update-GitHubLabel -OwnerName microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -NewName NewTestLabel -Color BBBB00 +Set-GitHubLabel -OwnerName microsoft -RepositoryName DesiredStateConfiguration -Name TestLabel -NewName NewTestLabel -Color BBBB00 ``` #### Bulk Updating Labels in a Repository +This replaces the entire set of labels in a repository to only contain the labels in the provided array. +Any labels already in the repository that are not in this array will be removed upon execution. + ```powershell $labels = @( @{ 'name' = 'Label1'; 'color' = 'BBBB00'; 'description' = 'My label description' }, @{ 'name' = 'Label2'; 'color' = 'FF00000' }) -Set-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Label $labels +Restore-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Label $labels ``` ---------- @@ -413,9 +416,9 @@ Set-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration Get-GitHubUser -Current ``` -#### Updating the current authenticated user +#### Updating the current authenticated user's profile ```powershell -Update-GitHubCurrentUser -Location 'Seattle, WA' -Hireable:$false +Set-GitHubProfile -Location 'Seattle, WA' -Hireable:$false ``` #### Getting any user @@ -628,7 +631,7 @@ Get-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Mi #### Assign an existing issue to a new milestone ```powershell New-GitHubMilestone -OwnerName microsoft -RepositoryName PowerShellForGitHub -Title "Testing this API" -Update-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 2 -Milestone 1 +Set-GitHubIssue -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 2 -Milestone 1 ``` #### Editing an existing milestone @@ -722,5 +725,5 @@ $issue = $repo | New-GitHubIssue -Title $IssueTitle -Body $body -Label 'blog com $issue | New-GitHubIssueComment -Body $CommentBody # Close issue -$issue | Update-GitHubIssue -State Closed +$issue | Set-GitHubIssue -State Closed ``` From 3caa8632a0f8b1af9f2ebfa58a28f40bb2bd14c1 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 8 Jun 2020 14:06:49 -0700 Subject: [PATCH 2/6] Also update `New-GitHubAssignee` -> `Add-GitHubAssignee` --- GitHubAssignees.ps1 | 11 ++++++----- PowerShellForGitHub.psd1 | 4 +++- Tests/GitHubAssignees.tests.ps1 | 8 ++++---- USAGE.md | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/GitHubAssignees.ps1 b/GitHubAssignees.ps1 index 2c439da1..0964573a 100644 --- a/GitHubAssignees.ps1 +++ b/GitHubAssignees.ps1 @@ -247,7 +247,7 @@ filter Test-GitHubAssignee } } -function New-GitHubAssignee +function Add-GitHubAssignee { <# .DESCRIPTION @@ -308,7 +308,7 @@ function New-GitHubAssignee .EXAMPLE $assignees = @('octocat') - New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Assignee $assignee + Add-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 -Assignee $assignee Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. @@ -316,7 +316,7 @@ function New-GitHubAssignee .EXAMPLE $assignees = @('octocat') $repo = Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub - $repo | New-GitHubAssignee -Issue 1 -Assignee $assignee + $repo | Add-GitHubAssignee -Issue 1 -Assignee $assignee Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. @@ -325,14 +325,14 @@ function New-GitHubAssignee $assignees = @('octocat') Get-GitHubRepository -OwnerName microsoft -RepositoryName PowerShellForGitHub | Get-GitHubIssue -Issue 1 | - New-GitHubAssignee -Assignee $assignee + Add-GitHubAssignee -Assignee $assignee Additionally assigns the usernames in $assignee to Issue #1 from the microsoft\PowerShellForGitHub project. .EXAMPLE $octocat = Get-GitHubUser -UserName 'octocat' - $octocat | New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 + $octocat | Add-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Issue 1 Additionally assigns the user 'octocat' to Issue #1 from the microsoft\PowerShellForGitHub project. @@ -341,6 +341,7 @@ function New-GitHubAssignee SupportsShouldProcess, DefaultParameterSetName='Elements')] [OutputType({$script:GitHubIssueTypeName})] + [Alias('New-GitHubAssignee')] # Non-standard usage of the New verb, but done to avoid a breaking change post 0.14.0 [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSReviewUnusedParameter", "", Justification="One or more parameters (like NoStatus) are only referenced by helper methods which get access to it from the stack via Get-Variable -Scope 1.")] param( diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 7c7d0149..41117e17 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -55,6 +55,7 @@ # Functions to export from this module FunctionsToExport = @( + 'Add-GitHubAssignee', 'Add-GitHubIssueLabel', 'Backup-GitHubConfiguration', 'Clear-GitHubAuthentication', @@ -109,7 +110,7 @@ 'Move-GitHubProjectCard', 'Move-GitHubProjectColumn', 'Move-GitHubRepositoryOwnership', - 'New-GitHubAssignee', + 'New-GitHubComment', 'New-GitHubIssue', 'New-GitHubIssueComment', 'New-GitHubLabel', @@ -171,6 +172,7 @@ 'Delete-GitHubRepository', 'Get-GitHubBranch', 'Get-GitHubComment', + 'New-GitHubAssignee', 'New-GitHubComment', 'Remove-GitHubComment', 'Set-GitHubComment', diff --git a/Tests/GitHubAssignees.tests.ps1 b/Tests/GitHubAssignees.tests.ps1 index d9eeb61c..64a694b5 100644 --- a/Tests/GitHubAssignees.tests.ps1 +++ b/Tests/GitHubAssignees.tests.ps1 @@ -112,7 +112,7 @@ try $issue.assignees | Should -BeNullOrEmpty } - $updatedIssue = New-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Assignee $owner.login + $updatedIssue = Add-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number -Assignee $owner.login It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } @@ -149,7 +149,7 @@ try $issue.assignees | Should -BeNullOrEmpty } - $updatedIssue = $repo | New-GitHubAssignee -Issue $issue.number -Assignee $owner.login + $updatedIssue = $repo | Add-GitHubAssignee -Issue $issue.number -Assignee $owner.login It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } @@ -186,7 +186,7 @@ try $issue.assignees | Should -BeNullOrEmpty } - $updatedIssue = $issue | New-GitHubAssignee -Assignee $owner.login + $updatedIssue = $issue | Add-GitHubAssignee -Assignee $owner.login It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } @@ -223,7 +223,7 @@ try $issue.assignees | Should -BeNullOrEmpty } - $updatedIssue = $owner | New-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number + $updatedIssue = $owner | Add-GitHubAssignee -OwnerName $script:ownerName -RepositoryName $repo.name -Issue $issue.number It 'Should have returned the same issue' { $updatedIssue.number | Should -Be $issue.number } diff --git a/USAGE.md b/USAGE.md index 9e0bdcdd..7b6bc941 100644 --- a/USAGE.md +++ b/USAGE.md @@ -572,7 +572,7 @@ $HasPermission = Test-GitHubAssignee -OwnerName microsoft -RepositoryName PowerS #### Add assignee to an issue ```powershell -New-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 +Add-GitHubAssignee -OwnerName microsoft -RepositoryName PowerShellForGitHub -Assignees $assignees -Issue 1 ``` #### Remove assignee from an issue From e40edf2a28dd70449c33cd0393862b2dcac3232a Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Mon, 8 Jun 2020 14:14:32 -0700 Subject: [PATCH 3/6] `Restore-GitHubLabel` -> `Initialize-GitHubLabel` --- GitHubLabels.ps1 | 4 ++-- PowerShellForGitHub.psd1 | 2 +- Tests/GitHubLabels.tests.ps1 | 16 ++++++++-------- USAGE.md | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/GitHubLabels.ps1 b/GitHubLabels.ps1 index 245f20b2..80f55480 100644 --- a/GitHubLabels.ps1 +++ b/GitHubLabels.ps1 @@ -638,7 +638,7 @@ filter Set-GitHubLabel return (Invoke-GHRestMethod @params | Add-GitHubLabelAdditionalProperties) } -filter Restore-GitHubLabel +filter Initialize-GitHubLabel { <# .SYNOPSIS @@ -698,7 +698,7 @@ filter Restore-GitHubLabel GitHub.Repository .EXAMPLE - Restore-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label @(@{'name' = 'TestLabel'; 'color' = 'EEEEEE'}, @{'name' = 'critical'; 'color' = 'FF000000'; 'description' = 'Needs immediate attention'}) + Initialize-GitHubLabel -OwnerName microsoft -RepositoryName PowerShellForGitHub -Label @(@{'name' = 'TestLabel'; 'color' = 'EEEEEE'}, @{'name' = 'critical'; 'color' = 'FF000000'; 'description' = 'Needs immediate attention'}) Removes any labels not in this Label array, ensure the current assigned color and descriptions match what's in the array for the labels that do already exist, and then creates new labels diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 41117e17..d8d91995 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -103,6 +103,7 @@ 'Get-GitHubViewTraffic', 'Group-GitHubIssue', 'Group-GitHubPullRequest', + 'Initialize-GitHubLabel', 'Invoke-GHRestMethod', 'Invoke-GHRestMethodMultipleResult', 'Join-GitHubUri', @@ -134,7 +135,6 @@ 'Rename-GitHubRepository', 'Reset-GitHubConfiguration', 'Restore-GitHubConfiguration', - 'Restore-GitHubLabel', 'Set-GitHubAuthentication', 'Set-GitHubConfiguration', 'Set-GitHubContent', diff --git a/Tests/GitHubLabels.tests.ps1 b/Tests/GitHubLabels.tests.ps1 index a986313c..5c3a1e30 100644 --- a/Tests/GitHubLabels.tests.ps1 +++ b/Tests/GitHubLabels.tests.ps1 @@ -81,7 +81,7 @@ try $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - Restore-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels + Initialize-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels } AfterAll { @@ -550,7 +550,7 @@ try } Context 'Applying a default set of labels' { - Restore-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels + Initialize-GitHubLabel -OwnerName $script:ownerName -RepositoryName $repositoryName -Label $defaultLabels $labels = @($repo | Get-GitHubLabel) @@ -578,7 +578,7 @@ try ) $originalLabels = @($repo | Get-GitHubLabel) - $null = $repo | Restore-GitHubLabel -Label $newLabels + $null = $repo | Initialize-GitHubLabel -Label $newLabels $labels = @($repo | Get-GitHubLabel) It 'Should return the expected number of labels' { @@ -617,7 +617,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Restore-GitHubLabel -Label $defaultLabels + $repo | Initialize-GitHubLabel -Label $defaultLabels } AfterAll { @@ -845,7 +845,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Restore-GitHubLabel -Label $defaultLabels + $repo | Initialize-GitHubLabel -Label $defaultLabels } AfterAll { @@ -911,7 +911,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Restore-GitHubLabel -Label $defaultLabels + $repo | Initialize-GitHubLabel -Label $defaultLabels } AfterAll { @@ -1078,7 +1078,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Restore-GitHubLabel -Label $defaultLabels + $repo | Initialize-GitHubLabel -Label $defaultLabels } AfterAll { @@ -1227,7 +1227,7 @@ try BeforeAll { $repositoryName = [Guid]::NewGuid().Guid $repo = New-GitHubRepository -RepositoryName $repositoryName - $repo | Restore-GitHubLabel -Label $defaultLabels + $repo | Initialize-GitHubLabel -Label $defaultLabels $milestone = $repo | New-GitHubMilestone -Title 'test milestone' diff --git a/USAGE.md b/USAGE.md index 7b6bc941..441081e7 100644 --- a/USAGE.md +++ b/USAGE.md @@ -404,7 +404,7 @@ Any labels already in the repository that are not in this array will be removed ```powershell $labels = @( @{ 'name' = 'Label1'; 'color' = 'BBBB00'; 'description' = 'My label description' }, @{ 'name' = 'Label2'; 'color' = 'FF00000' }) -Restore-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Label $labels +Initialize-GitHubLabel -OwnerName PowerShell -RepositoryName DesiredStateConfiguration -Label $labels ``` ---------- From 1ff4cb9e30b57fed83640e1b96071b1be015af23 Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Thu, 18 Jun 2020 15:31:24 -0700 Subject: [PATCH 4/6] Fixing bad merge in GitHubRepositories.tests.ps1 --- Tests/GitHubRepositories.tests.ps1 | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index d6a98953..9e7a0944 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -794,16 +794,6 @@ try It 'Should return the correct properties' { $updatedRepo.name | Should -Be $repoName $updatedRepo.private | Should -BeFalse - - It 'Should have the new updated description' { - $modifiedRepoDesc = $defaultRepoDesc + "_modified" - $updatedRepo = Set-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Description $modifiedRepoDesc - $updatedRepo.description | Should -Be $modifiedRepoDesc - } - - It 'Should have the new updated homepage url' { - $updatedRepo = Set-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Homepage $defaultRepoHomePage - $updatedRepo.homepage | Should -Be $defaultRepoHomePage } AfterAll -ScriptBlock { From 8733380c3eaf0eecc6807ec908f17c21997bab4d Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Thu, 18 Jun 2020 15:37:07 -0700 Subject: [PATCH 5/6] Fixing bad merge in the manifest --- PowerShellForGitHub.psd1 | 1 - 1 file changed, 1 deletion(-) diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index d8d91995..2bd3bf2f 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -111,7 +111,6 @@ 'Move-GitHubProjectCard', 'Move-GitHubProjectColumn', 'Move-GitHubRepositoryOwnership', - 'New-GitHubComment', 'New-GitHubIssue', 'New-GitHubIssueComment', 'New-GitHubLabel', From 4c9fd2100b9fa5a2f52c90c1380c9467f29c27bf Mon Sep 17 00:00:00 2001 From: Howard Wolosky Date: Sun, 28 Jun 2020 21:30:59 -0700 Subject: [PATCH 6/6] Fixing bad merge --- PowerShellForGitHub.psd1 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/PowerShellForGitHub.psd1 b/PowerShellForGitHub.psd1 index 2bd3bf2f..cb7fcf06 100644 --- a/PowerShellForGitHub.psd1 +++ b/PowerShellForGitHub.psd1 @@ -153,11 +153,7 @@ 'Test-GitHubAuthenticationConfigured', 'Test-GitHubOrganizationMember', 'Test-GitHubRepositoryVulnerabilityAlert', - 'Unlock-GitHubIssue', - 'Update-GitHubCurrentUser', - 'Update-GitHubIssue', - 'Update-GitHubLabel', - 'Update-GitHubRepository' + 'Unlock-GitHubIssue' ) AliasesToExport = @(