Skip to content
88 changes: 88 additions & 0 deletions GitHubRepositories.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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:
- PR_TITLE - default to the pull request's title.
- COMMIT_OR_PR_TITLE - 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:
- PR_BODY - default to the pull request's body.
- COMMIT_MESSAGES - 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:
- PR_TITLE - default to the pull request's title.
- MERGE_MESSAGE - 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:
- PR_TITLE - default to the pull request's title.
- PR_BODY - default to the pull request's body.
- BLANK - default to a blank commit message.

.PARAMETER DeleteBranchOnMerge
Specifies the automatic deleting of head branches when pull requests are merged.

Expand Down Expand Up @@ -165,6 +193,18 @@ filter New-GitHubRepository

[switch] $DisallowRebaseMerge,

[ValidateSet('PR_TITLE', 'COMMIT_OR_PR_TITLE')]
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer using PowerShell casing syntax for parameters, and then converting as necessary within the function for what the API requires. So, instead of PR_TITLE, it would be PRTitle and instead of MERGE_MESSAGE it would be MergeMessage. Similar for the other ones.

You can then use a hashtable to cleanly handle the conversions:

e.g.

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

# ....

$hashBody['squash_merge_commit_title'] = $squashMergeCommitTitleConversion.$SquashMergeCommitTitle

Similar feedback throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we do this, then I think we really need to modify all GitHub.Repository objects returned by any function so that the Merge Commit property values match, otherwise this will be confusing to users of the module. If we change the current property values, merge_commit_title for example, then that is technically a breaking change. I could add additional properties, MergeCommitTitle for example with the Pascal case value, but then we are duplicating the properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HowardWolosky, any response to this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies for the delayed response here.

Great question -- I appreciate you bringing it up.

My general philosophy on this module is that I don't want to modify the raw return values that GitHub is providing, but that I will add properties that either add clarity/value, or assist in the continued functioning of the module.

Given that, I wouldn't want to modify the merge_commit_title / merge_commit_message values returned by GitHub. I'd be totally fine with adding a MergeCommitTitle/MergeCommitMessage/etc... property to the object when the equivalent GH property exists, using the naming/casing syntax that is part of the module, even if that makes the properties duplicative.

On this one, I don't feel super strong on needing those extra properties though. I don't think that the different casing/underscore usage on the GH object property will necessarily be confusing to users, but I can be easily swayed here. I'd happily approve a change that added the additional properties if the source ones existed in the GH object. I just want to keep the parameters consistent in casing convention. The additional properties on the object have been a bit more important to me when those could be used as parameters when piped into a different module function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've update the parameter names as requested.

[string] $SquashMergeCommitTitle,

[ValidateSet('PR_BODY', 'COMMIT_MESSAGES', 'BLANK')]
[string] $SquashMergeCommitMessage,

[ValidateSet('PR_TITLE', 'MERGE_MESSAGE')]
[string] $MergeCommitTitle,

[ValidateSet('PR_TITLE', 'PR_BODY', 'BLANK')]
[string] $MergeCommitMessage,

[switch] $DeleteBranchOnMerge,

[switch] $IsTemplate,
Expand Down Expand Up @@ -211,6 +251,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'] = $SquashMergeCommitTitle }
if ($PSBoundParameters.ContainsKey('SquashMergeCommitMessage')) { $hashBody['squash_merge_commit_message'] = $SquashMergeCommitMessage }
if ($PSBoundParameters.ContainsKey('MergeCommitTitle')) { $hashBody['merge_commit_title'] = $MergeCommitTitle }
if ($PSBoundParameters.ContainsKey('MergeCommitMessage')) { $hashBody['merge_commit_message'] = $MergeCommitMessage }
if ($PSBoundParameters.ContainsKey('DeleteBranchOnMerge')) { $hashBody['delete_branch_on_merge'] = $DeleteBranchOnMerge.ToBool() }
if ($PSBoundParameters.ContainsKey('IsTemplate')) { $hashBody['is_template'] = $IsTemplate.ToBool() }

Expand Down Expand Up @@ -1066,6 +1110,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:
- PR_TITLE - default to the pull request's title.
- COMMIT_OR_PR_TITLE - 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:
- PR_BODY - default to the pull request's body.
- COMMIT_MESSAGES - 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:
- PR_TITLE - default to the pull request's title.
- MERGE_MESSAGE - 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:
- PR_TITLE - default to the pull request's title.
- PR_BODY - default to the pull request's body.
- BLANK - default to a blank commit message.

.PARAMETER DeleteBranchOnMerge
Specifies the automatic deleting of head branches when pull requests are merged.

Expand Down Expand Up @@ -1170,6 +1242,18 @@ filter Set-GitHubRepository

[switch] $DisallowRebaseMerge,

[ValidateSet('PR_TITLE', 'COMMIT_OR_PR_TITLE')]
[string] $SquashMergeCommitTitle,

[ValidateSet('PR_BODY', 'COMMIT_MESSAGES', 'BLANK')]
[string] $SquashMergeCommitMessage,

[ValidateSet('PR_TITLE', 'MERGE_MESSAGE')]
[string] $MergeCommitTitle,

[ValidateSet('PR_TITLE', 'PR_BODY', 'BLANK')]
[string] $MergeCommitMessage,

[switch] $DeleteBranchOnMerge,

[switch] $IsTemplate,
Expand Down Expand Up @@ -1215,6 +1299,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'] = $SquashMergeCommitTitle }
if ($PSBoundParameters.ContainsKey('SquashMergeCommitMessage')) { $hashBody['squash_merge_commit_message'] = $SquashMergeCommitMessage }
if ($PSBoundParameters.ContainsKey('MergeCommitTitle')) { $hashBody['merge_commit_title'] = $MergeCommitTitle }
if ($PSBoundParameters.ContainsKey('MergeCommitMessage')) { $hashBody['merge_commit_message'] = $MergeCommitMessage }
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() }
Expand Down
Loading