Skip to content
111 changes: 111 additions & 0 deletions GitHubRepositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@
Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value
}

$squashMergeCommitTitleConversion = @{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a module style perspective, the preference is that all script-level variables are used the following way:

  • References to them should explicitly include the $script: to make it clear where they come from
  • Should be SentenceCased
  • The should be read-only unless there's a good reason otherwise (e.g. being used to cache data)

We have the convenience creator at the top of the file to make those read-only script-level variables. So, you can do something like this in there for these:

{
    # ... cut for brevity
    GitHubRepositoryTeamPermissionTypeName = 'GitHub.RepositoryTeamPermission'
    SquashMergeCommitTitleConversion = @{
        'PRTitle' = 'PR_TITLE'
        'CommitOrPRTitle' = 'COMMIT_OR_PR_TITLE'
        'MergeMessage' = 'MERGE_MESSAGE'
    }
    # ... and the next one, etc...
 }.GetEnumerator() | ForEach-Object {
     Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'PRTitle' = 'PR_TITLE'
'CommitOrPRTitle' = 'COMMIT_OR_PR_TITLE'
'MergeMessage' = 'MERGE_MESSAGE'
}

$squashMergeCommitMessageConversion = @{
'PRBody' = 'PR_BODY'
'CommitMessages' = 'COMMIT_MESSAGES'
'Blank' = 'BLANK'
}

$mergeCommitTitleConversion = @{
'PRTitle' = 'PR_TITLE'
'MergeMessage' = 'MERGE_MESSAGE'
}

$mergeCommitMessageConversion = @{
'PRTitle' = 'PR_TITLE'
'PRBody' = 'PR_BODY'
'Blank' = 'BLANK'
}

filter New-GitHubRepository
{
<#
Expand Down Expand Up @@ -86,6 +109,34 @@ filter New-GitHubRepository
By default, rebase-merge pull requests will be allowed.
Specify this to disallow.

.PARAMETER SquashMergeCommitTitle
Specifies the default value for a squash merge commit title. This can be one of the
following values:
- 'PRTitle' - default to the pull request's title.
- 'CommitOrPRTitle' - default to the commit's title (if only one commit) or the pull
request's title (when more than one commit).

.PARAMETER SquashMergeCommitMessage
Specifies the default vaule for a squash merge commit message. This can be one of the
following values:
- 'PRBody' - default to the pull request's body.
- 'CommitMessages' - default to the branch's commit messages.
- Blank - default to a blank commit message.

.PARAMETER MergeCommitTitle
Specifies the default value for a merge commit title. This can be one of the
following values:
- 'PRTitle' - default to the pull request's title.
- 'MergeMessage' - default to the classic title for a merge message (e.g., Merge pull request
#123 from branch-name).

.PARAMETER MergeCommitMessage
Specifies the default vaule for a merge commit message. This can be one of the
following values:
- 'PRTitle' - default to the pull request's title.
- 'PRBody' - default to the pull request's body.
- 'Blank' - default to a blank commit message.

.PARAMETER AllowAutoMerge
Specifies whether to allow auto-merge on pull requests.

Expand Down Expand Up @@ -172,6 +223,18 @@ filter New-GitHubRepository

[switch] $DisallowRebaseMerge,

[ValidateSet('PRTitle', 'CommitOrPRTitle')]
[string] $SquashMergeCommitTitle,

[ValidateSet('PRBody', 'CommitMessages', 'Blank')]
[string] $SquashMergeCommitMessage,

[ValidateSet('PRTitle', 'MergeMessage')]
[string] $MergeCommitTitle,

[ValidateSet('PRTitle', 'PRBody', 'Blank')]
[string] $MergeCommitMessage,

[switch] $AllowAutoMerge,

[switch] $AllowUpdateBranch,
Expand Down Expand Up @@ -222,6 +285,10 @@ filter 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('SquashMergeCommitTitle')) { $hashBody['squash_merge_commit_title'] = $squashMergeCommitTitleConversion.$SquashMergeCommitTitle }
if ($PSBoundParameters.ContainsKey('SquashMergeCommitMessage')) { $hashBody['squash_merge_commit_message'] = $squashMergeCommitMessageConversion.$SquashMergeCommitMessage }
if ($PSBoundParameters.ContainsKey('MergeCommitTitle')) { $hashBody['merge_commit_title'] = $mergeCommitTitleConversion.$MergeCommitTitle }
if ($PSBoundParameters.ContainsKey('MergeCommitMessage')) { $hashBody['merge_commit_message'] = $mergeCommitMessageConversion.$MergeCommitMessage }
if ($PSBoundParameters.ContainsKey('AllowAutoMerge')) { $hashBody['allow_auto_merge'] = $AllowAutoMerge.ToBool() }
if ($PSBoundParameters.ContainsKey('AllowUpdateBranch')) { $hashBody['allow_update_branch'] = $AllowUpdateBranch.ToBool() }
if ($PSBoundParameters.ContainsKey('DeleteBranchOnMerge')) { $hashBody['delete_branch_on_merge'] = $DeleteBranchOnMerge.ToBool() }
Expand Down Expand Up @@ -1082,6 +1149,34 @@ filter Set-GitHubRepository
By default, rebase-merge pull requests will be allowed.
Specify this to disallow.

.PARAMETER SquashMergeCommitTitle
Specifies the default value for a squash merge commit title. This can be one of the
following values:
- PRTitle - default to the pull request's title.
- CommitOrPRTitle - default to the commit's title (if only one commit) or the pull
request's title (when more than one commit).

.PARAMETER SquashMergeCommitMessage
Specifies the default vaule for a squash merge commit message. This can be one of the
following values:
- PRBody - default to the pull request's body.
- CommitMessages - default to the branch's commit messages.
- Blank - default to a blank commit message.

.PARAMETER MergeCommitTitle
Specifies the default value for a merge commit title. This can be one of the
following values:
- PRTitle - default to the pull request's title.
- MergeMessage - default to the classic title for a merge message (e.g., Merge pull request
#123 from branch-name).

.PARAMETER MergeCommitMessage
Specifies the default vaule for a merge commit message. This can be one of the
following values:
- PRTitle - default to the pull request's title.
- PRBody - default to the pull request's body.
- Blank - default to a blank commit message.

.PARAMETER AllowAutoMerge
Specifies whether to allow auto-merge on pull requests.

Expand Down Expand Up @@ -1199,6 +1294,18 @@ filter Set-GitHubRepository

[switch] $DisallowRebaseMerge,

[ValidateSet('PRTitle', 'CommitOrPRTitle')]
[string] $SquashMergeCommitTitle,

[ValidateSet('PRBody', 'CommitMessages', 'Blank')]
[string] $SquashMergeCommitMessage,

[ValidateSet('PRTitle', 'MergeMessage')]
[string] $MergeCommitTitle,

[ValidateSet('PRTitle', 'PRBody', 'Blank')]
[string] $MergeCommitMessage,

[switch] $AllowAutoMerge,

[switch] $AllowUpdateBranch,
Expand Down Expand Up @@ -1250,6 +1357,10 @@ filter Set-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('SquashMergeCommitTitle')) { $hashBody['squash_merge_commit_title'] = $squashMergeCommitTitleConversion.$SquashMergeCommitTitle }
if ($PSBoundParameters.ContainsKey('SquashMergeCommitMessage')) { $hashBody['squash_merge_commit_message'] = $squashMergeCommitMessageConversion.$SquashMergeCommitMessage }
if ($PSBoundParameters.ContainsKey('MergeCommitTitle')) { $hashBody['merge_commit_title'] = $mergeCommitTitleConversion.$MergeCommitTitle }
if ($PSBoundParameters.ContainsKey('MergeCommitMessage')) { $hashBody['merge_commit_message'] = $mergeCommitMessageConversion.$MergeCommitMessage }
if ($PSBoundParameters.ContainsKey('AllowAutoMerge')) { $hashBody['allow_auto_merge'] = $AllowAutoMerge.ToBool() }
if ($PSBoundParameters.ContainsKey('AllowUpdateBranch')) { $hashBody['allow_update_branch'] = $AllowUpdateBranch.ToBool() }
if ($PSBoundParameters.ContainsKey('DeleteBranchOnMerge')) { $hashBody['delete_branch_on_merge'] = $DeleteBranchOnMerge.ToBool() }
Expand Down
Loading