Skip to content

Prepare for a Typed Octokat - #1937

Closed
philschatz wants to merge 2 commits into
desktop:masterfrom
philschatz:octokat-typescript-prep
Closed

philschatz wants to merge 2 commits into
desktop:masterfrom
philschatz:octokat-typescript-prep

Conversation

@philschatz

@philschatz philschatz commented Jun 8, 2017 •

Copy link
Copy Markdown

Many responses from GitHub's API yield JSON that describes a User but are missing the name: field (see below for a partial list).

This Pull Request changes the API interface to match that expectation.

This work is part of philschatz/octokat.js#176 (add TypeScript Definitions) and refs #1522 and #1281

To verify that these are the only changes needed, I plugged the octokat/index.d.ts file into Desktop and ran the CI tests. Here is a branch of that work: philschatz/desktop@master...philschatz:octokat-typescript-example


GitHub API Routes and User Objects

The following routes yield a User with a name: field in the Response JSON:

GET /users/:username yields a 'UserWithName'
GET /user yields a 'UserWithName'

The following routes (39) yield a User that does not contain the name: field in the Response JSON:

[Click me] to see all the routes...
GET /repos/:owner/:repo/issues/events
GET /users/:username/starred
GET /user/starred
GET /repos/:owner/:repo/subscribers
GET /issues
GET /repos/:owner/:repo/issues
GET /repos/:owner/:repo/issues/:issue_number
GET /repos/:owner/:repo/assignees
GET /repos/:owner/:repo/issues/:issue_number/comments
GET /repos/:owner/:repo/issues/comments
GET /repos/:owner/:repo/issues/comments/:issue_comment_id
GET /repos/:owner/:repo/issues/:issue_number/events
GET /repos/:owner/:repo/issues/events
GET /repos/:owner/:repo/pulls/:pull_request_number
GET /repos/:owner/:repo/pulls/:pull_request_number/commits
GET /repos/:owner/:repo/pulls/:pull_request_number/reviews
GET /repos/:owner/:repo/pulls/:pull_request_number/reviews/:review_id
GET /repos/:owner/:repo/pulls/:pull_request_number/reviews/:review_id/comments
GET /repos/:owner/:repo/pulls/:pull_request_number/comments
GET /repos/:owner/:repo/pulls/comments
GET /user/repos
GET /users/:username/repos
GET /repositories/:repository_id
GET /repos/:owner/:repo
GET /repos/:owner/:repo/collaborators
GET /repos/:owner/:repo/collaborators/:username/permission
GET /repos/:owner/:repo/comments
GET /repos/:owner/:repo/commits/:commit_sha/comments
GET /repos/:owner/:repo/comments/:repo_comment_id
GET /repos/:owner/:repo/commits
GET /repos/:owner/:repo/commits/:commit_sha
GET /repos/:owner/:repo/deployments
GET /repos/:owner/:repo/pages/builds
GET /repos/:owner/:repo/pages/builds/latest
GET /users
GET /users/:username/followers
GET /user/followers
GET /users/:username/following
GET /user/following

@philschatz philschatz left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Some notes on the proposed changes

Comment thread app/src/lib/api.ts
export interface IAPIUser {
readonly id: number
readonly url: string
readonly type: 'user' | 'org'

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/lib/api.ts
}

return new Account(user.login, endpoint, token, emails, user.avatarUrl, user.id, user.name)
return new Account(user.login, endpoint, token, emails, user.avatar_url, user.id, user.name)

This comment was marked as spam.

This comment was marked as spam.

public async getAutocompletionItems(text: string): Promise<ReadonlyArray<IUserHit>> {
const users = await this.gitHubUserStore.getMentionableUsersMatching(this.repository, text)
return users.map(u => ({ username: u.login, name: u.name }))
return users.map(u => ({ username: u.login, name: u.name || u.login }))

This comment was marked as spam.

@joshaber joshaber self-assigned this Jun 8, 2017

@joshaber joshaber left a comment

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.

Thanks @philschatz! It's awesome you're looking into providing typings!

I'm a little concerned about the knock-on effects of making name optional everywhere. I imagine we should split it into two types so we're clear about where we can rely on name and where we can't.

@joshaber joshaber added the ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jun 8, 2017
@philschatz

philschatz commented Jun 10, 2017 •

Copy link
Copy Markdown
Author

Thanks for the feedback!

I split the IAPIUser type into 3:

  • IAPIUserNoName used when searching for users by email, or as part of an IAPICommit (to update the user store cache)
  • IAPIUserWithName used when getting the current user
  • IAPIOrganizationSlug used when getting the list of the current users' Organizations

As a result, the User autocomplete no longer tries to show the user name (it did not work before anyway).

Aside: I tend to be extra-verbose so it is easier to replace the names later but can rename them to something shorter like IAPIOrgSlug, IAPIUserSlug, and IAPIUser.

@joshaber

Copy link
Copy Markdown
Contributor

Thanks @philschatz! We're getting close:

As a result, the User autocomplete no longer tries to show the user name (it did not work before anyway).

It seems to be working for me currently, or maybe I'm misunderstanding?

screen shot 2017-06-13 at 11 53 29 am

@joshaber joshaber mentioned this pull request Jun 21, 2017
13 tasks done
@niik

niik commented Jun 22, 2017

Copy link
Copy Markdown
Member

Thanks for all your work here @philschatz! I'm personally really excited to see a strongly typed Octokat!

With #2080 moving us over to issuing API requests manually I'm going to close this PR.

@niik niik closed this Jun 22, 2017
@philschatz philschatz mentioned this pull request Feb 11, 2018
4 tasks done
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