From 217ea5a608ac325ea886e3f4094946a9b3c04c3b Mon Sep 17 00:00:00 2001 From: Daniel Cole Date: Sun, 15 Sep 2024 14:08:09 -0400 Subject: [PATCH 1/3] Add 'mark thread as done' functionality --- 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..32c37791d6b 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 string) (*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..19fde8a8fd7 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, "\n") + 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() From 4f124d7923f4ae6a0978c2b12bb1be7c3f9edb5e Mon Sep 17 00:00:00 2001 From: Daniel Cole Date: Mon, 16 Sep 2024 17:23:57 -0400 Subject: [PATCH 2/3] Change 'id' to int64 --- github/activity_notifications.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/activity_notifications.go b/github/activity_notifications.go index 32c37791d6b..e712323ed43 100644 --- a/github/activity_notifications.go +++ b/github/activity_notifications.go @@ -184,7 +184,7 @@ func (s *ActivityService) MarkThreadRead(ctx context.Context, id string) (*Respo // 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 string) (*Response, error) { +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) From e0c8cdf6bd95f7754e539233d4d8223d57a5cab3 Mon Sep 17 00:00:00 2001 From: Daniel Cole Date: Mon, 16 Sep 2024 19:07:26 -0400 Subject: [PATCH 3/3] Fix tests for MarkThreadDone to use int --- github/activity_notifications_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/activity_notifications_test.go b/github/activity_notifications_test.go index 19fde8a8fd7..0c224924cc8 100644 --- a/github/activity_notifications_test.go +++ b/github/activity_notifications_test.go @@ -218,19 +218,19 @@ func TestActivityService_MarkThreadDone(t *testing.T) { }) ctx := context.Background() - _, err := client.Activity.MarkThreadDone(ctx, "1") + _, 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, "\n") + _, err = client.Activity.MarkThreadDone(ctx, 0) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Activity.MarkThreadDone(ctx, "1") + return client.Activity.MarkThreadDone(ctx, 1) }) }