-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from whywaita/fix/pending-log
Fix a logging
- Loading branch information
Showing
4 changed files
with
123 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package gh | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/google/go-github/v47/github" | ||
"github.com/whywaita/myshoes/pkg/logger" | ||
) | ||
|
||
func listInstallations(ctx context.Context) ([]*github.Installation, error) { | ||
if cachedRs, found := responseCache.Get(getCacheInstallationsKey()); found { | ||
return cachedRs.([]*github.Installation), nil | ||
} | ||
|
||
inst, err := _listInstallations(ctx) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to list installations: %w", err) | ||
} | ||
|
||
responseCache.Set(getCacheInstallationsKey(), inst, 1*time.Hour) | ||
|
||
return _listInstallations(ctx) | ||
} | ||
|
||
func getCacheInstallationsKey() string { | ||
return "installations" | ||
} | ||
|
||
func _listInstallations(ctx context.Context) ([]*github.Installation, error) { | ||
clientApps, err := NewClientGitHubApps() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create a client Apps: %w", err) | ||
} | ||
|
||
var opts = &github.ListOptions{ | ||
Page: 0, | ||
PerPage: 100, | ||
} | ||
|
||
var installations []*github.Installation | ||
for { | ||
logger.Logf(true, "get installations from GitHub, page: %d, now all installations: %d", opts.Page, len(installations)) | ||
is, resp, err := clientApps.Apps.ListInstallations(ctx, opts) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to list installations: %w", err) | ||
} | ||
installations = append(installations, is...) | ||
if resp.NextPage == 0 { | ||
break | ||
} | ||
opts.Page = resp.NextPage | ||
} | ||
return installations, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters