[PATCH pyonji] submit: Add reflection feature
Export this patch
Before sending off patches to a mailing list, it may be preferable to
have a final look at the entire series. Reflecting the series to only
the developers' address provides a means to preview the series.
Add button "Reflect" to the UI that, when clicked, sends patches to the
address of the developer. Addresses in the To, Cc and Bcc fields are
used to fill in the corresponding mail headers, but no mail is sent to
these addresses.
Upon reflection, the To, Cc and Bcc values of the corresponding UI
inputs are saved to the current branch state for later use.
Preset focus to the reflection button upon pyonji startup.
This reflection feature is inspired by b4 --reflect.
Depends: https://lists.sr.ht/~emersion/public-inbox/patches/51376
Signed-off-by: Folker Schwesinger <dev@folker-schwesinger.de>
---
submit.go | 87 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 73 insertions(+), 14 deletions(-)
diff --git a/submit.go b/submit.go
index 014f0d8..3d5d0c7 100644
--- a/submit.go
+++ b/submit.go
@@ -36,6 +36,7 @@ type submissionConfig struct {
bcc []*mail.Address
rerollCount string
subjectPrefix string
+ reflect bool
}
type coverLetterUpdated struct {
@@ -57,6 +58,7 @@ const (
submitStateVersion
submitStateCoverLetter
submitStateConfirm
+ submitStateReflect
)
var (
@@ -169,7 +171,7 @@ func initialSubmitModel(ctx context.Context, gitConfig *gitSendEmailConfig) subm
log.Fatal(err)
}
- state := submitStateConfirm
+ state := submitStateReflect
if len(cfg.to) == 0 {
state = submitStateTo
}
@@ -284,6 +286,40 @@ func (m submitModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
baseBranch: m.baseBranch,
rerollCount: m.version.Value(),
subjectPrefix: m.subjectPrefix,
+ reflect: false,
+ }
+ return submitPatches(m.ctx, m.headBranch, &cfg, m.gitConfig, m.coverLetter != "", m.progress)
+ }
+ case submitStateReflect:
+ if !m.canSubmit() {
+ break
+ }
+ m.loadingMsg = "Reflecting patches..."
+ return m, func() tea.Msg {
+ to, err := parseAddressList(m.to.Value())
+ if err != nil {
+ return err
+ }
+
+ cc, err := parseAddressList(m.cc.Value())
+ if err != nil {
+ return err
+ }
+
+ bcc, err := parseAddressList(m.bcc.Value())
+ if err != nil {
+ return err
+ }
+
+
+ cfg := submissionConfig{
+ to: to,
+ cc: cc,
+ bcc: bcc,
+ baseBranch: m.baseBranch,
+ rerollCount: m.version.Value(),
+ subjectPrefix: m.subjectPrefix,
+ reflect: true,
}
return submitPatches(m.ctx, m.headBranch, &cfg, m.gitConfig, m.coverLetter != "", m.progress)
}
@@ -293,7 +329,15 @@ func (m submitModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m = m.setState(m.state - 1)
}
case tea.KeyDown:
- if m.state < submitStateConfirm {
+ if m.state < submitStateReflect {
+ m = m.setState(m.state + 1)
+ }
+ case tea.KeyLeft:
+ if m.state == submitStateReflect {
+ m = m.setState(m.state - 1)
+ }
+ case tea.KeyRight:
+ if m.state == submitStateConfirm {
m = m.setState(m.state + 1)
}
case tea.KeyCtrlC, tea.KeyEsc:
@@ -375,12 +419,17 @@ func (m submitModel) View() string {
} else if m.done {
sb.WriteString(successStyle.Render("✓ Patches sent\n"))
} else {
- btn := button{
+ submitBtn := button{
Label: "Submit",
Active: m.state == submitStateConfirm,
Disabled: !m.canSubmit(),
}
- sb.WriteString(btn.View() + "\n")
+ reflectBtn := button{
+ Label: "Reflect",
+ Active: m.state == submitStateReflect,
+ Disabled: !m.canReflect(),
+ }
+ sb.WriteString(submitBtn.View() + " " + reflectBtn.View() + "\n")
}
sb.WriteString("\n")
@@ -446,6 +495,10 @@ func (m submitModel) setState(state submitState) submitModel {
return m
}
+func (m submitModel) canReflect() bool {
+ return len(m.commits) > 0 && checkVersion(m.version.Value())
+}
+
func (m submitModel) canSubmit() bool {
return len(m.commits) > 0 && checkAddressList(m.to.Value()) && checkVersion(m.version.Value())
}
@@ -532,16 +585,20 @@ func submitPatches(ctx context.Context, headBranch string, submission *submissio
}
var toAddrs []string
- for _, addr := range submission.to {
- toAddrs = append(toAddrs, addr.Address)
- }
+ if submission.reflect {
+ toAddrs = append(toAddrs, from.Address)
+ } else {
+ for _, addr := range submission.to {
+ toAddrs = append(toAddrs, addr.Address)
+ }
- for _, addr := range submission.cc {
- toAddrs = append(toAddrs, addr.Address)
- }
+ for _, addr := range submission.cc {
+ toAddrs = append(toAddrs, addr.Address)
+ }
- for _, addr := range submission.bcc {
- toAddrs = append(toAddrs, addr.Address)
+ for _, addr := range submission.bcc {
+ toAddrs = append(toAddrs, addr.Address)
+ }
}
var sender mailSender
@@ -569,8 +626,10 @@ func submitPatches(ctx context.Context, headBranch string, submission *submissio
ch <- progress
}
- if err := saveLastSentHash(headBranch); err != nil {
- return err
+ if !submission.reflect {
+ if err := saveLastSentHash(headBranch); err != nil {
+ return err
+ }
}
progress.done = true
base-commit: 09a38355d8e3ddcbebc3d410762d35ab56469c37
--
2.44.0
pyonji/patches/.build.yml: FAILED in 13s
[submit: Add reflection feature][0] from [Folker Schwesinger][1]
[0]: https://lists.sr.ht/~emersion/public-inbox/patches/51407
[1]: mailto:dev@folker-schwesinger.de
✗ #1206101 FAILED pyonji/patches/.build.yml https://builds.sr.ht/~emersion/job/1206101