(installationID int64, repoID *int64)
| 114 | } |
| 115 | |
| 116 | func (g *githubClient) InstallationClient(installationID int64, repoID *int64) *github.Client { |
| 117 | g.cacheMu.Lock() |
| 118 | defer g.cacheMu.Unlock() |
| 119 | |
| 120 | // lookup cache |
| 121 | cacheKey := installationCacheKey(installationID, repoID) |
| 122 | val, ok := g.installationCache.Get(cacheKey) |
| 123 | if ok { |
| 124 | return val.(*github.Client) |
| 125 | } |
| 126 | |
| 127 | // create transport for the installation from the app transport |
| 128 | itr := ghinstallation.NewFromAppsTransport(g.appTransport, installationID) |
| 129 | if repoID != nil { |
| 130 | // set the repository ID in the transport options |
| 131 | opts := itr.InstallationTokenOptions |
| 132 | if opts == nil { |
| 133 | opts = &github.InstallationTokenOptions{} |
| 134 | } |
| 135 | opts.RepositoryIDs = []int64{*repoID} |
| 136 | } |
| 137 | // create the installation client |
| 138 | installationClient := github.NewClient(&http.Client{Transport: itr}) |
| 139 | |
| 140 | // add to cache |
| 141 | g.installationCache.Add(cacheKey, installationClient) |
| 142 | return installationClient |
| 143 | } |
| 144 | |
| 145 | func (g *githubClient) InstallationToken(ctx context.Context, installationID, repoID int64) (string, time.Time, error) { |
| 146 | client := g.InstallationClient(installationID, &repoID) |
no test coverage detected