From 057ff1b1ae61d4ea6e71b00b712b26b2650772cc Mon Sep 17 00:00:00 2001 From: Daniel Cole <10801604+danhcole@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:18:28 -0400 Subject: [PATCH] Add 'mark thread as done' functionality (#3265) Fixes #3264. --- github/activity_notifications.go | 17 +++++++++++++++++ github/activity_notifications_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/github/activity_notifications.go b/github/activity_notifications.go index 47f22261dd2..e712323ed43 100644 --- a/github/activity_notifications.go +++ b/github/activity_notifications.go @@ -178,6 +178,23 @@ func (s *ActivityService) MarkThreadRead(ctx context.Context, id string) (*Respo return s.client.Do(ctx, req, nil) } +// MarkThreadDone marks the specified thread as done. +// Marking a thread as "done" is equivalent to marking a notification in your notification inbox on GitHub as done. +// +// GitHub API docs: https://docs.github.com/rest/activity/notifications#mark-a-thread-as-done +// +//meta:operation DELETE /notifications/threads/{thread_id} +func (s *ActivityService) MarkThreadDone(ctx context.Context, id int64) (*Response, error) { + u := fmt.Sprintf("notifications/threads/%v", id) + + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + // GetThreadSubscription checks to see if the authenticated user is subscribed // to a thread. // diff --git a/github/activity_notifications_test.go b/github/activity_notifications_test.go index 815238ebb5e..0c224924cc8 100644 --- a/github/activity_notifications_test.go +++ b/github/activity_notifications_test.go @@ -208,6 +208,32 @@ func TestActivityService_MarkThreadRead(t *testing.T) { }) } +func TestActivityService_MarkThreadDone(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/notifications/threads/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusResetContent) + }) + + ctx := context.Background() + _, err := client.Activity.MarkThreadDone(ctx, 1) + if err != nil { + t.Errorf("Activity.MarkThreadDone returned error: %v", err) + } + + const methodName = "MarkThreadDone" + testBadOptions(t, methodName, func() (err error) { + _, err = client.Activity.MarkThreadDone(ctx, 0) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Activity.MarkThreadDone(ctx, 1) + }) +} + func TestActivityService_GetThreadSubscription(t *testing.T) { client, mux, _, teardown := setup() defer teardown()