-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathstack_submit.go
More file actions
57 lines (49 loc) · 1.18 KB
/
stack_submit.go
File metadata and controls
57 lines (49 loc) · 1.18 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
package main
import (
"context"
"fmt"
"go.abhg.dev/gs/internal/git"
"go.abhg.dev/gs/internal/handler/submit"
"go.abhg.dev/gs/internal/spice"
"go.abhg.dev/gs/internal/spice/state"
"go.abhg.dev/gs/internal/text"
)
type stackSubmitCmd struct {
submitOptions
submit.BatchOptions
}
func (*stackSubmitCmd) Help() string {
return text.Dedent(`
Change Requests are created or updated
for all branches in the current stack.
`) + "\n" + _submitHelp
}
func (cmd *stackSubmitCmd) Run(
ctx context.Context,
wt *git.Worktree,
store *state.Store,
svc *spice.Service,
submitHandler SubmitHandler,
) error {
currentBranch, err := wt.CurrentBranch(ctx)
if err != nil {
return fmt.Errorf("get current branch: %w", err)
}
stack, err := svc.ListStack(ctx, currentBranch)
if err != nil {
return fmt.Errorf("list stack: %w", err)
}
toSubmit := stack[:0]
for _, branch := range stack {
if branch == store.Trunk() {
continue
}
toSubmit = append(toSubmit, branch)
}
// TODO: separate preparation of the stack from submission
return submitHandler.SubmitBatch(ctx, &submit.BatchRequest{
Branches: toSubmit,
Options: &cmd.Options,
BatchOptions: &cmd.BatchOptions,
})
}