Skip to content
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

Prepare for a Typed Octokat #1937

Closed
wants to merge 2 commits into from

Conversation

philschatz
Copy link

@philschatz philschatz commented Jun 8, 2017

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

Copy link
Author

@philschatz philschatz left a comment

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

@@ -76,10 +76,9 @@ export interface IAPICommit {
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.

@@ -554,7 +553,7 @@ export async function fetchUser(endpoint: string, token: string): Promise<Accoun
emails = [ ]
}

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.

@@ -31,7 +31,7 @@ export class UserAutocompletionProvider implements IAutocompletionProvider<IUser

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

@joshaber joshaber left a comment

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

philschatz commented Jun 10, 2017

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

niik commented Jun 22, 2017

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.

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.

None yet

3 participants