cli / cli

GitHub’s official command line tool
https://cli.github.com
MIT License
37.22k stars 5.78k forks source link

Allow editing the commit message when squash-merging a PR #1023

Closed g0tsimid closed 2 years ago

g0tsimid commented 4 years ago

Describe the feature or problem you’d like to solve

When performing a squash and merge on a pull request through the web interface, you can edit the commit message and extended description. By default, this is prepopulated with a list of all of the commit messages included in the pull request. I often find myself deleting some of the lines from this section because the additional commits are usually related to feedback brought up during the code review, and would be irrelevant or confusing when viewing in the context of the final commit.

When merging a PR through the CLI, the same commit message is generated as the web interface, but there is no option to edit the commit message.

Proposed solution

Open the user's default terminal editor to allow the PR maintainer to enter the commit message. By default, prepopulate the editor with the default generated message so the user can easily just save and exit the editor to continue using the current behaviour.

SPEC: https://github.com/cli/cli/issues/1023#issuecomment-765799502

mgabeler-lee-6rs commented 4 years ago

I'd like to be able to edit the commit message for all merges, not just squash ones.

My use case: I want/need my merge commits to have a conventional commit format to support semrel automation

chandlerc commented 4 years ago

I think this is more serious than an "enhancement".

In the GitHub web UI, the "squash and merge" button always opens a text box to prompt editing the commit message.

The git pr merge --squash command gives no indication that it will directly commit without any option to edit the commit message. This is extremely surprising and results in a bad history for repositories. At the very least, there needs to be an unambiguous prompt prior to this happening as this is not a local operation or easily undone.

krlmlr commented 4 years ago

Could we also offer an -m or --message argument that allows editing the message in non-interactive mode?

markov00 commented 4 years ago

The @krlmlr suggestion for the non-interactive mode is also very useful when you use tools and conventions like conventional-commits and semantic-release where both title and body of the commit are used to detect the next semantic version to release. Actually, except for a github enterprise on-premise version, there is no way to check/lint the body message of a squashed PR and doing that manually or through some browser extension is not ideal. Adding a -m option will allow to squash the PR from the command line with a prelinted body and title

andres-lowrie commented 3 years ago

building off of @krlmlr 's comment. It could be useful to have the whole sub command take an argument that would be the message, similar to how git commit -m works; so something like this

gh pr merge 123 -m "the commit message I want"

This could work the same for all the flags too not just m , basically changing the usage to something like this

USAGE
  gh pr merge [<number> | <url> | <branch>] [flags] [message]
vilmibm commented 3 years ago

I intend to merge #2810 but think this issue should remain open so we can discuss having an interactive prompt for this as well. @mislav do you recall if there was a technical reason for us not including that to begin with? @ampinsk do you recall if there was a UX reason?

mgabeler-lee-6rs commented 3 years ago

In addition to interactive prompting mode, the other thing #1023 doesn't cover is setting the first line of the commit, which is important for some CI flows (e.g. commit message validation, semantic versioning release automation e.g. through conventional commits)

vilmibm commented 3 years ago

We just didn't get to adding an interactive prompt for this and agreed internally it's a good idea.

The spec for this is converting the confirmation prompt from a y/N prompt to a select with options:

Submit
Edit Commit Message
Edit Commit Author
Cancel

Editing the commit message should prepopulate the user's editor with a precomputed headline/body. The web UI splits out the headline as a separate input, but I think it's okay to have it be the top line of the file opened in the editor.

cristiand391 commented 3 years ago

I'm working on this issue.

rfkd commented 3 years ago

Is there any way to change the commit message "title" (as shown in git log --oneline)? The new --body argument introduced with #2810 only seems to append its value to the default title "Merge pull request #... from ..." instead of allowing to define the entire commit message.

mgabeler-lee-6rs commented 3 years ago

I don't agree that #2980 resolves this

When performing a squash and merge on a pull request through the web interface, you can edit the commit message and extended description

2980 only permits editing the body, not the first line of the message. It has some internal code for setting the "headline", but no ability to invoke that code from the CLI AFAICT:

Compare:

achimnol commented 3 years ago

It is great to heart that this feature is finally implemented. However, I just faced a caveat: editing the commit message is only prompted when pr merge is executed in the interactive mode ONLY, meaning that pr merge --squash still does not have chances to change the commit message interactively. I think this is an acceptable complexity trade-off for handling scripted usage and interactive usage, but at least this should be documented somewhere, e.g., "When you specify the merge method explicitly via --merge / --rebase / --squash arguments, it runs in the non-interactive mode and the commit message is automatically filled unless specified with the --body argument".

Ashish-Pandey-Imprivata commented 3 years ago

Any timelines to fix the issue of changing first line of commit message when doing pr merge operation? As others have mentioned before, there is a need to consolidate the comments during pr merge operation for those who follow Conventional Commit message format. Thanks for adding -b option for commit body though.

mislav commented 3 years ago

Thanks for the feedback, everyone. Reopening as a feature request to be able to edit the commit subject message as well as the commit body.

Ashish-Pandey-Imprivata commented 3 years ago

Thanks for the feedback, everyone. Reopening as a feature request to be able to edit the commit subject message as well as the commit body.

Thanks a lot. Since I am not familiar with GH CLI release cycles, would it be possible to get a rough timeline on release when this feature would be available?

mislav commented 3 years ago

@Ashish-Pandey-Imprivata We don't know. If someone wants to step up and contribute the code for feature via a pull request, it might get released within the next few weeks. Otherwise, it's going to be whenever we find time to get to this.

In the meantime, this manual approach will work with existing versions of GitHub CLI:

gh api -XPUT --silent repos/:owner/:repo/pulls/NUMBER/merge -f merge_method=merge -f commit_title="TITLE" -f commit_message="MESSAGE"

It can be saved as an alias:

$ gh alias set merge-explicit '!gh api -XPUT --silent repos/:owner/:repo/pulls/$1/merge -f merge_method=merge -f commit_title="$2" -f commit_message="$3"'

$ gh merge-explicit 123 "this is commit subject" "this is commit message" 
Ashish-Pandey-Imprivata commented 3 years ago

Thanks for your comment and suggestions for a good workaround in the meantime. Using "gh api" is slightly involved, but works fine.

mislav commented 2 years ago

This shipped in v2.4.0, forgot to close: https://github.com/cli/cli/commit/f2d23d8c88845b8cf94a54130baa9fd5531e8801