Skip to content

Commit 3d3081e

Browse files
committed
dead code cleanup
1 parent 1cc2ace commit 3d3081e

9 files changed

Lines changed: 17 additions & 197 deletions

File tree

‎cmd/submit.go‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ This command performs several steps:
4646
3. Updates base branches for existing PRs
4747
4. Creates or updates the stack on GitHub
4848
49-
In the editor, new PRs default to ready for review; toggle "Open as draft" per
50-
PR. With --auto, new PRs are created as drafts unless you pass --open.`,
49+
In the editor, new PRs default to ready for review; switch any to draft with the
50+
"CREATE AS" toggle. With --auto, new PRs are created as drafts unless you pass
51+
--open.`,
5152
Example: ` # Push and create/update PRs (opens the interactive editor)
5253
$ gh stack submit
5354
@@ -284,7 +285,6 @@ func collectPRDrafts(cfg *config.Config, client github.ClientOps, s *stack.Stack
284285
model := submitview.New(submitview.Options{
285286
Nodes: nodes,
286287
Trunk: s.Trunk,
287-
StackName: stackDisplayName(s),
288288
RepoLabel: repoLabel,
289289
Version: Version,
290290
})
@@ -310,22 +310,6 @@ func collectPRDrafts(cfg *config.Config, client github.ClientOps, s *stack.Stack
310310
return submitview.BuildDrafts(m.Nodes()), false, nil
311311
}
312312

313-
// stackDisplayName returns a human-readable name for the stack, used in the TUI
314-
// header: the stack prefix, else the common branch-name prefix, else the
315-
// bottom-most branch.
316-
func stackDisplayName(s *stack.Stack) string {
317-
if s.Prefix != "" {
318-
return strings.TrimRight(s.Prefix, "/")
319-
}
320-
if p := submitview.CommonPrefix(s.BranchNames()); p != "" {
321-
return strings.TrimRight(p, "/")
322-
}
323-
if len(s.Branches) > 0 {
324-
return s.Branches[0].Branch
325-
}
326-
return s.Trunk.Branch
327-
}
328-
329313
// ensurePR finds or creates a PR for the branch at index i, and updates
330314
// its base branch if needed. This is the single place where PR state is
331315
// reconciled during submit.

‎cmd/submit_tui_test.go‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,6 @@ import (
1111
"github.com/stretchr/testify/require"
1212
)
1313

14-
func TestStackDisplayName(t *testing.T) {
15-
tests := []struct {
16-
name string
17-
s *stack.Stack
18-
want string
19-
}{
20-
{
21-
name: "uses stack prefix",
22-
s: &stack.Stack{Prefix: "feat/", Trunk: stack.BranchRef{Branch: "main"}},
23-
want: "feat",
24-
},
25-
{
26-
name: "falls back to common branch prefix",
27-
s: &stack.Stack{
28-
Trunk: stack.BranchRef{Branch: "main"},
29-
Branches: []stack.BranchRef{{Branch: "feat/auth/a"}, {Branch: "feat/auth/b"}},
30-
},
31-
want: "feat/auth",
32-
},
33-
{
34-
name: "single branch falls back to its name",
35-
s: &stack.Stack{
36-
Trunk: stack.BranchRef{Branch: "main"},
37-
Branches: []stack.BranchRef{{Branch: "solo"}},
38-
},
39-
want: "solo",
40-
},
41-
{
42-
name: "no branches falls back to trunk",
43-
s: &stack.Stack{Trunk: stack.BranchRef{Branch: "main"}},
44-
want: "main",
45-
},
46-
}
47-
for _, tt := range tests {
48-
t.Run(tt.name, func(t *testing.T) {
49-
assert.Equal(t, tt.want, stackDisplayName(tt.s))
50-
})
51-
}
52-
}
53-
5414
// TestCollectPRDrafts_SkipsWhenNoNewBranches verifies the TUI is skipped (no
5515
// program launched) when every branch already has a PR, returning nil drafts so
5616
// the normal push/relink path runs.

‎internal/tui/submitview/data.go‎

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func CountSelected(nodes []SubmitNode) int {
124124
}
125125

126126
// HasClosed reports whether any branch in the list has a closed PR, which blocks
127-
// the stack and triggers the Step 1 callout.
127+
// the stack and triggers the closed-branch callout.
128128
func HasClosed(nodes []SubmitNode) bool {
129129
for _, node := range nodes {
130130
if node.State == StateClosed {
@@ -145,63 +145,6 @@ func ClosedBranches(nodes []SubmitNode) []string {
145145
return names
146146
}
147147

148-
// CommonPrefix returns the longest shared slash-delimited path prefix across the
149-
// given branch names, including a trailing slash. It returns "" when fewer than
150-
// two names are given or there is no shared prefix. This is used to render the
151-
// stack map with short branch names.
152-
func CommonPrefix(names []string) string {
153-
if len(names) < 2 {
154-
return ""
155-
}
156-
157-
// Split each name into slash-delimited segments and find the longest run of
158-
// leading segments common to all names.
159-
segs := make([][]string, len(names))
160-
minLen := -1
161-
for i, n := range names {
162-
segs[i] = strings.Split(n, "/")
163-
// The last segment is the leaf name; only path segments before it can
164-
// be part of a shared prefix.
165-
pathLen := len(segs[i]) - 1
166-
if minLen == -1 || pathLen < minLen {
167-
minLen = pathLen
168-
}
169-
}
170-
if minLen <= 0 {
171-
return ""
172-
}
173-
174-
common := 0
175-
for i := 0; i < minLen; i++ {
176-
seg := segs[0][i]
177-
same := true
178-
for j := 1; j < len(segs); j++ {
179-
if segs[j][i] != seg {
180-
same = false
181-
break
182-
}
183-
}
184-
if !same {
185-
break
186-
}
187-
common++
188-
}
189-
if common == 0 {
190-
return ""
191-
}
192-
return strings.Join(segs[0][:common], "/") + "/"
193-
}
194-
195-
// Shortname strips prefix from branch when present, returning the remainder. If
196-
// branch does not start with prefix (or prefix is empty), branch is returned
197-
// unchanged.
198-
func Shortname(branch, prefix string) string {
199-
if prefix == "" {
200-
return branch
201-
}
202-
return strings.TrimPrefix(branch, prefix)
203-
}
204-
205148
// humanize replaces hyphens and underscores with spaces. It mirrors the helper
206149
// used by the submit command so auto-generated titles match across paths.
207150
func humanize(s string) string {

‎internal/tui/submitview/data_test.go‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -199,29 +199,3 @@ func TestClosedBranches(t *testing.T) {
199199
}
200200
assert.Equal(t, []string{"feat/legacy"}, ClosedBranches(nodes))
201201
}
202-
203-
func TestCommonPrefix(t *testing.T) {
204-
tests := []struct {
205-
name string
206-
names []string
207-
want string
208-
}{
209-
{"shared two-segment prefix", []string{"feat/auth/a", "feat/auth/b", "feat/auth/c"}, "feat/auth/"},
210-
{"shared one-segment prefix", []string{"feat/a", "feat/b"}, "feat/"},
211-
{"no shared prefix", []string{"feat/a", "fix/b"}, ""},
212-
{"single name has no prefix", []string{"feat/a"}, ""},
213-
{"empty list", nil, ""},
214-
{"flat names share nothing", []string{"a", "b"}, ""},
215-
}
216-
for _, tt := range tests {
217-
t.Run(tt.name, func(t *testing.T) {
218-
assert.Equal(t, tt.want, CommonPrefix(tt.names))
219-
})
220-
}
221-
}
222-
223-
func TestShortname(t *testing.T) {
224-
assert.Equal(t, "middleware", Shortname("feat/auth/middleware", "feat/auth/"))
225-
assert.Equal(t, "feat/auth/middleware", Shortname("feat/auth/middleware", ""))
226-
assert.Equal(t, "other/x", Shortname("other/x", "feat/auth/"))
227-
}

‎internal/tui/submitview/model.go‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ type Options struct {
4242
Nodes []SubmitNode
4343
// Trunk is the stack's trunk branch, shown for context.
4444
Trunk stack.BranchRef
45-
// StackName is the human-readable stack name shown in the header.
46-
StackName string
4745
// RepoLabel is the "owner/repo" string shown in the header.
4846
RepoLabel string
4947
// Version is the CLI version string.
@@ -54,14 +52,9 @@ type Options struct {
5452
type Model struct {
5553
nodes []SubmitNode
5654
trunk stack.BranchRef
57-
stackName string
5855
repoLabel string
5956
version string
6057

61-
// prefix is the common slash-delimited branch-name prefix, used to render
62-
// short branch names in the stack map.
63-
prefix string
64-
6558
cursor int // index into nodes (the focused branch)
6659

6760
width, height int
@@ -85,9 +78,6 @@ type Model struct {
8578
statusMessage string
8679
statusIsError bool
8780

88-
// hoverRow is the node index currently under the mouse pointer, or -1.
89-
hoverRow int
90-
9181
// leftScroll is the first visible row offset of the left stack timeline when
9282
// its content is taller than the panel.
9383
leftScroll int
@@ -115,11 +105,6 @@ type Model struct {
115105
// opens immediately with the first branch focused (preferring the first NEW
116106
// branch) and the title field ready for editing.
117107
func New(opts Options) Model {
118-
branchNames := make([]string, len(opts.Nodes))
119-
for i, n := range opts.Nodes {
120-
branchNames[i] = n.Ref.Branch
121-
}
122-
123108
// Start on the bottom-most NEW branch (closest to trunk) — the first PR
124109
// created, in stack order. Nodes are ordered top (index 0) to bottom, so the
125110
// bottom-most NEW branch is the highest-indexed one.
@@ -144,12 +129,9 @@ func New(opts Options) Model {
144129
m := Model{
145130
nodes: opts.Nodes,
146131
trunk: opts.Trunk,
147-
stackName: opts.StackName,
148132
repoLabel: opts.RepoLabel,
149133
version: opts.Version,
150-
prefix: CommonPrefix(branchNames),
151134
cursor: cursor,
152-
hoverRow: -1,
153135

154136
titleInput: ti,
155137
descArea: ta,

‎internal/tui/submitview/model_test.go‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func testModel(t *testing.T, nodes []SubmitNode) Model {
5252
m := New(Options{
5353
Nodes: nodes,
5454
Trunk: stack.BranchRef{Branch: "main"},
55-
StackName: "feat/auth",
5655
RepoLabel: "myorg/myrepo",
5756
Version: "1.0.0",
5857
})
@@ -88,11 +87,6 @@ func TestNew_AllNewIncludedByDefault(t *testing.T) {
8887
assert.True(t, m.nodes[1].Included)
8988
}
9089

91-
func TestNew_ComputesPrefix(t *testing.T) {
92-
m := testModel(t, newNodes())
93-
assert.Equal(t, "feat/auth/", m.prefix)
94-
}
95-
9690
// --- navigation ---
9791

9892
func TestNavigation_MovesAcrossAllBranches(t *testing.T) {
@@ -359,14 +353,6 @@ func TestMouse_ClickCheckboxToggles(t *testing.T) {
359353
assert.False(t, m.nodes[0].Included)
360354
}
361355

362-
func TestMouse_HoverTracksRow(t *testing.T) {
363-
m := testModel(t, newNodes())
364-
y, _ := leftBranchNode(m, 2)
365-
updated, _ := m.Update(tea.MouseMsg{Action: tea.MouseActionMotion, X: 6, Y: y})
366-
m = updated.(Model)
367-
assert.Equal(t, 2, m.hoverRow)
368-
}
369-
370356
// leftBranchNode returns the screen Y of branch idx's node line and the X of its
371357
// right-edge checkbox, using the live left-panel timeline layout (scroll-aware).
372358
func leftBranchNode(m Model, idx int) (y, checkboxX int) {

‎internal/tui/submitview/mouse.go‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ func (m Model) handleMouse(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
1414
}
1515

1616
switch msg.Action {
17-
case tea.MouseActionMotion:
18-
m.updateHover(msg.X, msg.Y)
19-
return m, nil
2017
case tea.MouseActionPress:
2118
leftW, _ := m.panelWidths()
2219
overLeft := msg.X >= 0 && msg.X < leftW
@@ -299,8 +296,3 @@ func (m *Model) positionDescCursor(visRow, col int) {
299296
}
300297
m.descArea.SetCursor(m.descArea.LineInfo().StartColumn + col)
301298
}
302-
303-
// updateHover tracks the branch row under the pointer for hover styling.
304-
func (m *Model) updateHover(x, y int) {
305-
m.hoverRow = m.branchRowAt(x, y)
306-
}

‎internal/tui/submitview/styles.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ func (s BranchState) Label() string {
4646
// Color returns the foreground color associated with a state.
4747
func (s BranchState) Color() lipgloss.Color { return stateColors[s] }
4848

49-
// Dot returns the compact legend glyph for a state, used in the Step 2 stack
50-
// map and legend.
49+
// Dot returns the compact status glyph for a state.
5150
func (s BranchState) Dot() string {
5251
switch s {
5352
case StateNew:

‎internal/tui/submitview/types.go‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Package submitview implements the interactive two-step TUI used by
2-
// `gh stack submit` to create a stack of pull requests. Step 1 selects which
3-
// branches without a PR should become PRs; Step 2 is a two-panel editor for
4-
// drafting each PR's title, description, and draft state before a single
5-
// batch submit.
1+
// Package submitview implements the interactive single-screen TUI used by
2+
// `gh stack submit` to create a stack of pull requests. A left-hand timeline
3+
// lists the stack and lets the user choose which branches without a PR should
4+
// become PRs; the right-hand editor drafts each PR's title, description, and
5+
// ready/draft state before a single batch submit.
66
//
77
// The package builds on the shared Charm components in internal/tui/shared and
88
// reuses the branch display data loaded by internal/tui/stackview. The submit
@@ -15,13 +15,13 @@ import (
1515
)
1616

1717
// BranchState classifies a branch by the status of its pull request. The state
18-
// determines whether a branch is selectable in Step 1, editable in Step 2, and
19-
// which badge color it renders with.
18+
// determines whether a branch is selectable and editable in the TUI, and which
19+
// badge color it renders with.
2020
type BranchState int
2121

2222
const (
2323
// StateNew is a branch with no PR yet. It is the only interactive state:
24-
// selectable in Step 1 (default on) and editable in Step 2.
24+
// selectable (default on) and editable.
2525
StateNew BranchState = iota
2626
// StateOpen is a branch with an open (non-draft) PR. Locked, shown for context.
2727
StateOpen
@@ -36,12 +36,12 @@ const (
3636
StateClosed
3737
)
3838

39-
// Selectable reports whether a branch in this state can be toggled in Step 1.
40-
// Only NEW branches are selectable.
39+
// Selectable reports whether a branch in this state can be toggled for
40+
// inclusion. Only NEW branches are selectable.
4141
func (s BranchState) Selectable() bool { return s == StateNew }
4242

43-
// Editable reports whether a branch in this state opens the editor in Step 2.
44-
// Only NEW branches are editable.
43+
// Editable reports whether a branch in this state opens the editor. Only NEW
44+
// branches are editable.
4545
func (s BranchState) Editable() bool { return s == StateNew }
4646

4747
// Locked reports whether a branch is shown for context only (open, draft,

0 commit comments

Comments
 (0)