From 272de12bf004f2ce2c4d59f1438cd2f19921d710 Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 1 Apr 2026 23:47:34 +0000 Subject: [PATCH] feat(users): add unblock helper Co-Authored-By: Virgil --- users.go | 6 ++++++ users_test.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/users.go b/users.go index ab52195..1cda90a 100644 --- a/users.go +++ b/users.go @@ -94,6 +94,12 @@ func (s *UserService) Block(ctx context.Context, username string) error { return s.client.Put(ctx, path, nil, nil) } +// Unblock unblocks a user as the authenticated user. +func (s *UserService) Unblock(ctx context.Context, username string) error { + path := ResolvePath("/api/v1/user/unblock/{username}", pathParams("username", username)) + return s.client.Put(ctx, path, nil, nil) +} + // ListMySubscriptions returns all repositories watched by the authenticated user. func (s *UserService) ListMySubscriptions(ctx context.Context) ([]types.Repository, error) { return ListAll[types.Repository](ctx, s.client, "/api/v1/user/subscriptions", nil) diff --git a/users_test.go b/users_test.go index 704e231..0c05aff 100644 --- a/users_test.go +++ b/users_test.go @@ -159,6 +159,24 @@ func TestUserService_Block_Good(t *testing.T) { } } +func TestUserService_Unblock_Good(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPut { + t.Errorf("expected PUT, got %s", r.Method) + } + if r.URL.Path != "/api/v1/user/unblock/alice" { + t.Errorf("wrong path: %s", r.URL.Path) + } + w.WriteHeader(http.StatusNoContent) + })) + defer srv.Close() + + f := NewForge(srv.URL, "tok") + if err := f.Users.Unblock(context.Background(), "alice"); err != nil { + t.Fatal(err) + } +} + func TestUserService_IterBlockedUsers_Good(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet {