Skip to content

Commit

Permalink
Merge pull request #119 from whywaita/fix/118
Browse files Browse the repository at this point in the history
Use conditional GET by httpcache
  • Loading branch information
whywaita authored Nov 10, 2021
2 parents 0933df7 + b8933df commit de869db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/go-sql-driver/mysql v1.5.0
github.com/google/go-cmp v0.5.6
github.com/google/go-github/v35 v35.2.0
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
github.com/hashicorp/go-plugin v1.4.0
github.com/hashicorp/go-version v1.3.0
github.com/jmoiron/sqlx v1.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-plugin v1.4.0 h1:b0O7rs5uiJ99Iu9HugEzsM67afboErkHUWddUSpUO3A=
Expand Down
8 changes: 5 additions & 3 deletions pkg/gh/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

"github.com/gregjones/httpcache"

"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v35/github"
"github.com/patrickmn/go-cache"
Expand Down Expand Up @@ -50,7 +52,7 @@ func NewClient(ctx context.Context, personalToken, gheDomain string) (*github.Cl
// header is "Authorization: Bearer YOUR_JWT"
// docs: https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app
func NewClientGitHubApps(gheDomain string, appID int64, appPEM []byte) (*github.Client, error) {
tr := http.DefaultTransport
tr := httpcache.NewMemoryCacheTransport()
itr, err := ghinstallation.NewAppsTransport(tr, appID, appPEM)
if err != nil {
return nil, fmt.Errorf("failed to create Apps transport: %w", err)
Expand All @@ -71,7 +73,7 @@ func NewClientGitHubApps(gheDomain string, appID int64, appPEM []byte) (*github.
// header is "Authorization: token YOUR_INSTALLATION_ACCESS_TOKEN"
// docs: https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-an-installation
func NewClientInstallation(gheDomain string, installationID int64, appID int64, appPEM []byte) (*github.Client, error) {
tr := http.DefaultTransport
tr := httpcache.NewMemoryCacheTransport()
itr, err := ghinstallation.New(tr, appID, installationID, appPEM)
if err != nil {
return nil, fmt.Errorf("failed to create Apps transport: %w", err)
Expand All @@ -93,7 +95,7 @@ func CheckSignature(installationID int64) error {
appID := config.Config.GitHub.AppID
pem := config.Config.GitHub.PEMByte

tr := http.DefaultTransport
tr := httpcache.NewMemoryCacheTransport()
_, err := ghinstallation.New(tr, appID, installationID, pem)
if err != nil {
return fmt.Errorf("failed to create GitHub installation: %w", err)
Expand Down

0 comments on commit de869db

Please sign in to comment.