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
base: trunk
Are you sure you want to change the base?
autofill with body #8423
Conversation
|
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. |
|
@guerinoni: could you add a 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 :) |
31b5519
to
f164b51
Compare
| split := strings.SplitN(line, ",", 2) | ||
| if len(split) != 2 { | ||
| split := strings.Split(line, ",") | ||
| if len(split) < 2 { | ||
| continue | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| 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", | ||
| }}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
pkg/cmd/pr/create/create.go
Outdated
| @@ -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") | |||
There was a problem hiding this comment.
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:
| 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, done
pkg/cmd/pr/create/create.go
Outdated
| WebMode bool | ||
| RecoverFile string | ||
| Autofill bool | ||
| AutofillVerbose bool |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pkg/cmd/pr/create/create.go
Outdated
| } 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) |
There was a problem hiding this comment.
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:
- Would want to change this from 3 spaces to 2 spaces in order to align with the title for proper markdown formatting
- 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)
There was a problem hiding this comment.
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 :)
| if i > 0 { | ||
| fmt.Fprintln(&body) | ||
| fmt.Fprintln(&body) | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
c4e0102
to
3e5f24b
Compare
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>
3e5f24b
to
77a93ce
Compare
|
@guerinoni : was doing some testing of this locally from your branch and see $ ~/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 +0x13These 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. |
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