feat(users): add quota artifact listing
All checks were successful
Security Scan / security (push) Successful in 12s
Test / test (push) Successful in 1m32s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 01:59:52 +00:00
parent c63e45d9e7
commit a383ece924
2 changed files with 70 additions and 0 deletions

View file

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

View file

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