From 0a5b78a510a7ed44ea833fb3e3da784e0243287d Mon Sep 17 00:00:00 2001 From: Kynan Ware <47394200+BagToad@users.noreply.github.com> Date: Fri, 29 Aug 2025 08:25:00 -0600 Subject: [PATCH] Refactor session filtering in listRun function Simplifies logic for filtering sessions to only include those with valid pull request and repository data. This reduces nested conditionals and improves code readability. --- pkg/cmd/agent-task/list/list.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/pkg/cmd/agent-task/list/list.go b/pkg/cmd/agent-task/list/list.go index b218242f4..ae498bfba 100644 --- a/pkg/cmd/agent-task/list/list.go +++ b/pkg/cmd/agent-task/list/list.go @@ -86,21 +86,14 @@ func listRun(opts *ListOptions) error { cs := opts.IO.ColorScheme() tp := tableprinter.New(opts.IO, tableprinter.WithHeader("Session ID", "Pull Request", "Repo", "Session State", "Created")) for _, s := range sessions { - pr := "" - if s.ResourceType == "pull" && s.PullRequest.Number != 0 { - pr = fmt.Sprintf("#%d", s.PullRequest.Number) - } else { - // Skip these sessions in case they happen, for now. - continue - } - repo := "" - if s.PullRequest.Repository != nil && s.PullRequest.Repository.NameWithOwner != "" { - repo = s.PullRequest.Repository.NameWithOwner - } else { + if s.ResourceType != "pull" || s.PullRequest == nil || s.PullRequest.Repository == nil { // Skip these sessions in case they happen, for now. continue } + pr := fmt.Sprintf("#%d", s.PullRequest.Number) + repo := s.PullRequest.Repository.NameWithOwner + // ID tp.AddField(s.ID) if tp.IsTTY() {