Code Study: GitHub Desktop / lib / stores / github-user-store.ts

This is the store in charge of getting GitHub user profile based on username, getting mentionable GitHub users of certain repo, and matching commit authors to GitHub users and avatars.

GitHubUserStore

Private Fields

Public Methods

getByLogin(account: Account, login: string)

Retrieve a public user profile based on the user’s login (i.e. username).

The account parameter is the account to use when querying the API. The login parameter is the username of the user. The username gets passed to the GitHub’s get a single user API.

If the user is already in the local GitHubUserDatabase’s users table no additional API requests will be made. If the user isn’t in the local database but found in the API it will be persisted to the database and the intermediate cache.

The method returns Promise<IGitHubUser | null>. [IGitHubUser] is defined in github-user-database.ts for persisting the user’s info in the local database for performance reasons and offline scenarios.

getUsersForRepository(repository: Repository)

Get GitHub users of a given repository from the cache (usersByEndpoint).

updateMentionables(repository: GitHubRepository, account: Account)

Update the mentionable users for the repository. It fetches the mentionable users for the repository by calling an undocumented API from GitHub, stores the mentionable users per repo in the local GitHubUserDatabase’s mentionables table, stores the user profiles in the local GitHubUserDatabase’s users table, and cache the users in the usersByEndpoint object.

cacheUser(user: IGitHubUser, overwriteEmail: boolean)

This method is used both internally inside the GitHubUserStore and externally. It updates the user info in the GitHubUserDatabase’s users table, and in the cache (usersByEndpoint).

tags: GitHub Desktop - Electron