Skip to content

Support preview Team Discussions API #889

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

Merged
merged 4 commits into from
Apr 27, 2018
Merged

Support preview Team Discussions API #889

merged 4 commits into from
Apr 27, 2018

Conversation

parkhyukjun89
Copy link
Contributor

Fixes #849
https://developer.github.com/changes/2018-02-07-team-discussions-api/#new-rest-api-endpoints

Second part of the change https://developer.github.com/changes/2018-02-07-team-discussions-api/#updates-to-the-teams-api-documentation will be done in a separate PR, once this PR is merged.

- Add a new service TeamsService to support API related to Organization Teams https://developer.github.com/v3/teams/
- Add methods to support new preview API for team discussions https://developer.github.com/v3/teams/discussions/
- Add methods to support new preview API for team discussion comments https://developer.github.com/v3/teams/discussion_comments/

Fixes #849
https://developer.github.com/changes/2018-02-07-team-discussions-api/
@googlebot googlebot added the cla: yes Indication that the PR author has signed a Google Contributor License Agreement. label Apr 3, 2018
Copy link
Contributor

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

This is looking great, @parkhyukjun89... thank you!
I have a few minor points that would be nice to address, and then I want to take a second pass while looking more closely at the docs.

"fmt"
)

// DiscussionComment represents a GitHub dicussion in a team
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: end comment with a period.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

}

// DiscussionCommentListOptions specifies optional parameters to the
// TeamServices.ListComments method
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: end comment with a period.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#create-a-comment
func (s *TeamsService) CreateComment(ctx context.Context, team, discussion int64, comment *DiscussionComment) (*DiscussionComment, *Response, error) {
u := fmt.Sprintf("teams/%v/discussions/%v/comments", team, discussion)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking we might want to check for comment == nil here and return an error if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a nil check

github/teams.go Outdated
@@ -0,0 +1,7 @@
package github

// TeamsService provides access to the team related functions
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/team related/team-related/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

// User is allowed to edit body of a comment only.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#edit-a-comment
func (s *TeamsService) EditComment(ctx context.Context, team, discussion, id int64, comment *DiscussionComment) (*DiscussionComment, *Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might also want to check for comment == nil here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a nil check

Copy link
Member

Choose a reason for hiding this comment

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

Similarly, what do you think of just making comment a value rather than pointer here as well?

}

// DiscussionListOptions specifies optional parameters to the
// TeamServices.ListDiscussions method
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: end comment with a period.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

type DiscussionListOptions struct {
// Sorts the discussion by the date they were created.
// Accepted values are asc and desc. Default is desc.
Direction string `url:"direction,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need to include ListOptions here? I haven't yet checked the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

type DiscussionCommentListOptions struct {
// Sorts the discussion comments by the date they were created.
// Accepted values are asc and desc. Default is desc.
Direction string `url:"direction,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need to include ListOptions here? I haven't yet checked the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// Authenticated user must grant write:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussions/#create-a-discussion
func (s *TeamsService) CreateDiscussion(ctx context.Context, team int64, discussion *TeamDiscussion) (*TeamDiscussion, *Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to check for discussion == nil here and return an error if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a nil check

// User is allowed to change Title and Body of a discussion only.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussions/#edit-a-discussion
func (s *TeamsService) EditDiscussion(ctx context.Context, team, id int64, discussion *TeamDiscussion) (*TeamDiscussion, *Response, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to check for discussion == nil here and return an error if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a nil check

@parkhyukjun89
Copy link
Contributor Author

Travis build failed at 'go get' stage.

package golang.org/x/tools/cmd/cover: unrecognized import path "golang.org/x/tools/cmd/cover" (https fetch: Get https://golang.org/x/tools/cmd/cover?go-get=1: net/http: TLS handshake timeout)

Is there a way to kick off another build?

@dmitshur
Copy link
Member

I've restarted the Travis build, it's passing now.

Copy link
Contributor

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @parkhyukjun89!
LGTM.
Awaiting second LGTM before merging.

@gmlewis
Copy link
Contributor

gmlewis commented Apr 18, 2018

It looks like merge conflicts need resolving, @parkhyukjun89. Either you can do that, or I can take a look at it later today.

@parkhyukjun89
Copy link
Contributor Author

Resolved merge conflict @gmlewis

Copy link
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

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

This looks great overall, but there are a few API-related concerns I think we should pay attention to, and consider changing before merging.

// Authenticated user must grant read:discussion scope.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#get-a-single-comment
func (s *TeamsService) GetComment(ctx context.Context, team, discussion, id int64) (*DiscussionComment, *Response, error) {
Copy link
Member

Choose a reason for hiding this comment

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

team, discussion, id int64

I think we'll need to take care of this (here, and elsewhere).

From looking over the API, it does seem they use "number" instead of "id" to identify discussions and comments within said discussions.

However, I haven't actually used team discussions, so I can't confirm if this matches the reality.

From https://developer.github.com/v3/teams/discussion_comments/#get-a-single-comment, I'm seeing:

GET /teams/:team_id/discussions/:discussion_number/comments/:comment_number

That tells me that the first parameter is a team ID (which we want to use int64 for), second one is the discussion number (not ID), which we want to map to int, and the comment also seems to be a number rather than ID (hence int).

I suggest we follow that closely and therefore use:

teamID int64, discussionNumber, commentNumber int

Let me know what you think, or if you have any concerns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Discussion & comment numbers are incrementing numbers.

func (s *TeamsService) CreateComment(ctx context.Context, team, discussion int64, comment *DiscussionComment) (*DiscussionComment, *Response, error) {
if comment == nil {
return nil, nil, errors.New("comment must be provided")
}
Copy link
Member

Choose a reason for hiding this comment

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

We did the if pull == nil change for existing endpoints where a pointer was already used (see PR #539), in order to avoid making a breaking API change.

Since this is a new API, I think we can simplify things and just make comment a value rather than pointer. After all, it's required.

It would be a little inconsistent with previous endpoints that use pointers, but I think it's a beneficial tradeoff. What do you think?

Copy link
Contributor Author

@parkhyukjun89 parkhyukjun89 Apr 23, 2018

Choose a reason for hiding this comment

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

Understood. But, what if user decides to pass in an empty struct. Should that be considered an error and need to be guarded against?

Copy link
Member

@dmitshur dmitshur Apr 25, 2018

Choose a reason for hiding this comment

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

But, what if user decides to pass in an empty struct. Should that be considered an error and need to be guarded against?

I think it's okay to let the GitHub API handle such an incorrect request (with a descriptive error message). We shouldn't, because it adds code, and it's not worth it (most people will not try to create an invalid comment, other than during testing). We don't try to catch empty or invalid input in all other endpoints either.

Making it a value rather than pointer is more about eliminating an unnecessary choice and making the API more intuitive to use. Since there's no reason to use a pointer (other than being consistent with prior unfortunate API choices, which isn't a strong enough reason I think), we shouldn't use it.

// User is allowed to edit body of a comment only.
//
// GitHub API docs: https://developer.github.com/v3/teams/discussion_comments/#edit-a-comment
func (s *TeamsService) EditComment(ctx context.Context, team, discussion, id int64, comment *DiscussionComment) (*DiscussionComment, *Response, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, what do you think of just making comment a value rather than pointer here as well?

- remove use of pointers
- use int for incrementing numbers
@parkhyukjun89
Copy link
Contributor Author

@shurcooL made changes accordingly

Copy link
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

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

I think the changes are fantastic. The parameter names are very clear, and using values (over pointers) for mandatory parameters removes ambiguity. Thanks for doing that.

LGTM.

@gmlewis Do the changes look okay to you too?

Copy link
Contributor

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Very nice! I like these changes a lot.
Thank you, @parkhyukjun89 and @shurcooL!
LGTM.
Merging.

@gmlewis gmlewis merged commit 29336db into google:master Apr 27, 2018
Copy link
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

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

I just spotted a few minor issues.

It should be easy to fix them, since this code has been merged very recently, there can’t be many users of it yet.

DiscussionURL *string `json:"discussion_url,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Number *int64 `json:"number,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

I just noticed this, it’s not an ID, so it should be int. We use int type for all numbers other than IDs.

Body *string `json:"body,omitempty"`
BodyHTML *string `json:"body_html,omitempty"`
BodyVersion *string `json:"body_version,omitempty"`
CommentsCount *int64 `json:"comments_count,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Also here, should be int.

LastEditedAt *Timestamp `json:"last_edited_at,omitempty"`
HTMLURL *string `json:"html_url,omitempty"`
NodeID *string `json:"node_id,omitempty"`
Number *int64 `json:"number,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Also here.

@gmlewis
Copy link
Contributor

gmlewis commented Apr 27, 2018

Great catches, @shurcooL! Thank you!

@parkhyukjun89
Copy link
Contributor Author

I will add those fixes in the next pr for https://developer.github.com/changes/2018-02-07-team-discussions-api/#updates-to-the-teams-api-documentation

nbareil pushed a commit to nbareil/go-github that referenced this pull request May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Indication that the PR author has signed a Google Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants