Skip to content

Commit 057ff1b

Browse files
authored
Add 'mark thread as done' functionality (#3265)
Fixes #3264.
1 parent 603bc4a commit 057ff1b

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

github/activity_notifications.go

+17
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@ func (s *ActivityService) MarkThreadRead(ctx context.Context, id string) (*Respo
178178
return s.client.Do(ctx, req, nil)
179179
}
180180

181+
// MarkThreadDone marks the specified thread as done.
182+
// Marking a thread as "done" is equivalent to marking a notification in your notification inbox on GitHub as done.
183+
//
184+
// GitHub API docs: https://docs.github.com/rest/activity/notifications#mark-a-thread-as-done
185+
//
186+
//meta:operation DELETE /notifications/threads/{thread_id}
187+
func (s *ActivityService) MarkThreadDone(ctx context.Context, id int64) (*Response, error) {
188+
u := fmt.Sprintf("notifications/threads/%v", id)
189+
190+
req, err := s.client.NewRequest("DELETE", u, nil)
191+
if err != nil {
192+
return nil, err
193+
}
194+
195+
return s.client.Do(ctx, req, nil)
196+
}
197+
181198
// GetThreadSubscription checks to see if the authenticated user is subscribed
182199
// to a thread.
183200
//

github/activity_notifications_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,32 @@ func TestActivityService_MarkThreadRead(t *testing.T) {
208208
})
209209
}
210210

211+
func TestActivityService_MarkThreadDone(t *testing.T) {
212+
client, mux, _, teardown := setup()
213+
defer teardown()
214+
215+
mux.HandleFunc("/notifications/threads/1", func(w http.ResponseWriter, r *http.Request) {
216+
testMethod(t, r, "DELETE")
217+
w.WriteHeader(http.StatusResetContent)
218+
})
219+
220+
ctx := context.Background()
221+
_, err := client.Activity.MarkThreadDone(ctx, 1)
222+
if err != nil {
223+
t.Errorf("Activity.MarkThreadDone returned error: %v", err)
224+
}
225+
226+
const methodName = "MarkThreadDone"
227+
testBadOptions(t, methodName, func() (err error) {
228+
_, err = client.Activity.MarkThreadDone(ctx, 0)
229+
return err
230+
})
231+
232+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
233+
return client.Activity.MarkThreadDone(ctx, 1)
234+
})
235+
}
236+
211237
func TestActivityService_GetThreadSubscription(t *testing.T) {
212238
client, mux, _, teardown := setup()
213239
defer teardown()

0 commit comments

Comments
 (0)