feat(pulls): add pull lookup by base and head
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
39742d75c2
commit
4a7743a8ac
2 changed files with 39 additions and 0 deletions
15
pulls.go
15
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))
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue