Skip to content

GitHubRepositories: Add Additional Parameters #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 9, 2020
Merged
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c67b279
Update GitHubRepositories.ps1
X-Guardian May 28, 2020
dfd95ca
Merge branch 'master' into GitHubRepository-Add-Properties
X-Guardian May 29, 2020
e5cc1fa
Merge branch 'master' into GitHubRepository-Add-Properties
X-Guardian May 29, 2020
738da43
Merge branch 'master' into GitHubRepository-Add-Properties
X-Guardian May 31, 2020
b2ee25d
Add Nebula/Baptiste Accept Header
X-Guardian May 31, 2020
0661a98
Merge branch 'GitHubRepository-Add-Properties' of https://github.com/…
X-Guardian May 31, 2020
b0026e4
Merge branch 'master' into GitHubRepository-Add-Properties
HowardWolosky May 31, 2020
aec7d0d
Merge branch 'master' into GitHubRepository-Add-Properties
HowardWolosky Jun 1, 2020
6e1e5de
Merge branch 'master' into GitHubRepository-Add-Properties
X-Guardian Jun 1, 2020
4bed23f
Merge branch 'master' into GitHubRepository-Add-Properties
HowardWolosky Jun 1, 2020
4c5b5c1
Review Updates
X-Guardian Jun 2, 2020
8787afd
Merge branch 'GitHubRepository-Add-Properties' of https://github.com/…
X-Guardian Jun 2, 2020
18a5235
Merge branch 'master' into GitHubRepository-Add-Properties
X-Guardian Jun 2, 2020
71e175c
Update review comments
X-Guardian Jun 2, 2020
d404247
Update GitHubRepositories.ps1
X-Guardian Jun 2, 2020
06b1cff
Merge branch 'master' into GitHubRepository-Add-Properties
X-Guardian Jun 2, 2020
b0711df
Add Update-GitHubRepository AcceptHeader
X-Guardian Jun 2, 2020
c2d60c0
Remove Visibility parameter
X-Guardian Jun 3, 2020
19020e5
Merge branch 'master' into GitHubRepository-Add-Properties
HowardWolosky Jun 4, 2020
5c0d45f
Update GitHubRepositories tests
X-Guardian Jun 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 89 additions & 5 deletions GitHubRepositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ 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
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. 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.
Expand Down Expand Up @@ -69,6 +76,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 @@ -106,6 +119,9 @@ function New-GitHubRepository

[switch] $Private,

[ValidateSet('Public', 'Private', 'Internal')]
[string] $Visibility,

[switch] $NoIssues,

[switch] $NoProjects,
Expand All @@ -120,6 +136,10 @@ function New-GitHubRepository

[switch] $DisallowRebaseMerge,

[switch] $DeleteBranchOnMerge,

[switch] $IsTemplate,

[string] $AccessToken,

[switch] $NoStatus
Expand All @@ -131,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)))
Expand All @@ -156,19 +194,23 @@ 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()) }
if ($PSBoundParameters.ContainsKey('AutoInit')) { $hashBody['auto_init'] = $AutoInit.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() }

$params = @{
'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
Expand Down Expand Up @@ -717,8 +759,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. 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.
Expand All @@ -743,6 +793,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 Down Expand Up @@ -787,6 +843,9 @@ function Update-GitHubRepository

[switch] $Private,

[ValidateSet('Public', 'Private', 'Internal')]
[string] $Visibility,

[switch] $NoIssues,

[switch] $NoProjects,
Expand All @@ -799,6 +858,10 @@ function Update-GitHubRepository

[switch] $DisallowRebaseMerge,

[switch] $DeleteBranchOnMerge,

[switch] $IsTemplate,

[switch] $Archived,

[string] $AccessToken,
Expand All @@ -817,6 +880,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
}
Expand All @@ -825,12 +906,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.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()) }
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 = @{
Expand Down