-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathdownstack_submit.go
More file actions
68 lines (57 loc) · 1.57 KB
/
Copy pathdownstack_submit.go
File metadata and controls
68 lines (57 loc) · 1.57 KB
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
package main
import (
"context"
"errors"
"fmt"
"slices"
"go.abhg.dev/gs/internal/git"
"go.abhg.dev/gs/internal/handler/submit"
"go.abhg.dev/gs/internal/must"
"go.abhg.dev/gs/internal/spice"
"go.abhg.dev/gs/internal/spice/state"
"go.abhg.dev/gs/internal/text"
)
type downstackSubmitCmd struct {
submitOptions
submit.BatchOptions
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,
wt *git.Worktree,
store *state.Store,
svc *spice.Service,
submitHandler SubmitHandler,
) error {
if cmd.Branch == "" {
currentBranch, err := wt.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")
}
graph, err := svc.BranchGraph(ctx, nil)
if err != nil {
return fmt.Errorf("build branch graph: %w", err)
}
downstacks := slices.Collect(graph.Downstack(cmd.Branch))
must.NotBeEmptyf(downstacks, "downstack cannot be empty")
slices.Reverse(downstacks)
// TODO: separate preparation of the stack from submission
return submitHandler.SubmitBatch(ctx, &submit.BatchRequest{
Branches: downstacks,
Options: &cmd.Options,
BatchOptions: &cmd.BatchOptions,
BranchGraph: graph,
})
}