Show conflicts to parent branch
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -375,3 +376,46 @@ func TestGetPullRequestUsesOriginalLineAndMetadata(t *testing.T) {
|
||||
t.Fatalf("unexpected comment snapshot: %#v", comment)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPullRequestLoadsConflictFilesForConflictingPR(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte(`{"data":{"repository":{
|
||||
"url":"https://github.com/o/r","pullRequest":{
|
||||
"id":"pr","number":3,"title":"Conflict","url":"u",
|
||||
"mergeable":"CONFLICTING","baseRefName":"main","headRefName":"feature",
|
||||
"headRefOid":"head123","baseRef":{"target":{"oid":"base123"}},
|
||||
"comments":{"pageInfo":{"hasNextPage":false}},
|
||||
"reviews":{"pageInfo":{"hasNextPage":false}},
|
||||
"timelineItems":{"pageInfo":{"hasNextPage":false}},
|
||||
"reviewThreads":{"pageInfo":{"hasNextPage":false}}
|
||||
}
|
||||
}}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := NewGitHubClient(server.URL, "secret")
|
||||
client.conflicts = func(
|
||||
_ context.Context,
|
||||
repositoryURL string,
|
||||
number int,
|
||||
baseRef, baseOID, headOID, token string,
|
||||
) ([]string, error) {
|
||||
if repositoryURL != "https://github.com/o/r" || number != 3 ||
|
||||
baseRef != "main" || baseOID != "base123" || headOID != "head123" ||
|
||||
token != "secret" {
|
||||
t.Fatalf(
|
||||
"conflict loader arguments = %q, %d, %q, %q, %q, %q",
|
||||
repositoryURL, number, baseRef, baseOID, headOID, token,
|
||||
)
|
||||
}
|
||||
return []string{"src/conflict.go", "README.md"}, nil
|
||||
}
|
||||
|
||||
got, err := client.GetPullRequest(context.Background(), "o", "r", 3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(got.ConflictFiles, []string{"src/conflict.go", "README.md"}) {
|
||||
t.Fatalf("conflict files = %#v", got.ConflictFiles)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user