feat(repo): add --squash-merge-commit-message flag to gh repo edit#12846
feat(repo): add --squash-merge-commit-message flag to gh repo edit#12846
Conversation
0460878 to
4b159bd
Compare
|
hey @BagToad, would love your eyes on this when you get a chance. small addition to gh repo edit, adds --squash-merge-commit-message flag to match the existing --merge-commit-message pattern. |
There was a problem hiding this comment.
Pull request overview
Adds support in gh repo edit for configuring the default squash merge commit message behavior using a single user-friendly flag, mapping to the REST API’s squash_merge_commit_title and squash_merge_commit_message fields.
Changes:
- Adds
--squash-merge-commit-messageflag parsing/validation and mapping into the repo edit PATCH payload. - Extends interactive merge options flow to prompt for the default squash merge commit message format when squash merge is enabled.
- Adds unit tests for flag parsing, validation/mapping, REST payload fields, and interactive prompting behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/cmd/repo/edit/edit.go | Implements the new flag, interactive prompt, validation, and mapping to REST fields. |
| pkg/cmd/repo/edit/edit_test.go | Adds coverage for parsing, mapping, payload formation, and interactive prompt flow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pkg/cmd/repo/edit/edit.go
Outdated
| squashMsgOptions := []string{ | ||
| squashMsgDefault, | ||
| squashMsgPRTitle, | ||
| squashMsgPRTitleCommits, | ||
| squashMsgPRTitleDescription, | ||
| } |
There was a problem hiding this comment.
The list of valid squash message values is duplicated here (squashMsgOptions) and again in validSquashMsgValues. To reduce the chance of them drifting, consider reusing the same slice (or deriving one from the other) in both the interactive prompt and validation.
| squashMsgOptions := []string{ | |
| squashMsgDefault, | |
| squashMsgPRTitle, | |
| squashMsgPRTitleCommits, | |
| squashMsgPRTitleDescription, | |
| } | |
| squashMsgOptions := validSquashMsgValues |
Add a single --squash-merge-commit-message flag that maps to both squash_merge_commit_title and squash_merge_commit_message API fields. Supported values: - default: COMMIT_OR_PR_TITLE + COMMIT_MESSAGES - pr-title: PR_TITLE + BLANK - pr-title-commits: PR_TITLE + COMMIT_MESSAGES - pr-title-description: PR_TITLE + PR_BODY The flag requires --enable-squash-merge to be set alongside it. In interactive mode, the squash merge commit message prompt appears when squash merging is selected. Closes cli#10092
babakks
left a comment
There was a problem hiding this comment.
Nice PR, @yuvrajangadsingh! 🙏
I haven't end-to-end tested it yet, but all seems to be in a good shape. I'll do proper testing once you apply the requested changes.
pkg/cmd/repo/edit/edit.go
Outdated
There was a problem hiding this comment.
nitpick: let's move this const to the end of the block and comment it out with an explanation:
| // TODO: GitHub Enterprise Server does not support has_discussions yet | |
| // optionDiscussions = "Discussions" |
There was a problem hiding this comment.
done, moved to end of the block with the TODO comment. 198487e
pkg/cmd/repo/edit/edit.go
Outdated
| if err := validateSquashMergeCommitMsg(*opts.Edits.squashMergeCommitMsg); err != nil { | ||
| return err | ||
| } | ||
| if opts.Edits.EnableSquashMerge == nil { | ||
| return cmdutil.FlagErrorf("--squash-merge-commit-message requires --enable-squash-merge") | ||
| } |
There was a problem hiding this comment.
The order of the if statements should change.
There was a problem hiding this comment.
reordered, and added the --enable-squash-merge=false check too. 198487e
| cmdutil.NilBoolFlag(cmd, &opts.Edits.DeleteBranchOnMerge, "delete-branch-on-merge", "", "Delete head branch when pull requests are merged") | ||
| cmdutil.NilBoolFlag(cmd, &opts.Edits.AllowForking, "allow-forking", "", "Allow forking of an organization repository") | ||
| cmdutil.NilBoolFlag(cmd, &opts.Edits.AllowUpdateBranch, "allow-update-branch", "", "Allow a pull request head branch that is behind its base branch to be updated") | ||
| cmdutil.NilStringFlag(cmd, &opts.Edits.squashMergeCommitMsg, "squash-merge-commit-message", "", "The default value for a squash merge commit message: {default|pr-title|pr-title-commits|pr-title-description}") |
There was a problem hiding this comment.
off-topic/ignore: we need to think about these inlined enum values since they're not rendered nicely on online (Markdown) docs. See gh search prs as an example.
There was a problem hiding this comment.
noted, yeah the inline enum rendering is a separate issue. skipping for now.
| cmdutil.NilBoolFlag(cmd, &opts.Edits.DeleteBranchOnMerge, "delete-branch-on-merge", "", "Delete head branch when pull requests are merged") | ||
| cmdutil.NilBoolFlag(cmd, &opts.Edits.AllowForking, "allow-forking", "", "Allow forking of an organization repository") | ||
| cmdutil.NilBoolFlag(cmd, &opts.Edits.AllowUpdateBranch, "allow-update-branch", "", "Allow a pull request head branch that is behind its base branch to be updated") | ||
| cmdutil.NilStringFlag(cmd, &opts.Edits.squashMergeCommitMsg, "squash-merge-commit-message", "", "The default value for a squash merge commit message: {default|pr-title|pr-title-commits|pr-title-description}") |
There was a problem hiding this comment.
suggestion: feel free to skip this one, but it'd be super nice if we could have a new helper like cmdutil.NilStringEnum, that uses the cmdutil.stringEnum under the hood. This way we won't need the validate function, and also the error message will be consistent with other commands.
I can help with this one, please let me know.
There was a problem hiding this comment.
skipping this one for now to keep the diff focused, but happy to take it on in a follow-up if you'd like.
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| edits := &EditRepositoryInput{ | ||
| squashMergeCommitMsg: sp(tt.input), |
There was a problem hiding this comment.
nitpick: since we're on go1.26 now, you can be the first use new instead of our homemade sp. 😉
There was a problem hiding this comment.
i looked into this but new(string) only gives you a *string pointing to the zero value. for non-zero values like sp("hello") we'd still need a helper. is there something new in 1.26 i'm missing, or were you thinking of something else?
There was a problem hiding this comment.
Yeah, the new syntax also accepts a value to initialise the allocated variable with. See here. I'm going to fix them all in a PR, so feel free to skip this one.
b1c1d77 to
3baf83a
Compare
- reorder if checks: validate --enable-squash-merge is set before checking the value, and error when --enable-squash-merge=false - use validSquashMsgValues directly in interactive prompt instead of duplicating the slice - use slices.Contains in validateSquashMergeCommitMsg - interpolate const values in Long description instead of hardcoding - add default clause in transformSquashMergeOpts to avoid mutating title/message on unknown input - move optionDiscussions to end of const block with TODO comment - add test for unknown input and --enable-squash-merge=false case
babakks
left a comment
There was a problem hiding this comment.
LGTM! Thanks for your contribution, @yuvrajangadsingh! 🙏
Verified both interactive and non-interactive flows.
Closes #10092
Adds
--squash-merge-commit-messagetogh repo editwith 4 human-friendly values that map to the GitHub API'ssquash_merge_commit_titleandsquash_merge_commit_messagefields.Flag values and API mapping:
squash_merge_commit_titlesquash_merge_commit_messagedefaultCOMMIT_OR_PR_TITLECOMMIT_MESSAGESpr-titlePR_TITLEBLANKpr-title-commitsPR_TITLECOMMIT_MESSAGESpr-title-descriptionPR_TITLEPR_BODYThese match the 4 options in the GitHub web UI for configuring squash merge behavior.
CLI usage:
Interactive mode:
When the user selects "Allow Squash Merging" in the merge strategies prompt, a follow-up prompt asks which commit message format to use:
Validation:
--enable-squash-mergeproduces an error explaining the requirementTests added:
--enable-squash-merge, invalid valuesquash_merge_commit_titleandsquash_merge_commit_messagein PATCH body