Skip to content

Commit

Permalink
fix: missing nil pointer check on PRs and Issues view #527
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujun-dev authored and dlvhdr committed Feb 21, 2025
1 parent e495592 commit 742131b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
12 changes: 12 additions & 0 deletions ui/components/issuesidebar/issuesidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ func (m *Model) shouldCancelComment() bool {
}

func (m *Model) SetIsCommenting(isCommenting bool) tea.Cmd {
if m.issue == nil {
return nil
}

if !m.isCommenting && isCommenting {
m.inputBox.Reset()
}
Expand All @@ -288,6 +292,10 @@ func (m *Model) GetIsAssigning() bool {
}

func (m *Model) SetIsAssigning(isAssigning bool) tea.Cmd {
if m.issue == nil {
return nil
}

if !m.isAssigning && isAssigning {
m.inputBox.Reset()
}
Expand Down Expand Up @@ -317,6 +325,10 @@ func (m *Model) GetIsUnassigning() bool {
}

func (m *Model) SetIsUnassigning(isUnassigning bool) tea.Cmd {
if m.issue == nil {
return nil
}

if !m.isUnassigning && isUnassigning {
m.inputBox.Reset()
}
Expand Down
16 changes: 16 additions & 0 deletions ui/components/prsidebar/prsidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ func (m *Model) shouldCancelComment() bool {
}

func (m *Model) SetIsCommenting(isCommenting bool) tea.Cmd {
if m.pr == nil {
return nil
}

if !m.isCommenting && isCommenting {
m.inputBox.Reset()
}
Expand All @@ -399,6 +403,10 @@ func (m *Model) GetIsApproving() bool {
}

func (m *Model) SetIsApproving(isApproving bool) tea.Cmd {
if m.pr == nil {
return nil
}

if !m.isApproving && isApproving {
m.inputBox.Reset()
}
Expand All @@ -417,6 +425,10 @@ func (m *Model) GetIsAssigning() bool {
}

func (m *Model) SetIsAssigning(isAssigning bool) tea.Cmd {
if m.pr == nil {
return nil
}

if !m.isAssigning && isAssigning {
m.inputBox.Reset()
}
Expand Down Expand Up @@ -446,6 +458,10 @@ func (m *Model) GetIsUnassigning() bool {
}

func (m *Model) SetIsUnassigning(isUnassigning bool) tea.Cmd {
if m.pr == nil {
return nil
}

if !m.isUnassigning && isUnassigning {
m.inputBox.Reset()
}
Expand Down
4 changes: 4 additions & 0 deletions ui/components/prssection/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (

func (m *Model) checkout() (tea.Cmd, error) {
pr := m.GetCurrRow()
if pr == nil {
return nil, errors.New("No pr selected")
}

repoName := pr.GetRepoNameWithOwner()
repoPath, ok := common.GetRepoLocalPath(repoName, m.Ctx.Config.RepoPaths)

Expand Down
7 changes: 6 additions & 1 deletion ui/components/prssection/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import (
)

func (m Model) diff() tea.Cmd {
currRowData := m.GetCurrRow()
if currRowData == nil {
return nil
}

c := exec.Command(
"gh",
"pr",
"diff",
fmt.Sprint(m.GetCurrRow().GetNumber()),
fmt.Sprint(currRowData.GetNumber()),
"-R",
m.GetCurrRow().GetRepoNameWithOwner(),
)
Expand Down
4 changes: 4 additions & 0 deletions ui/components/prssection/watchChecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (

func (m *Model) watchChecks() tea.Cmd {
pr := m.GetCurrRow()
if pr == nil {
return nil
}

prNumber := pr.GetNumber()
title := pr.GetTitle()
url := pr.GetUrl()
Expand Down
2 changes: 1 addition & 1 deletion ui/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (m *Model) openBrowser() tea.Cmd {
openCmd := func() tea.Msg {
b := browser.New("", os.Stdout, os.Stdin)
currRow := m.getCurrRowData()
if reflect.ValueOf(currRow).IsNil() {
if currRow == nil || reflect.ValueOf(currRow).IsNil() {
return constants.TaskFinishedMsg{TaskId: taskId, Err: errors.New("Current selection doesn't have a URL")}
}
err := b.Browse(currRow.GetUrl())
Expand Down
25 changes: 12 additions & 13 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
footerCmd tea.Cmd
cmds []tea.Cmd
currSection = m.getCurrSection()
currRowData = m.getCurrRowData()
)

switch msg := msg.(type) {
Expand Down Expand Up @@ -259,13 +260,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

case key.Matches(msg, m.keys.CopyNumber):
row := m.getCurrRowData()
var cmd tea.Cmd
if reflect.ValueOf(row).IsNil() {
if currRowData == nil || reflect.ValueOf(currRowData).IsNil() {
cmd = m.notifyErr("Current selection isn't associated with a PR/Issue")
return m, cmd
}
number := fmt.Sprint(row.GetNumber())
number := fmt.Sprint(currRowData.GetNumber())
err := clipboard.WriteAll(number)
if err != nil {
cmd = m.notifyErr(fmt.Sprintf("Failed copying to clipboard %v", err))
Expand All @@ -276,12 +276,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

case key.Matches(msg, m.keys.CopyUrl):
var cmd tea.Cmd
row := m.getCurrRowData()
if reflect.ValueOf(row).IsNil() {
if currRowData == nil || reflect.ValueOf(currRowData).IsNil() {
cmd = m.notifyErr("Current selection isn't associated with a PR/Issue")
return m, cmd
}
url := row.GetUrl()
url := currRowData.GetUrl()
err := clipboard.WriteAll(url)
if err != nil {
cmd = m.notifyErr(fmt.Sprintf("Failed copying to clipboard %v", err))
Expand Down Expand Up @@ -377,35 +376,35 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd

case key.Matches(msg, keys.PRKeys.Close):
if currSection != nil {
if currRowData != nil && currSection != nil {
currSection.SetPromptConfirmationAction("close")
cmd = currSection.SetIsPromptConfirmationShown(true)
}
return m, cmd

case key.Matches(msg, keys.PRKeys.Ready):
if currSection != nil {
if currRowData != nil && currSection != nil {
currSection.SetPromptConfirmationAction("ready")
cmd = currSection.SetIsPromptConfirmationShown(true)
}
return m, cmd

case key.Matches(msg, keys.PRKeys.Reopen):
if currSection != nil {
if currRowData != nil && currSection != nil {
currSection.SetPromptConfirmationAction("reopen")
cmd = currSection.SetIsPromptConfirmationShown(true)
}
return m, cmd

case key.Matches(msg, keys.PRKeys.Merge):
if currSection != nil {
if currRowData != nil && currSection != nil {
currSection.SetPromptConfirmationAction("merge")
cmd = currSection.SetIsPromptConfirmationShown(true)
}
return m, cmd

case key.Matches(msg, keys.PRKeys.Update):
if currSection != nil {
if currRowData != nil && currSection != nil {
currSection.SetPromptConfirmationAction("update")
cmd = currSection.SetIsPromptConfirmationShown(true)
}
Expand Down Expand Up @@ -455,14 +454,14 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd

case key.Matches(msg, keys.IssueKeys.Close):
if currSection != nil {
if currRowData != nil && currSection != nil {
currSection.SetPromptConfirmationAction("close")
cmd = currSection.SetIsPromptConfirmationShown(true)
}
return m, cmd

case key.Matches(msg, keys.IssueKeys.Reopen):
if currSection != nil {
if currRowData != nil && currSection != nil {
currSection.SetPromptConfirmationAction("reopen")
cmd = currSection.SetIsPromptConfirmationShown(true)
}
Expand Down

0 comments on commit 742131b

Please sign in to comment.