Client.Rate() method is unreliable in situations when API calls are made
by others that may hit different rate limit categories (core and search).
Each API call already returns a Response struct that contains an accurate
Rate, so that's a better mechanism to access this information.
See relevant discussion at https://github.com/google/go-github/pull/347#discussion_r61920849.
When possible to do so reliably, i.e., the client knows that the rate
limit is exceeded and reset time is in the future, immediately return
*RateLimitError without making network calls to GitHub API.
Add a unit test covering RateLimits method populating client.rateLimits.
Remove commented out code.
Helps #152 and #153.
In GitHub API, there are currently two categories of rate limits: core
and search. Previously, the client only tracked the rate limit from the
most recent API call. This change makes it track both rate limit
categories.
This will be useful in the following commit.
This describes the package in a way that can be seen via godoc,
and makes it so that the following command succeeds without
"no buildable Go source files" error:
go build github.com/google/go-github/...
Also make tip a fast-finish allowed failure. That way, if CI fails on
tip due to a temporary issue with tip, it will not break build status.
However, it's still possible to see tip build status by looking at CI
details page.
Do not run go vet with Go 1.4 since it's not included in the standard
library, and it's no longer available in external standard library.
If `RepositoriesService.DownloadReleaseAsset` encounters an error from
the GitHub API (e.g., 404 Not Found), The error would not be returned
by the method and instead the error payload would be delivered as the
`io.ReadCloser`. This patch resolves this with `CheckResponse`.
Fixes#343
It's not obvious from reading the GitHub API docs or the go-github docs
that RepositoryContent.Content may be base64 encoded. This adds
clarifying docs for that as well as the String method.
Also add an example of using the GetReadme method.
Fixes#322Fixes#323
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