-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathbranch_submit.go
More file actions
114 lines (91 loc) · 3.26 KB
/
branch_submit.go
File metadata and controls
114 lines (91 loc) · 3.26 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"context"
"fmt"
"go.abhg.dev/gs/internal/git"
"go.abhg.dev/gs/internal/handler/submit"
"go.abhg.dev/gs/internal/text"
)
// submitOptions defines options that are common to all submit commands.
type submitOptions struct {
submit.Options
NoWeb bool `help:"Alias for --web=false."`
// TODO: Other creation options e.g.:
// - milestone
}
const _submitHelp = `
Use --dry-run to print what would be submitted without submitting it.
For new Change Requests, a prompt will allow filling metadata.
Use --fill to populate title and body from the commit messages.
The --[no-]draft flag marks the CR as draft or not.
Use the 'spice.submit.draft' configuration option
to mark new CRs as drafts (or not) by default,
skipping the prompt.
For updating Change Requests,
use --[no-]draft to change its draft status.
Without the flag, the draft status is not changed.
Use --no-publish to push branches without creating CRs.
This has no effect if a branch already has an open CR.
Use --update-only to only update branches with existing CRs,
and skip those that would create new CRs.
Use --nav-comment=false to disable navigation comments in CRs,
or --nav-comment=multiple to post those comments
only if there are multiple CRs in the stack.
`
type branchSubmitCmd struct {
submitOptions
Title string `help:"Title of the change request" placeholder:"TITLE"`
Body string `help:"Body of the change request" placeholder:"BODY"`
Branch string `placeholder:"NAME" help:"Branch to submit" predictor:"trackedBranches"`
}
func (*branchSubmitCmd) Help() string {
return text.Dedent(`
A Change Request is created for the current branch,
or updated if it already exists.
Use the --branch flag to target a different branch.
For new Change Requests, a prompt will allow filling metadata.
Use the --title and --body flags to skip the prompt,
or the --fill flag to use the commit message to fill them in.
The --[no-]draft flag marks the CR as draft or not.
Use the 'spice.submit.draft' configuration option
to mark new CRs as drafts (or not) by default,
skipping the prompt.
For updating Change Requests,
use --[no-]draft to change its draft status.
Without the flag, the draft status is not changed.
Use --no-publish to push branches without creating CRs.
This has no effect if a branch already has an open CR.
Use --update-only to only update branches with existing CRs,
and skip those that would create new CRs.
Use --nav-comment=false to disable navigation comments in CRs,
or --nav-comment=multiple to post those comments
only if there are multiple CRs in the stack.
`)
}
// SubmitHandler submits change requests to a forge.
type SubmitHandler interface {
Submit(ctx context.Context, req *submit.Request) error
SubmitBatch(ctx context.Context, req *submit.BatchRequest) error
}
func (cmd *branchSubmitCmd) Run(
ctx context.Context,
wt *git.Worktree,
submitHandler SubmitHandler,
) error {
if cmd.NoWeb {
cmd.Web = submit.OpenWebNever
}
if cmd.Branch == "" {
currentBranch, err := wt.CurrentBranch(ctx)
if err != nil {
return fmt.Errorf("get current branch: %w", err)
}
cmd.Branch = currentBranch
}
return submitHandler.Submit(ctx, &submit.Request{
Branch: cmd.Branch,
Title: cmd.Title,
Body: cmd.Body,
Options: &cmd.Options,
})
}