Support preview GraphQL API v4 Node IDs by anubhakushwaha · Pull Request #817 · google/go-github · GitHub
Skip to content

Support preview GraphQL API v4 Node IDs#817

Merged
dmitshur merged 15 commits into
google:masterfrom
anubhakushwaha:graphQL
Jan 9, 2018
Merged

Support preview GraphQL API v4 Node IDs#817
dmitshur merged 15 commits into
google:masterfrom
anubhakushwaha:graphQL

Conversation

@anubhakushwaha

@anubhakushwaha anubhakushwaha commented Dec 23, 2017

Copy link
Copy Markdown
Contributor

Helps #814 .
The current pull request includes the GraphQL node ID in the response for the following REST API v3 resources:

  • Deployments
  • Gists
  • Git Blobs
  • Git Commits
  • Git References
  • Git Tags
  • Issues
  • Labels
  • Milestones
  • Organizations

@googlebot

Copy link
Copy Markdown

@anubhakushwaha

Copy link
Copy Markdown
Contributor Author

I signed it!

@googlebot

Copy link
Copy Markdown

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 Dec 23, 2017
@anubhakushwaha

Copy link
Copy Markdown
Contributor Author

@gmlewis @shurcooL I have added GraphQL node ID in the response, let me know if I am doing it correctly and would love to correct and work upon my mistakes.Thanks!

@anubhakushwaha anubhakushwaha force-pushed the graphQL branch 3 times, most recently from 4e56d34 to 0fe4ed7 Compare December 23, 2017 16:50

@dmitshur dmitshur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a large change, thank you for taking it on @anubhakushwaha!

It's looking great at a high level so far. I've spotted a few minor issues and change suggestions for you to consider, see inline comments.

Comment thread github/gists.go
@@ -193,6 +209,9 @@ func (s *GistsService) GetRevision(ctx context.Context, id, sha string) (*Gist,
if err != nil {
return nil, nil, err
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a blank line here for consistency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread github/git_blobs_test.go Outdated

if m := mediaTypeGraphQLNodeIDPreview; m != r.Header.Get("Accept") {
t.Errorf("Request accept header = %v, want %v", r.Header.Get("Accept"), m)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, why not use testHeader(t, r, "Accept", mediaTypeGraphQLNodeIDPreview) helper here?

@anubhakushwaha anubhakushwaha Dec 24, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@shurcooL While working on this file, I noticed that in git_blobs_test.go and git_trees_test.go we have used:

  if m := "GET"; m != r.Method {
  	t.Errorf("Request method = %v, want %v", r.Method, m)
         }

which is tested differently from the rest of the files for the header method where we have done it like :

  testMethod(t, r, "GET")

Is their any specific reason for doing so? I implemented the test on the accept header to maintain the consistency with the respective files. Let me know your thoughts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@anubhakushwaha IMO, the inconsistency in git_trees_test.go and git_blobs_test.go is by accident rather than having any reasoning behind it. I'll suggest you to use testHeader in your PR to make it consistent with the entire package.

We should instead fix the inconsistency to avoid confusions like this one in future.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sahildua2305 Thanks for the suggestion, will update the PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you still planning to do this? Just checking.

Comment thread github/gists.go Outdated
GitPushURL *string `json:"git_push_url,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
NodeID *string `json:"node_id,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line and many others aren't gofmted. You'll want to use gofmt command to format all these files. You can either invoke it directly in this directory:

gofmt -l -w .

Or you can format the entire package via go's fmt subcommand:

https://golang.org/cmd/go/#hdr-Run_gofmt_on_package_sources

go fmt github.com/google/go-github/github

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @shurcooL Resolved!

Comment thread github/git_blobs_test.go Outdated

if m := mediaTypeGraphQLNodeIDPreview; m != r.Header.Get("Accept") {
t.Errorf("Request accept header = %v, want %v", r.Header.Get("Accept"), m)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Queried above.

mux.HandleFunc("/repos/o/r/git/commits/s", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeGitSigningPreview)
testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", "))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is minor and either way is fine, but I'll make the suggestion for you to consider.

Since acceptHeaders is only used here, you can declare it right here. No need to declare it that much earlier:

acceptHeaders := []string{mediaTypeGitSigningPreview, mediaTypeGraphQLNodeIDPreview}
testHeader(t, r, "Accept", strings.Join(acceptHeaders, ", "))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@shurcooL It was done to maintain consistency with the rest of the files when we had multiple mediaType values. Let me know if I should change it 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay, keeping it as is is completely acceptable.

@dmitshur

dmitshur commented Dec 24, 2017

Copy link
Copy Markdown
Member

Also, you should edit the PR description and replace "Partially fixes #814." with something like "Helps #814." because GitHub syntax doesn't recognize the word "partially". It only sees "fixes #814", so it'll close that issue when this is merged, which isn't what you want.

@anubhakushwaha anubhakushwaha force-pushed the graphQL branch 4 times, most recently from 46b1c2e to 6e4b5f4 Compare December 24, 2017 08:32
@anubhakushwaha anubhakushwaha mentioned this pull request Dec 24, 2017
4 tasks
@kshitij10496

Copy link
Copy Markdown

The build is failing due to formatting issues with the code.

Run $ gofmt -d -s .in a terminal from the base directory of the repo.
This will show the diff of all formatting issues with the code.
I think fixing them should resolve the build failure.

@anubhakushwaha

Copy link
Copy Markdown
Contributor Author

@kshitij10496 Thanks, I will keep it in mind from future 😄

Comment thread github/issues_labels.go
}

// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One of the reasons of failing Travis, forgot to add it previously.

@dmitshur dmitshur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few minor comments. Otherwise this is looking good, not seeing other issues or opportunities for improvement.

It's hard to verify definitively which exact objects get the new NodeID field. I tried to confirm, and it looks good, but I can't give definitive guarantees. For example, I'm not quite sure if DeploymentStatus should get NodeID (it probably should, but I'm not 100% confident). GitHub documentation doesn't make it very easy to know for sure, so I think this is as good as it can be for the first version.

Comment thread github/git_commits.go Outdated
// Pulls.ListCommits, Repositories.ListCommits, etc.
CommentCount *int `json:"comment_count,omitempty"`
CommentCount *int `json:"comment_count,omitempty"`
NodeID *string `json:"node_id,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it'd be nicer to either move NodeID field up, together with all other fields, or add a blank line after CommentCount, since it has a comment saying that "This is only populated for requests that fetch GitHub data", which doesn't apply to NodeID as I understand.

Minor, but worth doing.

Comment thread github/git_blobs_test.go Outdated

if m := mediaTypeGraphQLNodeIDPreview; m != r.Header.Get("Accept") {
t.Errorf("Request accept header = %v, want %v", r.Header.Get("Accept"), m)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you still planning to do this? Just checking.

Comment thread github/issues.go Outdated
// TextMatches is only populated from search results that request text matches
// See: search.go and https://developer.github.com/v3/search/#text-match-metadata
TextMatches []TextMatch `json:"text_matches,omitempty"`
NodeID *string `json:"node_id,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also here, move NodeID field up to be with all other fields, rather than with TextMatches.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very nice, @anubhakushwaha... thank you!
Thanks to @shurcooL and @sahildua2305 for the code reviews, too!

After you address @shurcooL's review requests, this LGTM.

@anubhakushwaha

Copy link
Copy Markdown
Contributor Author

@shurcooL @sahildua2305 Apologies for the delay 😄 Updated the PR. Please review.

@sahildua2305 sahildua2305 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@dmitshur dmitshur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM; just see one minor thing that needs to be done before we merge this.

Comment thread github/github-accessors.go Outdated
@@ -1,4 +1,4 @@
// Copyright 2017 The go-github AUTHORS. All rights reserved.
// Copyright 2018 The go-github AUTHORS. All rights reserved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You'll need to revert this change. See #823 for the reason why. Sorry about the trouble.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've applied this trivial change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@shurcooL It was my pleasure working on this 😄

@googlebot

Copy link
Copy Markdown

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 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 the commit author(s) and 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 Jan 9, 2018
@dmitshur dmitshur merged commit cbeb72e into google:master Jan 9, 2018
@dmitshur

dmitshur commented Jan 9, 2018

Copy link
Copy Markdown
Member

Merged. Thanks a lot for working on this @anubhakushwaha!

@anubhakushwaha

Copy link
Copy Markdown
Contributor Author

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.

6 participants