feat(pulls): add pull lookup by base and head
All checks were successful
Security Scan / security (push) Successful in 22s
Test / test (push) Successful in 1m44s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 02:37:16 +00:00
parent 39742d75c2
commit 4a7743a8ac
2 changed files with 39 additions and 0 deletions

View file

@ -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))

View file

@ -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) {