feat: expose repository pull reviewers
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
43e99eb0d6
commit
67aad89cc4
2 changed files with 83 additions and 0 deletions
12
pulls.go
12
pulls.go
|
|
@ -50,6 +50,18 @@ func (s *PullService) IterReviews(ctx context.Context, owner, repo string, index
|
|||
return ListIter[types.PullReview](ctx, s.client, path, 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))
|
||||
return ListAll[types.User](ctx, s.client, path, nil)
|
||||
}
|
||||
|
||||
// IterReviewers returns an iterator over all users who can be requested to review a pull request.
|
||||
func (s *PullService) IterReviewers(ctx context.Context, owner, repo string) iter.Seq2[types.User, error] {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/reviewers", pathParams("owner", owner, "repo", repo))
|
||||
return ListIter[types.User](ctx, s.client, path, nil)
|
||||
}
|
||||
|
||||
// SubmitReview creates a new review on a pull request.
|
||||
func (s *PullService) SubmitReview(ctx context.Context, owner, repo string, index int64, review map[string]any) (*types.PullReview, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/pulls/{index}/reviews", pathParams("owner", owner, "repo", repo, "index", int64String(index)))
|
||||
|
|
|
|||
|
|
@ -94,6 +94,77 @@ func TestPullService_Create_Good(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPullService_ListReviewers_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/reviewers" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode([]types.User{
|
||||
{UserName: "alice"},
|
||||
{UserName: "bob"},
|
||||
})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
reviewers, err := f.Pulls.ListReviewers(context.Background(), "core", "go-forge")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(reviewers) != 2 || reviewers[0].UserName != "alice" || reviewers[1].UserName != "bob" {
|
||||
t.Fatalf("got %#v", reviewers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPullService_IterReviewers_Good(t *testing.T) {
|
||||
requests := 0
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests++
|
||||
if r.Method != http.MethodGet {
|
||||
t.Errorf("expected GET, got %s", r.Method)
|
||||
}
|
||||
if r.URL.Path != "/api/v1/repos/core/go-forge/reviewers" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
switch requests {
|
||||
case 1:
|
||||
if got := r.URL.Query().Get("page"); got != "1" {
|
||||
t.Errorf("got page=%q, want %q", got, "1")
|
||||
}
|
||||
w.Header().Set("X-Total-Count", "2")
|
||||
json.NewEncoder(w).Encode([]types.User{{UserName: "alice"}})
|
||||
case 2:
|
||||
if got := r.URL.Query().Get("page"); got != "2" {
|
||||
t.Errorf("got page=%q, want %q", got, "2")
|
||||
}
|
||||
w.Header().Set("X-Total-Count", "2")
|
||||
json.NewEncoder(w).Encode([]types.User{{UserName: "bob"}})
|
||||
default:
|
||||
t.Fatalf("unexpected request %d", requests)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
var got []string
|
||||
for reviewer, err := range f.Pulls.IterReviewers(context.Background(), "core", "go-forge") {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got = append(got, reviewer.UserName)
|
||||
}
|
||||
if len(got) != 2 || got[0] != "alice" || got[1] != "bob" {
|
||||
t.Fatalf("got %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPullService_Merge_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue