Skip to content

Commit

Permalink
Merge pull request #58 from wilsonehusin/github-httpcache
Browse files Browse the repository at this point in the history
Add use httpcache to cache GitHub responses
  • Loading branch information
k8s-ci-robot committed Apr 25, 2022
2 parents 682789c + d0ccdd3 commit 0b258c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions github/github.go
Expand Up @@ -27,6 +27,8 @@ import (
"strings"

"github.com/google/go-github/v39/github"
"github.com/gregjones/httpcache"
"github.com/gregjones/httpcache/diskcache"
"github.com/sirupsen/logrus"
"golang.org/x/oauth2"

Expand Down Expand Up @@ -183,6 +185,16 @@ func NewWithToken(token string) (*GitHub, error) {
&oauth2.Token{AccessToken: token},
))
}
cacheDir, err := os.UserCacheDir()
if err != nil {
logrus.Infof("Unable to retrieve user cache dir: %v", err)
cacheDir = os.TempDir()
}
dir := filepath.Join(cacheDir, "kubernetes", "release-sdk", "github")
logrus.Debugf("Caching GitHub responses in %v", dir)
t := httpcache.NewTransport(diskcache.New(dir))
client.Transport = t.Transport

logrus.Debugf("Using %s GitHub client", state)
return &GitHub{
client: &githubClient{github.NewClient(client)},
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -8,6 +8,7 @@ require (
github.com/go-git/go-git/v5 v5.4.2
github.com/google/go-containerregistry v0.8.1-0.20220209165246-a44adc326839
github.com/google/go-github/v39 v39.2.0
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
github.com/magefile/mage v1.13.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.5.0
github.com/sigstore/cosign v1.7.1
Expand Down Expand Up @@ -195,6 +196,7 @@ require (
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -1213,6 +1213,7 @@ github.com/gostaticanalysis/nilerr v0.1.1/go.mod h1:wZYb6YI5YAxxq0i1+VJbY0s2YONW
github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M=
github.com/gostaticanalysis/testutil v0.4.0/go.mod h1:bLIoPefWXrRi/ssLFWX1dx7Repi5x3CuviD3dgAZaBU=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
Expand Down Expand Up @@ -1786,6 +1787,7 @@ github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/peterh/liner v0.0.0-20170211195444-bf27d3ba8e1d/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d/go.mod h1:3OzsM7FXDQlpCiw2j81fOmAwQLnZnLGXVKUzeKQXIAw=
Expand Down

0 comments on commit 0b258c3

Please sign in to comment.