-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
- 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/
There was a problem hiding this 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.
github/teams_discussion_comments.go
Outdated
"fmt" | ||
) | ||
|
||
// DiscussionComment represents a GitHub dicussion in a team |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
github/teams_discussion_comments.go
Outdated
} | ||
|
||
// DiscussionCommentListOptions specifies optional parameters to the | ||
// TeamServices.ListComments method |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
github/teams_discussion_comments.go
Outdated
// | ||
// 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
github/teams_discussion_comments.go
Outdated
// 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a nil check
There was a problem hiding this comment.
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?
github/teams_discussions.go
Outdated
} | ||
|
||
// DiscussionListOptions specifies optional parameters to the | ||
// TeamServices.ListDiscussions method |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
github/teams_discussions.go
Outdated
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"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc mentions directions only https://developer.github.com/v3/teams/discussions/#parameters
github/teams_discussion_comments.go
Outdated
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"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc mentions directions only https://developer.github.com/v3/teams/discussion_comments/#parameters
github/teams_discussions.go
Outdated
// 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_discussions.go
Outdated
// 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a nil check
Travis build failed at 'go get' stage.
Is there a way to kick off another build? |
I've restarted the Travis build, it's passing now. |
There was a problem hiding this 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.
It looks like merge conflicts need resolving, @parkhyukjun89. Either you can do that, or I can take a look at it later today. |
Resolved merge conflict @gmlewis |
There was a problem hiding this 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.
github/teams_discussion_comments.go
Outdated
// 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
github/teams_discussion_comments.go
Outdated
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") | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
github/teams_discussion_comments.go
Outdated
// 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) { |
There was a problem hiding this comment.
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
@shurcooL made changes accordingly |
There was a problem hiding this 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?
There was a problem hiding this 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.
There was a problem hiding this 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"` |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here.
Great catches, @shurcooL! Thank you! |
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 |
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.