Add repo topic add/delete helpers
All checks were successful
Security Scan / security (push) Successful in 9s
Test / test (push) Successful in 58s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 22:18:01 +00:00
parent 60a7c9420d
commit 221c5fa94f
2 changed files with 52 additions and 0 deletions

View file

@ -105,6 +105,18 @@ func (s *RepoService) UpdateTopics(ctx context.Context, owner, repo string, topi
return s.client.Put(ctx, path, types.RepoTopicOptions{Topics: topics}, nil)
}
// AddTopic adds a topic to a repository.
func (s *RepoService) AddTopic(ctx context.Context, owner, repo, topic string) error {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/topics/{topic}", pathParams("owner", owner, "repo", repo, "topic", topic))
return s.client.Put(ctx, path, nil, nil)
}
// DeleteTopic removes a topic from a repository.
func (s *RepoService) DeleteTopic(ctx context.Context, owner, repo, topic string) error {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/topics/{topic}", pathParams("owner", owner, "repo", repo, "topic", topic))
return s.client.Delete(ctx, path)
}
// GetNewPinAllowed returns whether new issue pins are allowed for a repository.
func (s *RepoService) GetNewPinAllowed(ctx context.Context, owner, repo string) (*types.NewIssuePinsAllowed, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/new_pin_allowed", pathParams("owner", owner, "repo", repo))

View file

@ -64,6 +64,46 @@ func TestRepoService_UpdateTopics_Good(t *testing.T) {
}
}
func TestRepoService_AddTopic_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.EscapedPath() != "/api/v1/repos/core/go-forge/topics/release%20candidate" {
t.Errorf("wrong path: %s", r.URL.EscapedPath())
http.NotFound(w, r)
return
}
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
if err := f.Repos.AddTopic(context.Background(), "core", "go-forge", "release candidate"); err != nil {
t.Fatal(err)
}
}
func TestRepoService_DeleteTopic_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodDelete {
t.Errorf("expected DELETE, got %s", r.Method)
}
if r.URL.EscapedPath() != "/api/v1/repos/core/go-forge/topics/release%20candidate" {
t.Errorf("wrong path: %s", r.URL.EscapedPath())
http.NotFound(w, r)
return
}
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
if err := f.Repos.DeleteTopic(context.Background(), "core", "go-forge", "release candidate"); err != nil {
t.Fatal(err)
}
}
func TestRepoService_GetNewPinAllowed_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {