Skip to content

Commit

Permalink
Add 'mark thread as done' functionality (google#3265)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhcole authored and rafaeldtinoco committed Sep 20, 2024
1 parent e19aede commit bccb3a1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions github/activity_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
26 changes: 26 additions & 0 deletions github/activity_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bccb3a1

Please sign in to comment.