diff --git a/users.go b/users.go index efb6d30..fac6f25 100644 --- a/users.go +++ b/users.go @@ -62,6 +62,16 @@ func (s *UserService) GetQuota(ctx context.Context) (*types.QuotaInfo, error) { return &out, nil } +// ListQuotaArtifacts returns all artifacts affecting the authenticated user's quota. +func (s *UserService) ListQuotaArtifacts(ctx context.Context) ([]types.QuotaUsedArtifact, error) { + return ListAll[types.QuotaUsedArtifact](ctx, s.client, "/api/v1/user/quota/artifacts", nil) +} + +// IterQuotaArtifacts returns an iterator over all artifacts affecting the authenticated user's quota. +func (s *UserService) IterQuotaArtifacts(ctx context.Context) iter.Seq2[types.QuotaUsedArtifact, error] { + return ListIter[types.QuotaUsedArtifact](ctx, s.client, "/api/v1/user/quota/artifacts", nil) +} + // ListEmails returns all email addresses for the authenticated user. func (s *UserService) ListEmails(ctx context.Context) ([]types.Email, error) { return ListAll[types.Email](ctx, s.client, "/api/v1/user/emails", nil) diff --git a/users_test.go b/users_test.go index 48c3802..6ea3c13 100644 --- a/users_test.go +++ b/users_test.go @@ -163,6 +163,66 @@ func TestUserService_GetQuota_Good(t *testing.T) { } } +func TestUserService_ListQuotaArtifacts_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/user/quota/artifacts" { + t.Errorf("wrong path: %s", r.URL.Path) + } + w.Header().Set("X-Total-Count", "2") + json.NewEncoder(w).Encode([]types.QuotaUsedArtifact{ + {Name: "artifact-1", Size: 123, HTMLURL: "https://example.com/actions/runs/1"}, + {Name: "artifact-2", Size: 456, HTMLURL: "https://example.com/actions/runs/2"}, + }) + })) + defer srv.Close() + + f := NewForge(srv.URL, "tok") + artifacts, err := f.Users.ListQuotaArtifacts(context.Background()) + if err != nil { + t.Fatal(err) + } + if len(artifacts) != 2 { + t.Fatalf("got %d artifacts, want 2", len(artifacts)) + } + if artifacts[0].Name != "artifact-1" || artifacts[0].Size != 123 { + t.Errorf("unexpected first artifact: %+v", artifacts[0]) + } +} + +func TestUserService_IterQuotaArtifacts_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/user/quota/artifacts" { + t.Errorf("wrong path: %s", r.URL.Path) + } + w.Header().Set("X-Total-Count", "1") + json.NewEncoder(w).Encode([]types.QuotaUsedArtifact{ + {Name: "artifact-1", Size: 123, HTMLURL: "https://example.com/actions/runs/1"}, + }) + })) + defer srv.Close() + + f := NewForge(srv.URL, "tok") + var got []types.QuotaUsedArtifact + for artifact, err := range f.Users.IterQuotaArtifacts(context.Background()) { + if err != nil { + t.Fatal(err) + } + got = append(got, artifact) + } + if len(got) != 1 { + t.Fatalf("got %d artifacts, want 1", len(got)) + } + if got[0].Name != "artifact-1" { + t.Errorf("unexpected artifact: %+v", got[0]) + } +} + func TestUserService_ListEmails_Good(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet {