Skip to content

feat(repo): add --squash-merge-commit-message flag to gh repo edit#12846

Merged
babakks merged 3 commits intocli:trunkfrom
yuvrajangadsingh:feat/squash-merge-commit-message
Mar 10, 2026
Merged

feat(repo): add --squash-merge-commit-message flag to gh repo edit#12846
babakks merged 3 commits intocli:trunkfrom
yuvrajangadsingh:feat/squash-merge-commit-message

Conversation

@yuvrajangadsingh
Copy link
Contributor

Closes #10092

Adds --squash-merge-commit-message to gh repo edit with 4 human-friendly values that map to the GitHub API's squash_merge_commit_title and squash_merge_commit_message fields.

Flag values and API mapping:

Flag value squash_merge_commit_title squash_merge_commit_message
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

These match the 4 options in the GitHub web UI for configuring squash merge behavior.

CLI usage:

gh repo edit --enable-squash-merge --squash-merge-commit-message pr-title

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:

? Default squash merge commit message [Use arrows to move, type to filter]
> default
  pr-title
  pr-title-commits
  pr-title-description

Validation:

  • Invalid values produce a clear error listing the valid options
  • Using the flag without --enable-squash-merge produces an error explaining the requirement

Tests added:

  • Flag parsing: valid value, missing --enable-squash-merge, invalid value
  • API payload: verifies correct squash_merge_commit_title and squash_merge_commit_message in PATCH body
  • Interactive flow: squash enabled with commit message prompt, squash disabled (no prompt)
  • Transform function: all 4 mappings
  • Validation function: all valid values + invalid inputs

@github-actions github-actions bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Mar 5, 2026
@yuvrajangadsingh yuvrajangadsingh marked this pull request as ready for review March 5, 2026 11:27
@yuvrajangadsingh yuvrajangadsingh requested a review from a team as a code owner March 5, 2026 11:27
@yuvrajangadsingh yuvrajangadsingh requested a review from BagToad March 5, 2026 11:27
@yuvrajangadsingh yuvrajangadsingh force-pushed the feat/squash-merge-commit-message branch 3 times, most recently from 0460878 to 4b159bd Compare March 6, 2026 17:36
@yuvrajangadsingh
Copy link
Contributor Author

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.

marsam2489-lang

This comment was marked as spam.

@yuvrajangadsingh
Copy link
Contributor Author

@babakks would appreciate a look here too when you have time. same area as #12655 you just merged, adds the missing --squash-merge-commit-message and --squash-merge-commit-title flags to gh repo edit.

@babakks babakks self-requested a review March 9, 2026 17:04
@github-actions github-actions bot removed the needs-triage needs to be reviewed label Mar 10, 2026
@babakks babakks requested a review from Copilot March 10, 2026 10:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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-message flag 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.

Comment on lines +505 to +510
squashMsgOptions := []string{
squashMsgDefault,
squashMsgPRTitle,
squashMsgPRTitleCommits,
squashMsgPRTitleDescription,
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
squashMsgOptions := []string{
squashMsgDefault,
squashMsgPRTitle,
squashMsgPRTitleCommits,
squashMsgPRTitleDescription,
}
squashMsgOptions := validSquashMsgValues

Copilot uses AI. Check for mistakes.
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. 198487e

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
Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

nitpick: let's move this const to the end of the block and comment it out with an explanation:

Suggested change
// TODO: GitHub Enterprise Server does not support has_discussions yet
// optionDiscussions = "Discussions"

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, moved to end of the block with the TODO comment. 198487e

Comment on lines +182 to +187
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")
}
Copy link
Member

Choose a reason for hiding this comment

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

The order of the if statements should change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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}")
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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}")
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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),
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: since we're on go1.26 now, you can be the first use new instead of our homemade sp. 😉

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 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?

Copy link
Member

Choose a reason for hiding this comment

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

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.

@yuvrajangadsingh yuvrajangadsingh force-pushed the feat/squash-merge-commit-message branch from b1c1d77 to 3baf83a Compare March 10, 2026 11:48
- 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
@yuvrajangadsingh
Copy link
Contributor Author

@babakks addressed all your comments, pushed 198487e. replied inline to each one. skipped the NilStringEnum one for now to keep the diff small, happy to do it as a follow-up. had a question on the sp vs new thing, left it on that thread.

Copy link
Member

@babakks babakks left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your contribution, @yuvrajangadsingh! 🙏

Verified both interactive and non-interactive flows.

@babakks babakks merged commit 8f26730 into cli:trunk Mar 10, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow setting squash merge commit message and title in gh repo edit

4 participants