Skip to content

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

Closed

Conversation

monicbhanushali
Copy link

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

@googlebot
Copy link

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. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@monicbhanushali
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes Indication that the PR author has signed a Google Contributor License Agreement. and removed cla: no labels Apr 8, 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.

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 {
Copy link
Member

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

Copy link
Member

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

Copy link
Author

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"`
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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)
Copy link
Member

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 {
Copy link
Member

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"`
Copy link
Member

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

@monicbhanushali
Copy link
Author

Thanks for the suggestions @shurcooL .
PR has been updated to address the suggested changes.

@monicbhanushali
Copy link
Author

To use Hovercard api, authentication needs to be in place.
Should a comment describing this be added in the new method?

@dmitshur
Copy link
Member

Should a comment describing this be added in the new method?

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.

UsersService.GetGPGKey method serves as a good template for how to do it:

// GetGPGKey gets extended details for a single GPG key. It requires authentication
// via Basic Auth or via OAuth with at least read:gpg_key scope.
//
// GitHub API docs: https://developer.github.com/v3/users/gpg_keys/#get-a-single-gpg-key
func (s *UsersService) GetGPGKey(ctx context.Context, id int64) (*GPGKey, *Response, error) {

Also, given we already renamed UserContextualInfoResponse to Hovercard and the endpoint is GET /users/:username/hovercard, I think we should apply the same change to the method name. It can be renamed to GetHovercard. What do you think?

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 *Hovercard from that method, not just []*UserContext. That way, if the hovercard gets extra fields in the future, they'll be a part of the response.

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) {
Copy link
Member

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.

Copy link
Author

@monicbhanushali monicbhanushali Apr 22, 2018

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

Copy link
Author

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?

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.

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:

image

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.

Copy link
Author

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)
Copy link
Member

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.

Copy link
Author

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.

@monicbhanushali
Copy link
Author

I have made the suggested changes.
Apologies for taking so long.

@monicbhanushali
Copy link
Author

monicbhanushali commented May 22, 2018

Hey @shurcooL , any views on these changes ? Let me know if it looks good to you

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.

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.
Copy link
Member

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
Copy link
Member

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:

go-github/github/users.go

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"`
}
Copy link
Member

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 {
    ...
}

@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@googlebot googlebot added cla: no and removed cla: yes Indication that the PR author has signed a Google Contributor License Agreement. labels Aug 10, 2018
@gmlewis gmlewis closed this in #973 Aug 10, 2018
gmlewis added a commit that referenced this pull request Aug 10, 2018
gmlewis added a commit to gmlewis/go-github that referenced this pull request Aug 10, 2018
n1lesh pushed a commit to n1lesh/go-github that referenced this pull request Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants