Skip to content

Commit

Permalink
GitHubRepositories: Add Additional Parameters (#192)
Browse files Browse the repository at this point in the history
This PR adds the following parameters to the `New-GitHubRepository` and `Update-GitHubRepository` functions:

- DeleteBranchOnMerge
- IsTemplate

It also adds substantial UT's to verify these changes.

Fixes #189
  • Loading branch information
X-Guardian authored Jun 9, 2020
1 parent 742b853 commit ef246cd
Show file tree
Hide file tree
Showing 2 changed files with 419 additions and 71 deletions.
34 changes: 32 additions & 2 deletions GitHubRepositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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 NoIssues
Expand Down Expand Up @@ -69,6 +69,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.
Expand Down Expand Up @@ -120,6 +126,10 @@ function New-GitHubRepository

[switch] $DisallowRebaseMerge,

[switch] $DeleteBranchOnMerge,

[switch] $IsTemplate,

[string] $AccessToken,

[switch] $NoStatus
Expand Down Expand Up @@ -163,12 +173,15 @@ 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
'Body' = (ConvertTo-Json -InputObject $hashBody)
'Method' = 'Post'
'Description' = "Creating $RepositoryName"
'AcceptHeader' = $script:baptisteAcceptHeader
'Description' = "Creating $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
'TelemetryProperties' = $telemetryProperties
Expand Down Expand Up @@ -743,6 +756,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.
Expand All @@ -760,8 +779,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
Changes the visibility of the specified repository to be public.
#>
[CmdletBinding(
SupportsShouldProcess,
Expand Down Expand Up @@ -799,6 +822,10 @@ function Update-GitHubRepository

[switch] $DisallowRebaseMerge,

[switch] $DeleteBranchOnMerge,

[switch] $IsTemplate,

[switch] $Archived,

[string] $AccessToken,
Expand Down Expand Up @@ -831,12 +858,15 @@ function Update-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() }
if ($PSBoundParameters.ContainsKey('Archived')) { $hashBody['archived'] = $Archived.ToBool() }

$params = @{
'UriFragment' = "repos/$OwnerName/$RepositoryName"
'Body' = (ConvertTo-Json -InputObject $hashBody)
'Method' = 'Patch'
'AcceptHeader' = $script:baptisteAcceptHeader
'Description' = "Updating $RepositoryName"
'AccessToken' = $AccessToken
'TelemetryEventName' = $MyInvocation.MyCommand.Name
Expand Down
Loading

0 comments on commit ef246cd

Please sign in to comment.