diff --git a/pulls.go b/pulls.go index bdab33d..5f00e98 100644 --- a/pulls.go +++ b/pulls.go @@ -68,6 +68,21 @@ func (s *PullService) IterFiles(ctx context.Context, owner, repo string, index i return ListIter[types.ChangedFile](ctx, s.client, path, nil) } +// GetByBaseHead returns a pull request for a given base and head branch pair. +func (s *PullService) GetByBaseHead(ctx context.Context, owner, repo, base, head string) (*types.PullRequest, error) { + path := ResolvePath("/api/v1/repos/{owner}/{repo}/pulls/{base}/{head}", pathParams( + "owner", owner, + "repo", repo, + "base", base, + "head", head, + )) + var out types.PullRequest + if err := s.client.Get(ctx, path, &out); err != nil { + return nil, err + } + return &out, nil +} + // ListReviewers returns all users who can be requested to review a pull request. func (s *PullService) ListReviewers(ctx context.Context, owner, repo string) ([]types.User, error) { path := ResolvePath("/api/v1/repos/{owner}/{repo}/reviewers", pathParams("owner", owner, "repo", repo)) diff --git a/pulls_test.go b/pulls_test.go index 65225cf..79571fc 100644 --- a/pulls_test.go +++ b/pulls_test.go @@ -151,6 +151,30 @@ func TestPullService_ListFiles_Good(t *testing.T) { } } +func TestPullService_GetByBaseHead_Good(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + t.Errorf("expected GET, got %s", r.Method) + } + if r.URL.Path != "/api/v1/repos/core/go-forge/pulls/main/feature" { + t.Errorf("wrong path: %s", r.URL.Path) + http.NotFound(w, r) + return + } + json.NewEncoder(w).Encode(types.PullRequest{Index: 7, Title: "Add feature"}) + })) + defer srv.Close() + + f := NewForge(srv.URL, "tok") + pr, err := f.Pulls.GetByBaseHead(context.Background(), "core", "go-forge", "main", "feature") + if err != nil { + t.Fatal(err) + } + if pr.Index != 7 || pr.Title != "Add feature" { + t.Fatalf("got %+v", pr) + } +} + func TestPullService_IterFiles_Good(t *testing.T) { requests := 0 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {