Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'mark thread as done' functionality #3265

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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")

Check failure on line 221 in github/activity_notifications_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use "1" (untyped string constant) as int64 value in argument to client.Activity.MarkThreadDone

Check failure on line 221 in github/activity_notifications_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use "1" (untyped string constant) as int64 value in argument to client.Activity.MarkThreadDone
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings will need to be changed to int64 for tests to pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whops, fixed and tests pass locally now.

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")

Check failure on line 228 in github/activity_notifications_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use "\n" (untyped string constant) as int64 value in argument to client.Activity.MarkThreadDone

Check failure on line 228 in github/activity_notifications_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use "\n" (untyped string constant) as int64 value in argument to client.Activity.MarkThreadDone
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Activity.MarkThreadDone(ctx, "1")

Check failure on line 233 in github/activity_notifications_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use "1" (untyped string constant) as int64 value in argument to client.Activity.MarkThreadDone (typecheck)

Check failure on line 233 in github/activity_notifications_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use "1" (untyped string constant) as int64 value in argument to client.Activity.MarkThreadDone) (typecheck)
})
}

func TestActivityService_GetThreadSubscription(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down
Loading