-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support Preview hovercard API (#875) #890
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
Support Preview hovercard API (#875) #890
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
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.
Thanks for working on this. It's a good start.
I see some opportunities to improve this PR. I've left initial comments.
github/users.go
Outdated
} | ||
|
||
// UserContextualInfoResponse holds the parsed response from GetContextualInfo. | ||
type UserContextualInfoResponse struct { |
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.
To be more consistent with the existing API, let's rename this to UserContextualInfo
(without Response
suffix).
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.
Actually, what do you think about calling it Hovercard
? It's what the API endpoint is called:
GET /users/:username/hovercard
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 came to my mind but then I thought to keep the names consistent and hence changed it to UserContextualInfoResponse
, but Hovercard
seems much better name considering the API endpoint.
github/users.go
Outdated
// UserContext represents the contextual information about user. | ||
type UserContext struct { | ||
Message *string `url:"message,omitempty"` | ||
Octicon *string `url:"octicon,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.
Why is it url
in the struct field tag? Shouldn't it be json
?
github/users.go
Outdated
// method. | ||
type UserContextualInfoOptions struct { | ||
// SubjectType specifies the additional information to be received about the hovercard. | ||
// Possible values are : organization, repository, issue, pull_request. |
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.
Remove space before colon.
github/users.go
Outdated
return nil, nil, err | ||
} | ||
|
||
//TODO : remove custom Accept header when this API fully launches. |
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.
The spacing around TODO is a little unusual. Let's make it consistent. Move the space before colon to before TODO:
// TODO: remove custom Accept header when this API fully launches.
github/users.go
Outdated
//TODO : remove custom Accept header when this API fully launches. | ||
req.Header.Set("Accept", mediaTypeHovercardPreview) | ||
|
||
contextResp := new(UserContextualInfoResponse) |
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.
Give this variable a shorter name. Like uci
(for User Contextual Info).
github/users.go
Outdated
@@ -134,6 +134,55 @@ func (s *UsersService) Edit(ctx context.Context, user *User) (*User, *Response, | |||
return uResp, resp, nil | |||
} | |||
|
|||
// UserContextualInfoOptions specifies optional parameters to the UsersService.GetContextualInfo | |||
// method. | |||
type UserContextualInfoOptions struct { |
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 will be HovercardOptions
then.
github/users.go
Outdated
SubjectType string `url:"subject_type,omitempty"` | ||
|
||
// SubjectID specifies the ID for the SubjectType. | ||
SubjectID string `url:"subject_id,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.
Both the parameters are required, not optional. So remove ,omitempty
and add (Required.)
at the end of comment (like here).
Thanks for the suggestions @shurcooL . |
To use Hovercard api, authentication needs to be in place. |
Good call, let's do that. GitHub API v3 already documents that requirement at https://developer.github.com/v3/users/#get-contextual-information-about-a-user, but it will be nice if we mention it here too.
go-github/github/users_gpg_keys.go Lines 77 to 81 in 89a446e
Also, given we already renamed So, it can look something like this: // GetHovercard gets hovercard information for specified user. It requires authentication
// via Basic Auth or via OAuth with the repo scope.
//
// GitHub API docs: https://developer.github.com/v3/users/#get-contextual-information-about-a-user
func (s *UsersService) GetHovercard(ctx context.Context, user string, opt *HovercardOptions) (*Hovercard, *Response, error) Note that you should return the entire |
github/users.go
Outdated
// GetContextualInfo fetches contextual information about user. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/users/#get-contextual-information-about-a-user | ||
func (s *UsersService) GetContextualInfo(ctx context.Context, user string, opt *HovercardOptions) ([]*UserContext, *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.
Both options in HovercardOptions
are required. So, we should make opt
mandatory here as well. No need to make it a pointer, since nil
value can never be valid.
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 revisited the API documentation and it says "The subject_type
and subject_id
parameters provide context for the person's hovercard, which returns more information than without the parameters".
I tried using the API service without parameters and the response is empty contexts
array. (HTTP response code is 200)
Response without parameters:
{
"contexts": [ ]
}
So I was thinking whether to keep these parameters optional or mandatory ? Would like to hear your views @shurcooL
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.
Hey, any views on this?
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.
Sorry about the delay.
I see, it looks like they've updated the documentation to say that the two parameters are not mandatory, but if one is used, then the other is required too:
That means passing neither parameter is a valid operation.
So, we should keep it a pointer then, so it'd be possible to pass nil
value for *opt HovercardOptions
when both parameters are being left out.
We should also update the documentation of HovercardOptions
fields. Instead of "(Required.)", it should say something like "(Required when using subject_id.)" and "(Required when using subject_type.)", respectively.
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.
Great! Will keep the opt
optional and update the documentation. Should be done by today. Thanks @shurcooL
github/users.go
Outdated
req.Header.Set("Accept", mediaTypeHovercardPreview) | ||
|
||
contextResp := new(UserContextualInfoResponse) | ||
resp, err := s.client.Do(ctx, req, contextResp) | ||
uci := new(Hovercard) |
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.
uci
is no longer applicable. Make it hc
or hovercard
.
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.
Oops Sorry! missed it.
I will make the suggested improvements.
I have made the suggested changes. |
Hey @shurcooL , any views on these changes ? Let me know if it looks good to you |
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.
Thanks for working on this @MonicB14. The latest changes look good and this has my LGTM now. There's just one minor godoc issue (missing blank line in a comment) and a few optional suggestions. See inline comments.
github/users.go
Outdated
Octicon *string `json:"octicon,omitempty"` | ||
} | ||
|
||
// Hovercard holds the parsed response from GetHovercard. |
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.
It'd be nice if we could better describe what this struct is, rather than saying it's "what GetHovercard returns". Perhaps something like this?
// Hovercard represents hovercard information about a user.
It's not great, so you can go either way here.
github/users.go
Outdated
|
||
// GetHovercard fetches contextual information about user. It requires authentication | ||
// via Basic Auth or via OAuth with the repo scope. | ||
// GitHub API docs: https://developer.github.com/v3/users/#get-contextual-information-about-a-user |
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.
The // GitHub API docs: ...
line needs an empty line above, otherwise it gets parsed by godoc as part of the same paragraph, making it less readable. See here for example:
Lines 118 to 120 in d4c2343
// Edit the authenticated user. | |
// | |
// GitHub API docs: https://developer.github.com/v3/users/#update-the-authenticated-user |
github/users.go
Outdated
// Hovercard holds the parsed response from GetHovercard. | ||
type Hovercard struct { | ||
Contexts []*UserContext `json:"contexts,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.
It would be good to place Hovercard
on top of UserContext
. The general pattern is higher level identifiers should come first. They are easier to understand, and they set context for the lower level identifiers that follow. I.e.:
// Hovercard ...
type Hovercard struct {
...
}
// UserContext ...
type UserContext struct {
...
}
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
Fixes google#875. Closes google#890.
Fixes google#875. Closes google#890.
Add support for new preview Hovercard API as described in:
https://developer.github.com/changes/2018-03-21-hovercard-api-preview/
This PR adds:
Fixes: #875