From c67b279dd5130b6eb05cfab361a513e7b7b1b81e Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Thu, 28 May 2020 22:00:50 +0100 Subject: [PATCH 1/8] Update GitHubRepositories.ps1 --- GitHubRepositories.ps1 | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 5f58b450..27d84aa7 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -40,9 +40,12 @@ function New-GitHubRepository This is only valid when creating a repository in an organization. .PARAMETER Private - By default, this repository will created Public. Specify this to create + By default, this repository will be created Public. Specify this to create a private repository. + .PARAMETER Visibility + Specifies the visibility level of the repository. + .PARAMETER NoIssues By default, this repository will support Issues. Specify this to disable Issues. @@ -69,6 +72,12 @@ function New-GitHubRepository By default, rebase-merge pull requests will be allowed. Specify this to disallow. + .PARAMETER DeleteBranchOnMerge + Specifies the automatic deleting of head branches when pull requests are merged. + + .PARAMETER IsTemplate + Specifies whether the repository is made available as a template. + .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. @@ -106,6 +115,9 @@ function New-GitHubRepository [switch] $Private, + [ValidateSet('Public', 'Private', 'Internal')] + [string] $Visibility, + [switch] $NoIssues, [switch] $NoProjects, @@ -120,6 +132,10 @@ function New-GitHubRepository [switch] $DisallowRebaseMerge, + [switch] $DeleteBranchOnMerge, + + [switch] $IsTemplate, + [string] $AccessToken, [switch] $NoStatus @@ -156,6 +172,7 @@ function New-GitHubRepository if ($PSBoundParameters.ContainsKey('LicenseTemplate')) { $hashBody['license_template'] = $LicenseTemplate } if ($PSBoundParameters.ContainsKey('TeamId')) { $hashBody['team_id'] = $TeamId } if ($PSBoundParameters.ContainsKey('Private')) { $hashBody['private'] = $Private.ToBool() } + if ($PSBoundParameters.ContainsKey('Visibility')) { $hashBody['visibility'] = $Visibility } if ($PSBoundParameters.ContainsKey('NoIssues')) { $hashBody['has_issues'] = (-not $NoIssues.ToBool()) } if ($PSBoundParameters.ContainsKey('NoProjects')) { $hashBody['has_projects'] = (-not $NoProjects.ToBool()) } if ($PSBoundParameters.ContainsKey('NoWiki')) { $hashBody['has_wiki'] = (-not $NoWiki.ToBool()) } @@ -163,6 +180,8 @@ function New-GitHubRepository if ($PSBoundParameters.ContainsKey('DisallowSquashMerge')) { $hashBody['allow_squash_merge'] = (-not $DisallowSquashMerge.ToBool()) } if ($PSBoundParameters.ContainsKey('DisallowMergeCommit')) { $hashBody['allow_merge_commit'] = (-not $DisallowMergeCommit.ToBool()) } if ($PSBoundParameters.ContainsKey('DisallowRebaseMerge')) { $hashBody['allow_rebase_merge'] = (-not $DisallowRebaseMerge.ToBool()) } + if ($PSBoundParameters.ContainsKey('DeleteBranchOnMerge')) { $hashBody['delete_branch_on_merge'] = $DeleteBranchOnMerge.ToBool() } + if ($PSBoundParameters.ContainsKey('IsTemplate')) { $hashBody['is_template'] = $IsTemplate.ToBool() } $params = @{ 'UriFragment' = $uriFragment @@ -713,6 +732,9 @@ function Update-GitHubRepository Specify this to make the repository private. To change a repository to be public, specify -Private:$false + .PARAMETER Visibility + Specifies the visibility level of the repository. + .PARAMETER NoIssues By default, this repository will support Issues. Specify this to disable Issues. @@ -736,6 +758,12 @@ function Update-GitHubRepository By default, rebase-merge pull requests will be allowed. Specify this to disallow. + .PARAMETER DeleteBranchOnMerge + Specifies the automatic deleting of head branches when pull requests are merged. + + .PARAMETER IsTemplate + Specifies whether the repository is made available as a template. + .PARAMETER Archived Specify this to archive this repository. NOTE: You cannot unarchive repositories through the API / this module. @@ -780,6 +808,9 @@ function Update-GitHubRepository [switch] $Private, + [ValidateSet('Public', 'Private', 'Internal')] + [string] $Visibility, + [switch] $NoIssues, [switch] $NoProjects, @@ -792,6 +823,10 @@ function Update-GitHubRepository [switch] $DisallowRebaseMerge, + [switch] $DeleteBranchOnMerge, + + [switch] $IsTemplate, + [switch] $Archived, [string] $AccessToken, @@ -818,12 +853,15 @@ function Update-GitHubRepository if ($PSBoundParameters.ContainsKey('Homepage')) { $hashBody['homepage'] = $Homepage } if ($PSBoundParameters.ContainsKey('DefaultBranch')) { $hashBody['default_branch'] = $DefaultBranch } if ($PSBoundParameters.ContainsKey('Private')) { $hashBody['private'] = $Private.ToBool() } + if ($PSBoundParameters.ContainsKey('Visibility')) { $hashBody['visibility'] = $Visibility } if ($PSBoundParameters.ContainsKey('NoIssues')) { $hashBody['has_issues'] = (-not $NoIssues.ToBool()) } if ($PSBoundParameters.ContainsKey('NoProjects')) { $hashBody['has_projects'] = (-not $NoProjects.ToBool()) } if ($PSBoundParameters.ContainsKey('NoWiki')) { $hashBody['has_wiki'] = (-not $NoWiki.ToBool()) } if ($PSBoundParameters.ContainsKey('DisallowSquashMerge')) { $hashBody['allow_squash_merge'] = (-not $DisallowSquashMerge.ToBool()) } if ($PSBoundParameters.ContainsKey('DisallowMergeCommit')) { $hashBody['allow_merge_commit'] = (-not $DisallowMergeCommit.ToBool()) } if ($PSBoundParameters.ContainsKey('DisallowRebaseMerge')) { $hashBody['allow_rebase_merge'] = (-not $DisallowRebaseMerge.ToBool()) } + if ($PSBoundParameters.ContainsKey('DeleteBranchOnMerge')) { $hashBody['delete_branch_on_merge'] = $DeleteBranchOnMerge.ToBool() } + if ($PSBoundParameters.ContainsKey('IsTemplate')) { $hashBody['is_template'] = $IsTemplate.ToBool() } if ($PSBoundParameters.ContainsKey('Archived')) { $hashBody['archived'] = $Archived.ToBool() } $params = @{ From b2ee25d36ffcb8c0c4dc84126d5f6322f3ce8094 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Sun, 31 May 2020 11:01:54 +0100 Subject: [PATCH 2/8] Add Nebula/Baptiste Accept Header --- GitHubRepositories.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 5fe026cc..b9691f79 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -187,7 +187,8 @@ function New-GitHubRepository 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Post' - 'Description' = "Creating $RepositoryName" + 'AcceptHeader' = "$script:nebulaAcceptHeader,$script:baptisteAcceptHeader" + 'Description' = "Creating $RepositoryName" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name 'TelemetryProperties' = $telemetryProperties From 4c5b5c1d04aa9d30b2b8d8e97c9c39c832398052 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 2 Jun 2020 16:53:57 +0100 Subject: [PATCH 3/8] Review Updates --- GitHubRepositories.ps1 | 61 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index b9691f79..8502cb41 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -40,11 +40,15 @@ function New-GitHubRepository This is only valid when creating a repository in an organization. .PARAMETER Private - By default, this repository will be created Public. Specify this to create - a private repository. + By default, this repository will be created Public. Specify this to create a private + repository. This parameter controls the same setting as the 'Visibility' parameter and only + one should be specified. This parameter will be deprecated in a future release. .PARAMETER Visibility - Specifies the visibility level of the repository. + Specifies the visibility level of the repository. This controls the same setting as + the 'Private' parameter and only one should be specified. Internal is only available if + your organization is associated with an enterprise account using GitHub Enterprise Cloud + or GitHub Enterprise Server 2.20+ .PARAMETER NoIssues By default, this repository will support Issues. Specify this to disable Issues. @@ -147,6 +151,24 @@ function New-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } + if ($PSBoundParameters.ContainsKey('Private')) + { + Write-Log -Level Warning -Message ('The Private switch is being replaced by the Visibility parameter. ' + + 'Please update any scripts/usage that you may have to migrate to the Visibility parameter, ' + + 'as the Private switch will be replaced in a future update.') + + if ($PSBoundParameters.ContainsKey('Visibility')) + { + if (($Private -and ($Visibility -ne 'Private')) -or ((-not $Private) -and ($Visibility -ne 'Public'))) + { + $message = ('The Private and Visibility parameters control the same repo property. ' + + 'If both are specified, their values must be the same.') + Write-Log -Message $message -Level Error + throw $message + } + } + } + $uriFragment = 'user/repos' if ($PSBoundParameters.ContainsKey('OrganizationName') -and (-not [String]::IsNullOrEmpty($OrganizationName))) @@ -172,7 +194,7 @@ function New-GitHubRepository if ($PSBoundParameters.ContainsKey('LicenseTemplate')) { $hashBody['license_template'] = $LicenseTemplate } if ($PSBoundParameters.ContainsKey('TeamId')) { $hashBody['team_id'] = $TeamId } if ($PSBoundParameters.ContainsKey('Private')) { $hashBody['private'] = $Private.ToBool() } - if ($PSBoundParameters.ContainsKey('Visibility')) { $hashBody['visibility'] = $Visibility } + if ($PSBoundParameters.ContainsKey('Visibility')) { $hashBody['visibility'] = $Visibility.ToLower() } if ($PSBoundParameters.ContainsKey('NoIssues')) { $hashBody['has_issues'] = (-not $NoIssues.ToBool()) } if ($PSBoundParameters.ContainsKey('NoProjects')) { $hashBody['has_projects'] = (-not $NoProjects.ToBool()) } if ($PSBoundParameters.ContainsKey('NoWiki')) { $hashBody['has_wiki'] = (-not $NoWiki.ToBool()) } @@ -730,11 +752,16 @@ function Update-GitHubRepository Update the default branch for this repository. .PARAMETER Private - Specify this to make the repository private. - To change a repository to be public, specify -Private:$false + Specify this to make the repository private. To change a repository to be public, + specify -Private:$false. This parameter controls the same setting as the 'Visibility' + parameter and only one should be specified. This parameter will be deprecated in a future + release. .PARAMETER Visibility - Specifies the visibility level of the repository. + Specifies the visibility level of the repository. This controls the same setting as + the 'Private' parameter and only one should be specified. Internal is only available if + your organization is associated with an enterprise account using GitHub Enterprise Cloud + or GitHub Enterprise Server 2.20+ .PARAMETER NoIssues By default, this repository will support Issues. Specify this to disable Issues. @@ -846,6 +873,24 @@ function Update-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } + if ($PSBoundParameters.ContainsKey('Private')) + { + Write-Log -Level Warning -Message ('The Private switch is being replaced by the Visibility parameter. ' + + 'Please update any scripts/usage that you may have to migrate to the Visibility parameter, ' + + 'as the Private switch will be replaced in a future update.') + + if ($PSBoundParameters.ContainsKey('Visibility')) + { + if (($Private -and ($Visibility -ne 'Private')) -or ((-not $Private) -and ($Visibility -ne 'Public'))) + { + $message = ('The Private and Visibility parameters control the same repo property. ' + + 'If both are specified, their values must be the same.') + Write-Log -Message $message -Level Error + throw $message + } + } + } + $hashBody = @{ 'name' = $RepositoryName } @@ -854,7 +899,7 @@ function Update-GitHubRepository if ($PSBoundParameters.ContainsKey('Homepage')) { $hashBody['homepage'] = $Homepage } if ($PSBoundParameters.ContainsKey('DefaultBranch')) { $hashBody['default_branch'] = $DefaultBranch } if ($PSBoundParameters.ContainsKey('Private')) { $hashBody['private'] = $Private.ToBool() } - if ($PSBoundParameters.ContainsKey('Visibility')) { $hashBody['visibility'] = $Visibility } + if ($PSBoundParameters.ContainsKey('Visibility')) { $hashBody['visibility'] = $Visibility.ToLower() } if ($PSBoundParameters.ContainsKey('NoIssues')) { $hashBody['has_issues'] = (-not $NoIssues.ToBool()) } if ($PSBoundParameters.ContainsKey('NoProjects')) { $hashBody['has_projects'] = (-not $NoProjects.ToBool()) } if ($PSBoundParameters.ContainsKey('NoWiki')) { $hashBody['has_wiki'] = (-not $NoWiki.ToBool()) } From 71e175c2c442812fc1b9ece935b2cd3553ba9640 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 2 Jun 2020 18:04:47 +0100 Subject: [PATCH 4/8] Update review comments --- GitHubRepositories.ps1 | 10 +++++++--- Tests/GitHubRepositories.tests.ps1 | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 2c3fa4b5..ec3d40a1 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -155,7 +155,7 @@ function New-GitHubRepository { Write-Log -Level Warning -Message ('The Private switch is being replaced by the Visibility parameter. ' + 'Please update any scripts/usage that you may have to migrate to the Visibility parameter, ' + - 'as the Private switch will be replaced in a future update.') + 'as the Private switch will be deprecated in a future update.') if ($PSBoundParameters.ContainsKey('Visibility')) { @@ -816,8 +816,12 @@ function Update-GitHubRepository .EXAMPLE Update-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 + Update-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -Visibility 'Private' + + Changes the visibility of the specified repository to 'Private'. #> [CmdletBinding( SupportsShouldProcess, @@ -884,7 +888,7 @@ function Update-GitHubRepository { Write-Log -Level Warning -Message ('The Private switch is being replaced by the Visibility parameter. ' + 'Please update any scripts/usage that you may have to migrate to the Visibility parameter, ' + - 'as the Private switch will be replaced in a future update.') + 'as the Private switch will be deprecated in a future update.') if ($PSBoundParameters.ContainsKey('Visibility')) { diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index e2f4d99d..3e1c6dd3 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -18,7 +18,7 @@ try Context 'For authenticated user' { BeforeAll -Scriptblock { $publicRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $privateRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private + $privateRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Visibility Private # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments $publicRepo = $publicRepo From d40424797cce770f210a15050e5672f6e8b0fd18 Mon Sep 17 00:00:00 2001 From: Simon Heather <32168619+X-Guardian@users.noreply.github.com> Date: Tue, 2 Jun 2020 21:08:05 +0100 Subject: [PATCH 5/8] Update GitHubRepositories.ps1 Co-authored-by: Howard Wolosky --- GitHubRepositories.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index ec3d40a1..7aedf5b8 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -819,9 +819,9 @@ function Update-GitHubRepository Changes the description of the specified repository. .EXAMPLE - Update-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -Visibility 'Private' + Update-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -Visibility 'Public' - Changes the visibility of the specified repository to 'Private'. + Changes the visibility of the specified repository to be public. #> [CmdletBinding( SupportsShouldProcess, From b0711df6856d2e5c2be6df8dd9a096ce531e60ad Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Tue, 2 Jun 2020 23:42:50 +0100 Subject: [PATCH 6/8] Add Update-GitHubRepository AcceptHeader --- GitHubRepositories.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index 42ca17b5..c954482c 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -925,6 +925,7 @@ function Update-GitHubRepository 'UriFragment' = "repos/$OwnerName/$RepositoryName" 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Patch' + 'AcceptHeader' = "$script:nebulaAcceptHeader,$script:baptisteAcceptHeader" 'Description' = "Updating $RepositoryName" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name From c2d60c095a0d3f7bf8ace9b74856e90b92e8e952 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Wed, 3 Jun 2020 07:41:30 +0100 Subject: [PATCH 7/8] Remove Visibility parameter --- GitHubRepositories.ps1 | 73 +++--------------------------- Tests/GitHubRepositories.tests.ps1 | 2 +- 2 files changed, 8 insertions(+), 67 deletions(-) diff --git a/GitHubRepositories.ps1 b/GitHubRepositories.ps1 index c954482c..97f76c43 100644 --- a/GitHubRepositories.ps1 +++ b/GitHubRepositories.ps1 @@ -40,15 +40,8 @@ function New-GitHubRepository This is only valid when creating a repository in an organization. .PARAMETER Private - By default, this repository will be created Public. Specify this to create a private - repository. This parameter controls the same setting as the 'Visibility' parameter and only - one should be specified. This parameter will be deprecated in a future release. - - .PARAMETER Visibility - Specifies the visibility level of the repository. This controls the same setting as - the 'Private' parameter and only one should be specified. Internal is only available if - your organization is associated with an enterprise account using GitHub Enterprise Cloud - or GitHub Enterprise Server 2.20+ + By default, this repository will be created Public. Specify this to create + a private repository. .PARAMETER NoIssues By default, this repository will support Issues. Specify this to disable Issues. @@ -119,9 +112,6 @@ function New-GitHubRepository [switch] $Private, - [ValidateSet('Public', 'Private', 'Internal')] - [string] $Visibility, - [switch] $NoIssues, [switch] $NoProjects, @@ -151,24 +141,6 @@ function New-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($PSBoundParameters.ContainsKey('Private')) - { - Write-Log -Level Warning -Message ('The Private switch is being replaced by the Visibility parameter. ' + - 'Please update any scripts/usage that you may have to migrate to the Visibility parameter, ' + - 'as the Private switch will be deprecated in a future update.') - - if ($PSBoundParameters.ContainsKey('Visibility')) - { - if (($Private -and ($Visibility -ne 'Private')) -or ((-not $Private) -and ($Visibility -ne 'Public'))) - { - $message = ('The Private and Visibility parameters control the same repo property. ' + - 'If both are specified, their values must be the same.') - Write-Log -Message $message -Level Error - throw $message - } - } - } - $uriFragment = 'user/repos' if ($PSBoundParameters.ContainsKey('OrganizationName') -and (-not [String]::IsNullOrEmpty($OrganizationName))) @@ -194,7 +166,6 @@ function New-GitHubRepository if ($PSBoundParameters.ContainsKey('LicenseTemplate')) { $hashBody['license_template'] = $LicenseTemplate } if ($PSBoundParameters.ContainsKey('TeamId')) { $hashBody['team_id'] = $TeamId } if ($PSBoundParameters.ContainsKey('Private')) { $hashBody['private'] = $Private.ToBool() } - if ($PSBoundParameters.ContainsKey('Visibility')) { $hashBody['visibility'] = $Visibility.ToLower() } if ($PSBoundParameters.ContainsKey('NoIssues')) { $hashBody['has_issues'] = (-not $NoIssues.ToBool()) } if ($PSBoundParameters.ContainsKey('NoProjects')) { $hashBody['has_projects'] = (-not $NoProjects.ToBool()) } if ($PSBoundParameters.ContainsKey('NoWiki')) { $hashBody['has_wiki'] = (-not $NoWiki.ToBool()) } @@ -209,7 +180,7 @@ function New-GitHubRepository 'UriFragment' = $uriFragment 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Post' - 'AcceptHeader' = "$script:nebulaAcceptHeader,$script:baptisteAcceptHeader" + 'AcceptHeader' = $script:baptisteAcceptHeader 'Description' = "Creating $RepositoryName" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name @@ -759,16 +730,8 @@ function Update-GitHubRepository Update the default branch for this repository. .PARAMETER Private - Specify this to make the repository private. To change a repository to be public, - specify -Private:$false. This parameter controls the same setting as the 'Visibility' - parameter and only one should be specified. This parameter will be deprecated in a future - release. - - .PARAMETER Visibility - Specifies the visibility level of the repository. This controls the same setting as - the 'Private' parameter and only one should be specified. Internal is only available if - your organization is associated with an enterprise account using GitHub Enterprise Cloud - or GitHub Enterprise Server 2.20+ + Specify this to make the repository private. + To change a repository to be public, specify -Private:$false .PARAMETER NoIssues By default, this repository will support Issues. Specify this to disable Issues. @@ -819,7 +782,7 @@ function Update-GitHubRepository Changes the description of the specified repository. .EXAMPLE - Update-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -Visibility 'Public' + Update-GitHubRepository -Uri https://github.com/PowerShell/PowerShellForGitHub -Private:$false Changes the visibility of the specified repository to be public. #> @@ -847,9 +810,6 @@ function Update-GitHubRepository [switch] $Private, - [ValidateSet('Public', 'Private', 'Internal')] - [string] $Visibility, - [switch] $NoIssues, [switch] $NoProjects, @@ -884,24 +844,6 @@ function Update-GitHubRepository 'RepositoryName' = (Get-PiiSafeString -PlainText $RepositoryName) } - if ($PSBoundParameters.ContainsKey('Private')) - { - Write-Log -Level Warning -Message ('The Private switch is being replaced by the Visibility parameter. ' + - 'Please update any scripts/usage that you may have to migrate to the Visibility parameter, ' + - 'as the Private switch will be deprecated in a future update.') - - if ($PSBoundParameters.ContainsKey('Visibility')) - { - if (($Private -and ($Visibility -ne 'Private')) -or ((-not $Private) -and ($Visibility -ne 'Public'))) - { - $message = ('The Private and Visibility parameters control the same repo property. ' + - 'If both are specified, their values must be the same.') - Write-Log -Message $message -Level Error - throw $message - } - } - } - $hashBody = @{ 'name' = $RepositoryName } @@ -910,7 +852,6 @@ function Update-GitHubRepository if ($PSBoundParameters.ContainsKey('Homepage')) { $hashBody['homepage'] = $Homepage } if ($PSBoundParameters.ContainsKey('DefaultBranch')) { $hashBody['default_branch'] = $DefaultBranch } if ($PSBoundParameters.ContainsKey('Private')) { $hashBody['private'] = $Private.ToBool() } - if ($PSBoundParameters.ContainsKey('Visibility')) { $hashBody['visibility'] = $Visibility.ToLower() } if ($PSBoundParameters.ContainsKey('NoIssues')) { $hashBody['has_issues'] = (-not $NoIssues.ToBool()) } if ($PSBoundParameters.ContainsKey('NoProjects')) { $hashBody['has_projects'] = (-not $NoProjects.ToBool()) } if ($PSBoundParameters.ContainsKey('NoWiki')) { $hashBody['has_wiki'] = (-not $NoWiki.ToBool()) } @@ -925,7 +866,7 @@ function Update-GitHubRepository 'UriFragment' = "repos/$OwnerName/$RepositoryName" 'Body' = (ConvertTo-Json -InputObject $hashBody) 'Method' = 'Patch' - 'AcceptHeader' = "$script:nebulaAcceptHeader,$script:baptisteAcceptHeader" + 'AcceptHeader' = $script:baptisteAcceptHeader 'Description' = "Updating $RepositoryName" 'AccessToken' = $AccessToken 'TelemetryEventName' = $MyInvocation.MyCommand.Name diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 3e1c6dd3..e2f4d99d 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -18,7 +18,7 @@ try Context 'For authenticated user' { BeforeAll -Scriptblock { $publicRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - $privateRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Visibility Private + $privateRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments $publicRepo = $publicRepo From 5c0d45fadf7524b2ce0cb5f09ee93a905b3fd453 Mon Sep 17 00:00:00 2001 From: Simon Heather Date: Thu, 4 Jun 2020 18:33:34 +0100 Subject: [PATCH 8/8] Update GitHubRepositories tests --- Tests/GitHubRepositories.tests.ps1 | 456 ++++++++++++++++++++++++----- 1 file changed, 387 insertions(+), 69 deletions(-) diff --git a/Tests/GitHubRepositories.tests.ps1 b/Tests/GitHubRepositories.tests.ps1 index 76c2f9b7..b580c763 100644 --- a/Tests/GitHubRepositories.tests.ps1 +++ b/Tests/GitHubRepositories.tests.ps1 @@ -6,6 +6,11 @@ Tests for GitHubRepositories.ps1 module #> +[CmdletBinding()] +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', + Justification='Suppress false positives in Pester code blocks')] +param() + # This is common test code setup logic for all Pester test files $moduleRootPath = Split-Path -Path $PSScriptRoot -Parent . (Join-Path -Path $moduleRootPath -ChildPath 'Tests\Common.ps1') @@ -21,15 +26,275 @@ try Set-Variable -Force -Scope Script -Option ReadOnly -Visibility Private -Name $_.Key -Value $_.Value } + Describe 'GitHubRepositories\New-GitHubRepository' { + + Context -Name 'When creating a repository for the authenticated user' -Fixture { + + Context -Name 'When creating a public repository with default settings' -Fixture { + BeforeAll -ScriptBlock { + $repoName = ([Guid]::NewGuid().Guid) + $newGitHubRepositoryParms = @{ + RepositoryName = $repoName + } + $repo = New-GitHubRepository @newGitHubRepositoryParms + } + + It 'Should return an object of the correct type' { + $repo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $repo.name | Should -Be $repoName + $repo.private | Should -BeFalse + $repo.description | Should -BeNullOrEmpty + $repo.homepage | Should -BeNullOrEmpty + $repo.has_issues | Should -BeTrue + $repo.has_projects | Should -BeTrue + $repo.has_Wiki | Should -BeTrue + $repo.allow_squash_merge | Should -BeTrue + $repo.allow_merge_commit | Should -BeTrue + $repo.allow_rebase_merge | Should -BeTrue + $repo.delete_branch_on_merge | Should -BeFalse + $repo.is_template | Should -BeFalse + } + + AfterAll -ScriptBlock { + if ($repo) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + } + } + + Context -Name 'When creating a private repository with default settings' -Fixture { + BeforeAll -ScriptBlock { + $repoName = ([Guid]::NewGuid().Guid) + $newGitHubRepositoryParms = @{ + RepositoryName = $repoName + Private = $true + } + $repo = New-GitHubRepository @newGitHubRepositoryParms + } + + It 'Should return an object of the correct type' { + $repo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $repo.name | Should -Be $repoName + $repo.private | Should -BeTrue + $repo.description | Should -BeNullOrEmpty + $repo.homepage | Should -BeNullOrEmpty + $repo.has_issues | Should -BeTrue + $repo.has_projects | Should -BeTrue + $repo.has_Wiki | Should -BeTrue + $repo.allow_squash_merge | Should -BeTrue + $repo.allow_merge_commit | Should -BeTrue + $repo.allow_rebase_merge | Should -BeTrue + $repo.delete_branch_on_merge | Should -BeFalse + $repo.is_template | Should -BeFalse + } + + AfterAll -ScriptBlock { + if ($repo) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + } + } + + Context -Name 'When creating a repository with all possible settings' -Fixture { + BeforeAll -ScriptBlock { + $repoName = ([Guid]::NewGuid().Guid) + $testGitIgnoreTemplate=(Get-GitHubGitIgnore)[0] + $testLicenseTemplate=(Get-GitHubLicense)[0].key + + $newGitHubRepositoryParms = @{ + RepositoryName = $repoName + Description = $defaultRepoDesc + HomePage = $defaultRepoHomePage + NoIssues = $true + NoProjects = $true + NoWiki = $true + DisallowSquashMerge = $true + DisallowMergeCommit = $true + DisallowRebaseMerge = $false + DeleteBranchOnMerge = $true + GitIgnoreTemplate = $testGitIgnoreTemplate + LicenseTemplate = $testLicenseTemplate + IsTemplate = $true + } + $repo = New-GitHubRepository @newGitHubRepositoryParms + } + + It 'Should return an object of the correct type' { + $repo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $repo.name | Should -Be $repoName + $repo.description | Should -Be $defaultRepoDesc + $repo.homepage | Should -Be $defaultRepoHomePage + $repo.has_issues | Should -BeFalse + $repo.has_projects | Should -BeFalse + $repo.has_Wiki | Should -BeFalse + $repo.allow_squash_merge | Should -BeFalse + $repo.allow_merge_commit | Should -BeFalse + $repo.allow_rebase_merge | Should -BeTrue + $repo.delete_branch_on_merge | Should -BeTrue + $repo.is_template | Should -BeTrue + } + + It 'Should have created a .gitignore file' { + { Get-GitHubContent -Uri $repo.svn_url -Path '.gitignore' } | Should -Not -Throw + } + + It 'Should have created a LICENSE file' { + { Get-GitHubContent -Uri $repo.svn_url -Path 'LICENSE' } | Should -Not -Throw + } + + AfterAll -ScriptBlock { + if ($repo) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + } + } + + Context -Name 'When creating a repository with alternative Merge settings' -Fixture { + BeforeAll -ScriptBlock { + $repoName = ([Guid]::NewGuid().Guid) + $newGitHubRepositoryParms = @{ + RepositoryName = $repoName + DisallowSquashMerge = $true + DisallowMergeCommit = $false + DisallowRebaseMerge = $true + } + $repo = New-GitHubRepository @newGitHubRepositoryParms + } + + It 'Should return an object of the correct type' { + $repo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $repo.name | Should -Be $repoName + $repo.allow_squash_merge | Should -BeFalse + $repo.allow_merge_commit | Should -BeTrue + $repo.allow_rebase_merge | Should -BeFalse + } + + AfterAll -ScriptBlock { + if ($repo) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + } + } + + Context -Name 'When a TeamID is specified' -Fixture { + BeforeAll -ScriptBlock { + $repoName = ([Guid]::NewGuid().Guid) + $mockTeamID=1 + $newGitHubRepositoryParms = @{ + RepositoryName = $repoName + TeamID = $mockTeamID + } + } + + It 'Should throw the correct exception' { + $errorMessage = 'TeamId may only be specified when creating a repository under an organization.' + { New-GitHubRepository @newGitHubRepositoryParms } | Should -Throw $errorMessage + } + } + } + + Context -Name 'When creating an organization repository' -Fixture { + + Context -Name 'When creating a public repository with default settings' -Fixture { + BeforeAll -ScriptBlock { + $repoName = ([Guid]::NewGuid().Guid) + $newGitHubRepositoryParms = @{ + RepositoryName = $repoName + OrganizationName = $script:organizationName + } + $repo = New-GitHubRepository @newGitHubRepositoryParms + } + + It 'Should return an object of the correct type' { + $repo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $repo.name | Should -Be $repoName + $repo.private | Should -BeFalse + $repo.organization.login | Should -Be $script:organizationName + $repo.description | Should -BeNullOrEmpty + $repo.homepage | Should -BeNullOrEmpty + $repo.has_issues | Should -BeTrue + $repo.has_projects | Should -BeTrue + $repo.has_Wiki | Should -BeTrue + $repo.allow_squash_merge | Should -BeTrue + $repo.allow_merge_commit | Should -BeTrue + $repo.allow_rebase_merge | Should -BeTrue + $repo.delete_branch_on_merge | Should -BeFalse + $repo.is_template | Should -BeFalse + } + + AfterAll -ScriptBlock { + if ($repo) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + } + } + + Context -Name 'When creating a private repository with default settings' -Fixture { + BeforeAll -ScriptBlock { + $repoName = ([Guid]::NewGuid().Guid) + $newGitHubRepositoryParms = @{ + RepositoryName = $repoName + Private = $true + OrganizationName = $script:organizationName + } + $repo = New-GitHubRepository @newGitHubRepositoryParms + } + + It 'Should return an object of the correct type' { + $repo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $repo.name | Should -Be $repoName + $repo.private | Should -BeTrue + $repo.organization.login | Should -Be $script:organizationName + $repo.description | Should -BeNullOrEmpty + $repo.homepage | Should -BeNullOrEmpty + $repo.has_issues | Should -BeTrue + $repo.has_projects | Should -BeTrue + $repo.has_Wiki | Should -BeTrue + $repo.allow_squash_merge | Should -BeTrue + $repo.allow_merge_commit | Should -BeTrue + $repo.allow_rebase_merge | Should -BeTrue + $repo.delete_branch_on_merge | Should -BeFalse + $repo.is_template | Should -BeFalse + } + + AfterAll -ScriptBlock { + if ($repo) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + } + } + } + } + Describe 'Getting repositories' { Context 'For authenticated user' { BeforeAll -Scriptblock { $publicRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $privateRepo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit -Private - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $publicRepo = $publicRepo - $privateRepo = $privateRepo } It "Should have the public repo" { @@ -68,9 +333,6 @@ try Context 'For organizations' { BeforeAll -Scriptblock { $repo = New-GitHubRepository -OrganizationName $script:organizationName -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } It "Should have results for the organization" { @@ -91,9 +353,6 @@ try Context 'For a specific repo' { BeforeAll -ScriptBlock { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } It "Should be a single result using Uri ParameterSet" { @@ -121,44 +380,11 @@ try } } - Describe 'Creating repositories' { - - Context -Name 'For creating a repository' -Fixture { - BeforeAll -ScriptBlock { - $repoName = ([Guid]::NewGuid().Guid) - $repo = New-GitHubRepository -RepositoryName $repoName -Description $defaultRepoDesc -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repoName = $repoName - $repo = $repo - } - - It 'Should get repository' { - $repo | Should -Not -BeNullOrEmpty - } - - It 'Name is correct' { - $repo.name | Should -Be $repoName - } - - It 'Description is correct' { - $repo.description | Should -Be $defaultRepoDesc - } - - AfterAll -ScriptBlock { - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false - } - } - } - Describe 'Deleting repositories' { Context -Name 'For deleting a repository' -Fixture { BeforeAll -ScriptBlock { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -Description $defaultRepoDesc -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } It 'Should get no content' { @@ -175,9 +401,6 @@ try $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit $suffixToAddToRepo = "_renamed" $newRepoName = "$($repo.name)$suffixToAddToRepo" - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $newRepoName = $newRepoName } It "Should have the expected new repository name - by URI" { @@ -196,29 +419,133 @@ try } } - Describe 'Updating repositories' { + Describe 'GitHubRepositories\Update-GitHubRepository' { - Context -Name 'For creating a repository' -Fixture { + Context -Name 'When updating a public repository' -Fixture { BeforeAll -ScriptBlock { - $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -Description $defaultRepoDesc -AutoInit + $repoName = ([Guid]::NewGuid().Guid) + $repo = New-GitHubRepository -RepositoryName $repoName + } + + Context -Name 'When updating a repository with all possible settings' { + BeforeAll -ScriptBlock { + $updateGithubRepositoryParms = @{ + OwnerName = $repo.owner.login + RepositoryName = $repoName + Private = $true + Description = $defaultRepoDesc + HomePage = $defaultRepoHomePage + NoIssues = $true + NoProjects = $true + NoWiki = $true + DisallowSquashMerge = $true + DisallowMergeCommit = $true + DisallowRebaseMerge = $false + DeleteBranchOnMerge = $true + IsTemplate = $true + } + $updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms + } + + It 'Should return an object of the correct type' { + $updatedRepo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $updatedRepo.name | Should -Be $repoName + $updatedRepo.private | Should -BeTrue + $updatedRepo.description | Should -Be $defaultRepoDesc + $updatedRepo.homepage | Should -Be $defaultRepoHomePage + $updatedRepo.has_issues | Should -BeFalse + $updatedRepo.has_projects | Should -BeFalse + $updatedRepo.has_Wiki | Should -BeFalse + $updatedRepo.allow_squash_merge | Should -BeFalse + $updatedRepo.allow_merge_commit | Should -BeFalse + $updatedRepo.allow_rebase_merge | Should -BeTrue + $updatedRepo.delete_branch_on_merge | Should -BeTrue + $updatedRepo.is_template | Should -BeTrue + } + } + + Context -Name 'When updating a repository with alternative Merge settings' { + BeforeAll -ScriptBlock { + $updateGithubRepositoryParms = @{ + OwnerName = $repo.owner.login + RepositoryName = $repoName + DisallowSquashMerge = $true + DisallowMergeCommit = $false + DisallowRebaseMerge = $true + } + $updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms + } + + It 'Should return an object of the correct type' { + $updatedRepo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $updatedRepo.name | Should -Be $repoName + $updatedRepo.allow_squash_merge | Should -BeFalse + $updatedRepo.allow_merge_commit | Should -BeTrue + $updatedRepo.allow_rebase_merge | Should -BeFalse + } + } + + Context -Name 'When updating a repository with the Archive setting' { + BeforeAll -ScriptBlock { + $updateGithubRepositoryParms = @{ + OwnerName = $repo.owner.login + RepositoryName = $repoName + Archived = $true + } + $updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms + } + + It 'Should return an object of the correct type' { + $updatedRepo | Should -BeOfType PSCustomObject + } + + It 'Should return the correct properties' { + $updatedRepo.name | Should -Be $repoName + $updatedRepo.archived | Should -BeTrue + } + } - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo + AfterAll -ScriptBlock { + if ($repo) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } + } + } + + Context -Name 'When updating a private repository' -Fixture { + BeforeAll -ScriptBlock { + $repoName = ([Guid]::NewGuid().Guid) + $repo = New-GitHubRepository -RepositoryName $repoName -Private + + $updateGithubRepositoryParms = @{ + OwnerName = $repo.owner.login + RepositoryName = $repoName + Private = $false + } + $updatedRepo = Update-GitHubRepository @updateGithubRepositoryParms } - It 'Should have the new updated description' { - $modifiedRepoDesc = $defaultRepoDesc + "_modified" - $updatedRepo = Update-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Description $modifiedRepoDesc - $updatedRepo.description | Should -Be $modifiedRepoDesc + It 'Should return an object of the correct type' { + $updatedRepo | Should -BeOfType PSCustomObject } - It 'Should have the new updated homepage url' { - $updatedRepo = Update-GitHubRepository -OwnerName $repo.owner.login -RepositoryName $repo.name -Homepage $defaultRepoHomePage - $updatedRepo.homepage | Should -Be $defaultRepoHomePage + It 'Should return the correct properties' { + $updatedRepo.name | Should -Be $repoName + $updatedRepo.private | Should -BeFalse } AfterAll -ScriptBlock { - Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + if ($repo) + { + Remove-GitHubRepository -Uri $repo.svn_url -Confirm:$false + } } } } @@ -228,9 +555,6 @@ try Context -Name 'For creating and getting a repository topic' -Fixture { BeforeAll -ScriptBlock { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } It 'Should have the expected topic' { @@ -256,9 +580,6 @@ try Context -Name 'For getting repository languages' -Fixture { BeforeAll -ScriptBlock { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } It 'Should be empty' { @@ -282,9 +603,6 @@ try Context -Name 'For getting repository tags' -Fixture { BeforeAll -ScriptBlock { $repo = New-GitHubRepository -RepositoryName ([Guid]::NewGuid().Guid) -AutoInit - - # Avoid PSScriptAnalyzer PSUseDeclaredVarsMoreThanAssignments - $repo = $repo } It 'Should be empty' { @@ -306,4 +624,4 @@ finally Restore-GitHubConfiguration -Path $script:originalConfigFile $script:originalConfigFile = $null } -} +} \ No newline at end of file