From 783d167f37f854d472f2fc8e6c30f93a0a79549a Mon Sep 17 00:00:00 2001 From: harryzcy Date: Tue, 10 Jan 2023 23:54:03 -0500 Subject: [PATCH] Update branch filtering --- cmd/pulls/merge.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/pulls/merge.go b/cmd/pulls/merge.go index e1785f0..775dae5 100644 --- a/cmd/pulls/merge.go +++ b/cmd/pulls/merge.go @@ -96,22 +96,21 @@ func getPullIndex(ctx *context.TeaContext, branch string) (int64, error) { return 0, fmt.Errorf("No open PRs found") } - prOptions := make([]string, len(prs)) + prOptions := make([]string, 0) - // get the PR index for the current branch first + // get the PR indexes where head branch is the current branch for _, pr := range prs { if pr.Head.Ref == branch { - prOptions[0] = fmt.Sprintf("#%d: %s", pr.Index, pr.Title) + prOptions = append(prOptions, fmt.Sprintf("#%d: %s", pr.Index, pr.Title)) } } - // then get the rest of the PRs - i := 1 + // then get the PR indexes where base branch is the current branch for _, pr := range prs { - if pr.Head.Ref != branch { - prOptions[i] = fmt.Sprintf("#%d: %s", pr.Index, pr.Title) + // don't add the same PR twice, so `pr.Head.Ref != branch` + if pr.Base.Ref == branch && pr.Head.Ref != branch { + prOptions = append(prOptions, fmt.Sprintf("#%d: %s", pr.Index, pr.Title)) } - i++ } selected := ""