Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autofill with body #8423

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open

autofill with body #8423

wants to merge 2 commits into from

Conversation

guerinoni
Copy link
Contributor

@guerinoni guerinoni commented Dec 5, 2023

  • git: Return body from list of commits
    This allow to use body of every commits between two ref.

  • pr: Add flag fillverbose
    This is used to fill the body of PR with all commits msg + body

Motivation: Usually I have lot of information within the body of commit msg, as you know many project had this situation, i.e. kernel. With this flag we can keep compatibility to previous flags but add a special behaviour if a developer put lot of effort in writing good commits.
(This pr is opened with this flag :) )

Bonus: Another thing that I would love to see is the same feature but when a PR is already opened, in this way we can backfill description of PR with the same content of commits.

Fixes: #8445

@guerinoni guerinoni requested a review from a team as a code owner December 5, 2023 22:33
@guerinoni guerinoni requested review from andyfeller and removed request for a team December 5, 2023 22:33
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Dec 5, 2023
@cliAutomation
Copy link
Collaborator

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Dec 5, 2023
@andyfeller
Copy link
Contributor

andyfeller commented Dec 8, 2023

@guerinoni: could you add a fixes #... line at the beginning of your PR body please? 🙇 Helping to link this up to the issue also it to be automatically closed when the PR is closed and merged.

If there is no existing issue, then this PR request will likely wait until such an issue is created and discussed with the core maintainers. 🙇

@guerinoni
Copy link
Contributor Author

@guerinoni: could you add a fixes #... line at the beginning of your PR body please? 🙇 Helping to link this up to the issue also it to be automatically closed when the PR is closed and merged.

If there is no existing issue, then this PR request will likely wait until such an issue is created and discussed with the core maintainers. 🙇

Oh thanks! I did the issue, didn't know about the right workflow :)

split := strings.SplitN(line, ",", 2)
if len(split) != 2 {
split := strings.Split(line, ",")
if len(split) < 2 {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not keep SplitN and only increment the number of potential splits we want? How does this work if the body contains commas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I improved the test case to check the correctness in case of , in the body of commit

Comment on lines +474 to 478
wantCmdArgs: `path/to/git -c log.ShowSignature=false log --pretty=format:%H,%s,%b --cherry SHA1...SHA2`,
wantCommits: []*Commit{{
Sha: "6a6872b918c601a0e730710ad8473938a7516d30",
Title: "testing testability test",
}},
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this and other tests fail because Body is missing? Should existing tests around commits be enhanced to account for these new changes with body?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not affected also if body is missing! I added a new test to check body is read correctly :)

@@ -196,6 +205,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
fl.StringVarP(&opts.BaseBranch, "base", "B", "", "The `branch` into which you want your code merged")
fl.StringVarP(&opts.HeadBranch, "head", "H", "", "The `branch` that contains commits for your pull request (default: current branch)")
fl.BoolVarP(&opts.WebMode, "web", "w", false, "Open the web browser to create a pull request")
fl.BoolVarP(&opts.AutofillVerbose, "fillverbose", "", false, "Use commits msg+body for description")
Copy link
Contributor

Choose a reason for hiding this comment

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

Using hyphens to separate words like fill-first:

Suggested change
fl.BoolVarP(&opts.AutofillVerbose, "fillverbose", "", false, "Use commits msg+body for description")
fl.BoolVarP(&opts.AutofillVerbose, "fill-verbose", "", false, "Use commits msg+body for description")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, done

WebMode bool
RecoverFile string
Autofill bool
AutofillVerbose bool
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe all flags that relate to auto fill drop the Auto portion of the flag internally like FillFirst.

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

} else {
state.Title = humanize(headRef)
var body strings.Builder
for i := len(commits) - 1; i >= 0; i-- {
fmt.Fprintf(&body, "- %s\n", commits[i].Title)
if addBody {
fmt.Fprintf(&body, " %s", commits[i].Body)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see 2 problems with this formatting change:

  1. Would want to change this from 3 spaces to 2 spaces in order to align with the title for proper markdown formatting
  2. Because many people write larger git commit bodies, there are multiple lines involved and all of it would need to be indented to align.
				fmt.Fprintf(&body, "    %s", commits[i].Body)

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 fixed this case also splitting Body every 72 chars, as the best practices for writing commits want... Bonus, the split doesn't split in the middle of the word but it split before the 72 chunk in case is in the middle of word :)

Comment on lines +436 to +482
if i > 0 {
fmt.Fprintln(&body)
fmt.Fprintln(&body)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this adding 2 newlines? Why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for separate commits

This allow to use body of every commits between two ref.
@guerinoni guerinoni force-pushed the autofill-with-body branch 3 times, most recently from c4e0102 to 3e5f24b Compare January 6, 2024 15:59
This is used to fill the body of PR with all commits msg + body
of every commits because there can be lot of useful information.

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
@andyfeller
Copy link
Contributor

@guerinoni : was doing some testing of this locally from your branch and see gh panicking

$ ~/Documents/workspace/cli/cli/bin/gh pr create --fill-verbose
? Where should we push the 'test' branch? tinyfists/actions-experiments
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/cli/cli/v2/pkg/cmd/pr/create.initDefaultTitleBody({0xc000215280, 0xc00037c380, {0x30451f0, 0xc0006da000}, {0xc00055fb50, 0xb}, {0xc00042aa80, 0x4}, {0xc00042aa9b, 0x4}, ...}, ...)
	github.com/cli/cli/v2/pkg/cmd/pr/create/create.go:470 +0x3fe
github.com/cli/cli/v2/pkg/cmd/pr/create.NewIssueState({0xc000215280, 0xc00037c380, {0x30451f0, 0xc0006da000}, {0xc00055fb50, 0xb}, {0xc00042aa80, 0x4}, {0xc00042aa9b, 0x4}, ...}, ...)
	github.com/cli/cli/v2/pkg/cmd/pr/create/create.go:555 +0x318
github.com/cli/cli/v2/pkg/cmd/pr/create.createRun(0xc000274d80)
	github.com/cli/cli/v2/pkg/cmd/pr/create/create.go:241 +0xfe
github.com/cli/cli/v2/pkg/cmd/pr/create.NewCmdCreate.func1(0xc00044ba00?, {0xc0000467d0?, 0x4?, 0x20d5302?})
	github.com/cli/cli/v2/pkg/cmd/pr/create/create.go:196 +0x8cc
github.com/spf13/cobra.(*Command).execute(0xc000465200, {0xc0000467c0, 0x1, 0x1})
	github.com/spf13/cobra@v1.6.1/command.go:916 +0x87c
github.com/spf13/cobra.(*Command).ExecuteC(0xc000004300)
	github.com/spf13/cobra@v1.6.1/command.go:1044 +0x3a5
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
	github.com/spf13/cobra@v1.6.1/command.go:977
main.mainRun()
	github.com/cli/cli/v2/cmd/gh/main.go:119 +0x5db
main.main()
	github.com/cli/cli/v2/cmd/gh/main.go:46 +0x13

These are the only 2 commits on the branch I was using for testing:

commit 56b2c0c702e4e89fab48009fa082d7b581a49fbf
Author: Andy Feller <andyfeller@github.com>
Date:   Tue Jan 9 14:21:50 2024 -0500

    Arbitrary change for testing
    
    This adds an arbitrary test, defining run-name on the workflow, to see how multiple commits are handled.

commit 8ba8b27b1607e77b7194945ba68ea7346c288743
Author: Andy Feller <andyfeller@github.com>
Date:   Tue Jan 9 14:20:21 2024 -0500

    This is a test of new gh pr create --fill-verbose PR
    
    This is a random commit that I can use for testing out changes to gh pr create --fill-verbose.
    
    This has multiple lines, which this may or may not break about but will also try adding a really long line without breaking it to see how it handles verbose content.

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
Projects
No open projects
The GitHub CLI
  
Needs review 🤔
Development

Successfully merging this pull request may close these issues.

Open a PR with all commits title + body as PR description
3 participants