-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdownstack_submit.go
87 lines (75 loc) · 1.92 KB
/
downstack_submit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"context"
"errors"
"fmt"
"slices"
"github.com/charmbracelet/log"
"go.abhg.dev/gs/internal/git"
"go.abhg.dev/gs/internal/must"
"go.abhg.dev/gs/internal/secret"
"go.abhg.dev/gs/internal/spice"
"go.abhg.dev/gs/internal/spice/state"
"go.abhg.dev/gs/internal/text"
"go.abhg.dev/gs/internal/ui"
)
type downstackSubmitCmd struct {
submitOptions
Branch string `placeholder:"NAME" help:"Branch to start at" predictor:"trackedBranches"`
}
func (*downstackSubmitCmd) Help() string {
return text.Dedent(`
Change Requests are created or updated
for the current branch and all branches below it until trunk.
Use --branch to start at a different branch.
`) + "\n" + _submitHelp
}
func (cmd *downstackSubmitCmd) Run(
ctx context.Context,
secretStash secret.Stash,
log *log.Logger,
view ui.View,
repo *git.Repository,
store *state.Store,
svc *spice.Service,
) error {
if cmd.Branch == "" {
currentBranch, err := repo.CurrentBranch(ctx)
if err != nil {
return fmt.Errorf("get current branch: %w", err)
}
cmd.Branch = currentBranch
}
if cmd.Branch == store.Trunk() {
return errors.New("nothing to submit below trunk")
}
downstacks, err := svc.ListDownstack(ctx, cmd.Branch)
if err != nil {
return fmt.Errorf("list downstack: %w", err)
}
must.NotBeEmptyf(downstacks, "downstack cannot be empty")
slices.Reverse(downstacks)
// TODO: generalize into a service-level method
// TODO: separate preparation of the stack from submission
session := newSubmitSession(repo, store, secretStash, view, log)
for _, downstack := range downstacks {
err := (&branchSubmitCmd{
submitOptions: cmd.submitOptions,
Branch: downstack,
}).run(ctx, session, log, view, repo, store, svc)
if err != nil {
return fmt.Errorf("submit %v: %w", downstack, err)
}
}
if cmd.DryRun {
return nil
}
return updateNavigationComments(
ctx,
store,
svc,
log,
cmd.NavigationComment,
session,
)
}