fix(pr): prefer an open pull request over a merged one recorded by checkout

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 20:25:40 +02:00
1 parent 12972e6327
commit badd934d64
2 files changed
+27 -6

No files matched your search

+12 -1
View File
@@ -6,6 +6,7 @@ package app
import (
"context"
"net/http"
"strings"
"testing"
"gitea.dev/tea/internal/clierr"
@@ -59,10 +60,18 @@ func TestParseRefAcceptsNumbersQualifiedNumbersAndURLs(t *testing.T) {
// refApplication returns an application authenticated against a server listing the open pull
// requests #3 (feat/one in alice/project), #4 (feat/two), #17 (fix in bob/project) and two
// pull requests from branch dup.
// pull requests from branch dup. Viewing one pull request finds it open, except the merged #30.
func refApplication(t *testing.T, gitResults map[string]string) (*application, string) {
t.Helper()
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if number, ok := strings.CutPrefix(r.URL.Path, "/api/v1/repos/alice/project/pulls/"); ok {
state := "open"
if number == "30" {
state = "closed"
}
_, _ = w.Write([]byte(`{"number":` + number + `,"state":"` + state + `","merged":true}`))
return
}
require.Equal(t, "/api/v1/repos/alice/project/pulls", r.URL.Path)
writeFirstPage(w, r, `[
{"number":3,"head":{"ref":"feat/one","repo":{"full_name":"alice/project"}}},
@@ -111,6 +120,8 @@ func TestPullSelectorDefaultsToTheCheckedOutBranch(t *testing.T) {
}{
{"recorded by pr checkout", branch("pr/17", map[string]string{"tea-pr": "17", "tea-base-remote": "origin", "remote": "pulls/bob/project", "merge": "refs/heads/fix"}), 17, ""},
{"head branch name kept by pr checkout", branch("fix", map[string]string{"tea-pr": "17", "tea-base-remote": "origin"}), 17, ""},
{"recorded but merged, the head branch has a newer one", branch("fix", map[string]string{"tea-pr": "30", "tea-base-remote": "origin"}), 17, ""},
{"recorded but merged, no open one", branch("gone", map[string]string{"tea-pr": "30", "tea-base-remote": "origin"}), 30, ""},
{"recorded for another repository", branch("pr/9", map[string]string{"tea-pr": "9", "tea-base-remote": "fork", "remote": "fork", "merge": "refs/heads/fix"}), 17, ""},
{"upstream branch and owner", branch("local", map[string]string{"remote": "origin", "merge": "refs/heads/feat/one"}), 3, ""},
{"upstream owner tells forks apart", branch("dup", map[string]string{"remote": "pulls/carol/project", "merge": "refs/heads/dup"}), 21, ""},