forked from abhinav/git-spice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack_submit.go
75 lines (63 loc) · 1.41 KB
/
stack_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
package main
import (
"context"
"fmt"
"github.com/charmbracelet/log"
"go.abhg.dev/gs/internal/secret"
"go.abhg.dev/gs/internal/text"
"go.abhg.dev/gs/internal/ui"
)
type stackSubmitCmd struct {
submitOptions
}
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,
secretStash secret.Stash,
log *log.Logger,
view ui.View,
) error {
repo, store, svc, err := openRepo(ctx, log, view)
if err != nil {
return err
}
currentBranch, err := repo.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)
}
// TODO: generalize into a service-level method
// TODO: separate preparation of the stack from submission
session := newSubmitSession(repo, store, secretStash, view, log)
for _, branch := range stack {
if branch == store.Trunk() {
continue
}
err := (&branchSubmitCmd{
submitOptions: cmd.submitOptions,
Branch: branch,
}).run(ctx, session, repo, store, svc, log, view)
if err != nil {
return fmt.Errorf("submit %v: %w", branch, err)
}
}
if cmd.DryRun {
return nil
}
return updateNavigationComments(
ctx,
store,
svc,
log,
cmd.NavigationComment,
session,
)
}