Decode only works if r.Content is actually encoded, which I'm not sure
that it always will be. GetContent will return the content, decoding it
only if necessary. Deprecate the old Decode method.
Also expand and cleanup the tests for both of these methods.
Related to #323
The markdown and repo list examples are pretty simple and can easily be
moved to be inline samples so that they render as part of the packages
godocs. This helps make them more visible even if they won't run in the
browser. The basic auth example requires interacting with the user, so
leaving it where it is. Future examples should be included inline
whenever possible.
On successful queries (on errors ReadAll runs in CheckResponse), the
Response.Body is not read all the way to the EOF as json.Decoder is used,
which stops at the end of the object, which is probably followed by a \n.
Then, Response.Body.Close() is called. When that happens with a non-drained
Body, the TCP/TLS connection is closed (which makes sense, in case there was
still a lot to read from the network), stopping the Transport from reusing
it. Also, a library user can't drain the Body themselves because Close() is
called before passing the Response to the user.
Since we know GitHub API responses only carry a single JSON object, draining
before closing is free, and saving all those handshakes causes huge savings
in latency, bandwidth and CPU for both the client and the poor GitHub
servers.
Here's the result of running the benchmark below on a ADSL connection:
before: 2m3.001599093s
after: 33.753543928s
func main() {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
gh := github.NewClient(tc)
start := time.Now()
for i := 0; i < 100; i++ {
gh.Repositories.Get("FiloSottile", "gvt")
fmt.Print(".")
}
fmt.Printf("\n%s\n", time.Now().Sub(start))
}
If a redirect to AWS occurs, then the redirect will be canceled and
the redirect Location will be returned in redirectURL and the
io.ReadCloser will be nil. At this point, the user would need to
perform the http.Get with the redirectURL in a different http.Client
(without the GitHub authentication transport).
Note that this is a breaking API change.
Fixes#246.
Change-Id: I4fe2dfc9cd0ce81934a07f11a6296e71c7dd51a0
In V3 of the GitHub API, pull request comments are created in two ways. The
first way is to create a comment on a specific line of a file in a commit
with the following parameters:
| Name | Type | Description |
|-----------|---------|--------------------------------------------------------|
| body | string | Required. The text of the comment |
| commit_id | string | Required. The SHA of the commit to comment on. |
| path | string | Required. The relative path of the file to comment on. |
| position | integer | Required. The line index in the diff to comment on. |
And the second way is through a reply to an existing comment with the following
parameters:
| Name | Type | Description |
|-------------|---------|---------------------------------------|
| body | string | Required. The text of the comment |
| in_reply_to | integer | Required. The comment id to reply to. |
This commit adds support for the second (or "Alternative Input" according to
the GitHub docs) way.
Rate is now a method, not a field.
Mention RateLimits rather than RateLimit since the latter is deprecated.
Use Go convention for marking deprecated identifiers. See
257114af91.
For more information about the preview see here:
https://developer.github.com/changes/2015-11-11-protected-branches-api/
This adds only retrieving the information and not setting it. Setting
will come in a later commit (if that one here is okay).
I tried to follow the naming guidelines as much as possible and
hopefully I made it right the first time. :-)
Add a new error type, TwoFactorAuthError, which identifies the need to
include a one-time password when using Basic Auth for a user with
two-factor auth enabled.
An example of using both the new transport and error type can be seen in
examples/basicauth/main.go.
fixes#258