Skip to content

Commit

Permalink
feat(prs): reopen pr command
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolev Hadar authored and dlvhdr committed Sep 5, 2022
1 parent fb4d011 commit 05be3d1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ui/components/prssection/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/dlvhdr/gh-dash/ui/constants"
"github.com/dlvhdr/gh-dash/ui/context"
"github.com/dlvhdr/gh-dash/utils"
)

func (m *Model) close() tea.Cmd {
Expand Down Expand Up @@ -39,7 +40,7 @@ func (m *Model) close() tea.Cmd {
Err: err,
Msg: UpdatePRMsg{
PrNumber: prNumber,
IsClosed: true,
IsClosed: utils.BoolPtr(true),
},
}
})
Expand Down
17 changes: 12 additions & 5 deletions ui/components/prssection/prssection.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) {
case key.Matches(msg, keys.PRKeys.Ready):
cmd = m.ready()

case key.Matches(msg, keys.PRKeys.Reopen):
cmd = m.reopen()

case msg.Type == tea.KeyEnter:
m.SearchValue = m.SearchBar.Value()
m.SetIsSearching(false)
Expand All @@ -79,13 +82,17 @@ func (m Model) Update(msg tea.Msg) (section.Section, tea.Cmd) {
case UpdatePRMsg:
for i, currPr := range m.Prs {
if currPr.Number == msg.PrNumber {
if msg.IsClosed {
currPr.State = "CLOSED"
if msg.IsClosed != nil {
if *msg.IsClosed == true {
currPr.State = "CLOSED"
} else {
currPr.State = "OPEN"
}
}
if msg.NewComment != nil {
currPr.Comments.Nodes = append(currPr.Comments.Nodes, *msg.NewComment)
}
if msg.ReadyForReview {
if msg.ReadyForReview != nil && *msg.ReadyForReview {
currPr.IsDraft = false
}
m.Prs[i] = currPr
Expand Down Expand Up @@ -238,7 +245,7 @@ func FetchAllSections(ctx context.ProgramContext) (sections []section.Section, f

type UpdatePRMsg struct {
PrNumber int
IsClosed bool
IsClosed *bool
NewComment *data.Comment
ReadyForReview bool
ReadyForReview *bool
}
3 changes: 2 additions & 1 deletion ui/components/prssection/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/dlvhdr/gh-dash/ui/constants"
"github.com/dlvhdr/gh-dash/ui/context"
"github.com/dlvhdr/gh-dash/utils"
)

func (m *Model) ready() tea.Cmd {
Expand Down Expand Up @@ -39,7 +40,7 @@ func (m *Model) ready() tea.Cmd {
Err: err,
Msg: UpdatePRMsg{
PrNumber: prNumber,
ReadyForReview: true,
ReadyForReview: utils.BoolPtr(true),
},
}
})
Expand Down
47 changes: 47 additions & 0 deletions ui/components/prssection/reopen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package prssection

import (
"fmt"
"os/exec"

tea "github.com/charmbracelet/bubbletea"
"github.com/dlvhdr/gh-dash/ui/constants"
"github.com/dlvhdr/gh-dash/ui/context"
"github.com/dlvhdr/gh-dash/utils"
)

func (m *Model) reopen() tea.Cmd {
pr := m.GetCurrRow()
prNumber := pr.GetNumber()
taskId := fmt.Sprintf("reopen_%d", prNumber)
task := context.Task{
Id: taskId,
StartText: fmt.Sprintf("Reopening PR #%d", prNumber),
FinishedText: fmt.Sprintf("PR #%d has been reopened", prNumber),
State: context.TaskStart,
Error: nil,
}
startCmd := m.Ctx.StartTask(task)
return tea.Batch(startCmd, func() tea.Msg {
c := exec.Command(
"gh",
"pr",
"reopen",
fmt.Sprint(m.GetCurrRow().GetNumber()),
"-R",
m.GetCurrRow().GetRepoNameWithOwner(),
)

err := c.Run()
return constants.TaskFinishedMsg{
SectionId: m.Id,
SectionType: SectionType,
TaskId: taskId,
Err: err,
Msg: UpdatePRMsg{
PrNumber: prNumber,
IsClosed: utils.BoolPtr(false),
},
}
})
}
6 changes: 6 additions & 0 deletions ui/keys/prKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type PRKeyMap struct {
Diff key.Binding
Checkout key.Binding
Close key.Binding
Ready key.Binding
Reopen key.Binding
}

Expand All @@ -31,6 +32,10 @@ var PRKeys = PRKeyMap{
key.WithKeys("X"),
key.WithHelp("X", "reopen"),
),
Ready: key.NewBinding(
key.WithKeys("w"),
key.WithHelp("w", "ready for review"),
),
}

func PRFullHelp() []key.Binding {
Expand All @@ -39,6 +44,7 @@ func PRFullHelp() []key.Binding {
PRKeys.Diff,
PRKeys.Checkout,
PRKeys.Close,
PRKeys.Ready,
PRKeys.Reopen,
}
}

0 comments on commit 05be3d1

Please sign in to comment.