Skip to content

make loadAndCacheUser more resilient to bad input - #6945

Merged
iAmWillShepherd merged 6 commits into
developmentfrom
review-users-from-api
Mar 12, 2019
Merged

iAmWillShepherd merged 6 commits into
developmentfrom
review-users-from-api

Conversation

@shiftkey

@shiftkey shiftkey commented Feb 26, 2019 •

Copy link
Copy Markdown
Member

Overview

Related to #6313

Description

This PR addresses a few things I uncovered during the investigation for #6313. I couldn't reproduce the "menus disabled" behaviour but I could trigger everything else.

Here's what I found:

  1. the GitHub API would return an empty object for the author for some commits, instead of null

This was fixed in 2484ff6 to add a runtime check that the object found is the expected shape and contents.

  1. our use of IAPIUser to represent a unified account does not reflect what was returned by the API. I uncovered three different shapes of data,

IAPIUser has been deprecated in favour of these three shapes in 8847ef6:

  • IAPIFullIdentity - this is the same shape as IAPIUser but is only used in two places - /user ( the details about the current user) and /users/{user} to find details about a GitHub account
  • IAPIIdentity - this is the subset of account information that is used in most places of the API - commits, pull requests, etc. No name or email is provided in this payload, irrespective of the privacy settings defined by the user. I didn't notice any strange issues downstream as a result of this change, but this is something to be mindful of while I'm doing more testing.
  • IAPIOrganization - the array of objects returned by /user/orgs is similar to IAPIIdentity, but for some reason omitted the type value (because only organizations are returned by this endpoint?).
  1. this problem commit had it's email address set to "" in Git

We have a few places where we look for a null email and bail out, so I also added checks for "" in 9d0a484 to save API calls when searching for a user.

Release notes

Notes: [Fixed] caching GitHub users does not handle edge case where email is empty string

@shiftkey
shiftkey force-pushed the review-users-from-api branch from 299a24a to 9d0a484 Compare February 26, 2019 14:26
@shiftkey shiftkey added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Feb 26, 2019
@shiftkey shiftkey added this to the 1.7.0 milestone Feb 26, 2019
@shiftkey
shiftkey marked this pull request as ready for review February 26, 2019 18:06
Comment thread app/src/lib/api.ts
* Minimum subset of an identity returned by the GitHub API
*/
export interface IAPIIdentity {
readonly id: number

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking

Is it possible to use a sum/intersection type here to take advantage of the fact that these same fields are defined in the type above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't really see the value in coupling these together to save on typings because it felt like a different version of our mistake of assuming IAPIUser everywhere. Also, using IAPIOrganization (a special case returned by a specific API) to derive IAPIIdentity (a more general case used broadly in the API) doesn't make sense to me from a composition side.

@iAmWillShepherd iAmWillShepherd self-assigned this Mar 8, 2019
@ahxlaaaaiy

This comment has been minimized.

@iAmWillShepherd
iAmWillShepherd merged commit ce4b9e0 into development Mar 12, 2019
@iAmWillShepherd
iAmWillShepherd deleted the review-users-from-api branch March 12, 2019 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants