Skip to content

Commit

Permalink
New/Set-GitHubRepository: Add Support for Merge Commit Title and Mess…
Browse files Browse the repository at this point in the history
…age Options (#385)

Adds merge commit message and title parameters to the `New-GitHubRepository` and `Set-GitHubRepository` functions.

Fixes #384

#### References

- https://docs.github.com/en/rest/repos/repos#create-an-organization-repository
- https://docs.github.com/en/rest/repos/repos#update-a-repository
  • Loading branch information
X-Guardian authored May 2, 2023
1 parent dd844e5 commit 6f94a9b
Show file tree
Hide file tree
Showing 2 changed files with 506 additions and 0 deletions.
107 changes: 107 additions & 0 deletions GitHubRepositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@
GitHubRepositoryLanguageTypeName = 'GitHub.RepositoryLanguage'
GitHubRepositoryTagTypeName = 'GitHub.RepositoryTag'
GitHubRepositoryTeamPermissionTypeName = 'GitHub.RepositoryTeamPermission'
SquashMergeCommitTitleConversion = @{
'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'
}
}.GetEnumerator() | ForEach-Object {
Set-Variable -Scope Script -Option ReadOnly -Name $_.Key -Value $_.Value
}
Expand Down Expand Up @@ -86,6 +105,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 value 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 +219,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 +281,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'] = $script:SquashMergeCommitTitleConversion.$SquashMergeCommitTitle }
if ($PSBoundParameters.ContainsKey('SquashMergeCommitMessage')) { $hashBody['squash_merge_commit_message'] = $script:SquashMergeCommitMessageConversion.$SquashMergeCommitMessage }
if ($PSBoundParameters.ContainsKey('MergeCommitTitle')) { $hashBody['merge_commit_title'] = $script:MergeCommitTitleConversion.$MergeCommitTitle }
if ($PSBoundParameters.ContainsKey('MergeCommitMessage')) { $hashBody['merge_commit_message'] = $script: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 +1145,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 value 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 +1290,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 +1353,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'] = $script:SquashMergeCommitTitleConversion.$SquashMergeCommitTitle }
if ($PSBoundParameters.ContainsKey('SquashMergeCommitMessage')) { $hashBody['squash_merge_commit_message'] = $script:SquashMergeCommitMessageConversion.$SquashMergeCommitMessage }
if ($PSBoundParameters.ContainsKey('MergeCommitTitle')) { $hashBody['merge_commit_title'] = $script:MergeCommitTitleConversion.$MergeCommitTitle }
if ($PSBoundParameters.ContainsKey('MergeCommitMessage')) { $hashBody['merge_commit_message'] = $script: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

0 comments on commit 6f94a9b

Please sign in to comment.