Skip to content

Commit 0c41524

Browse files
committed
Add DeleteAllTagBindings to projects
1 parent 9e23f0e commit 0c41524

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

project.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type Projects interface {
4444

4545
// AddTagBindings adds or modifies the value of existing tag binding keys for a project.
4646
AddTagBindings(ctx context.Context, projectID string, options ProjectAddTagBindingsOptions) ([]*TagBinding, error)
47+
48+
// DeleteAllTagBindings removes all existing tag bindings for a project.
49+
DeleteAllTagBindings(ctx context.Context, projectID string) error
4750
}
4851

4952
// projects implements Projects
@@ -326,6 +329,30 @@ func (s *projects) Delete(ctx context.Context, projectID string) error {
326329
return req.Do(ctx, nil)
327330
}
328331

332+
// Delete all tag bindings associated with a project.
333+
func (s *projects) DeleteAllTagBindings(ctx context.Context, projectID string) error {
334+
if !validStringID(&projectID) {
335+
return ErrInvalidProjectID
336+
}
337+
338+
type aliasOpts struct {
339+
Type string `jsonapi:"primary,projects"`
340+
TagBindings []*TagBinding `jsonapi:"relation,tag-bindings"`
341+
}
342+
343+
opts := &aliasOpts{
344+
TagBindings: []*TagBinding{},
345+
}
346+
347+
u := fmt.Sprintf("projects/%s", url.PathEscape(projectID))
348+
req, err := s.client.NewRequest("PATCH", u, opts)
349+
if err != nil {
350+
return err
351+
}
352+
353+
return req.Do(ctx, nil)
354+
}
355+
329356
func (o ProjectCreateOptions) valid() error {
330357
if !validString(&o.Name) {
331358
return ErrRequiredName

projects_integration_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,33 @@ func TestProjectsAddTagBindings(t *testing.T) {
380380
})
381381
}
382382

383+
func TestProjects_DeleteAllTagBindings(t *testing.T) {
384+
skipUnlessBeta(t)
385+
386+
client := testClient(t)
387+
ctx := context.Background()
388+
389+
pTest, wCleanup := createProject(t, client, nil)
390+
t.Cleanup(wCleanup)
391+
392+
tagBindings := []*TagBinding{
393+
{Key: "foo", Value: "bar"},
394+
{Key: "baz", Value: "qux"},
395+
}
396+
397+
_, err := client.Projects.AddTagBindings(ctx, pTest.ID, ProjectAddTagBindingsOptions{
398+
TagBindings: tagBindings,
399+
})
400+
require.NoError(t, err)
401+
402+
err = client.Projects.DeleteAllTagBindings(ctx, pTest.ID)
403+
require.NoError(t, err)
404+
405+
bindings, err := client.Projects.ListTagBindings(ctx, pTest.ID)
406+
require.NoError(t, err)
407+
require.Empty(t, bindings)
408+
}
409+
383410
func TestProjectsDelete(t *testing.T) {
384411
client := testClient(t)
385412
ctx := context.Background()

0 commit comments

Comments
 (0)