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 1 commit
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 string) (*Response, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

According to this: https://docs.github.com/en/rest/activity/notifications?apiVersion=2022-11-28#mark-a-thread-as-done
id is an integer, so let's please change this:

Suggested change
func (s *ActivityService) MarkThreadDone(ctx context.Context, id string) (*Response, error) {
func (s *ActivityService) MarkThreadDone(ctx context.Context, id int64) (*Response, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me, I'll update the PR. The MarkThreadRead function (which I shamelessly copied from) has the same issue, would you like me to fix it as part of this PR, or put in a separate PR to keep things clean?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, a separate PR would be great since that will be a breaking change. Thank you!

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