* Support scanning all GitHub App installations Add scan_all_installations handling for GitHub App sources so multi-installation scans use the correct per-installation clients, token mapping, and fail-closed repo ownership checks. * Cache per-installation GitHub App API clients Avoid creating a new client and token negotiation on every repo operation by caching clients per installation ID, reusing the configured default client, and giving each cached client its own apps transport to avoid races on the shared transport's token-refresh path. * Cache per-installation GraphQL clients and hoist URL scheme regex Reuse GraphQL clients for non-default installations the same way REST clients are cached, and compile the URL scheme regex once at package level instead of on every call. * Log per-installation mapping errors on early return When all requested repos get mapped, failures from other installations no longer disappear silently; they're logged before the success return. * Report per-installation enumeration failures without aborting scan-all A transient failure in one installation no longer aborts the whole multi-org enumeration; it's reported via the unit reporter and remaining installations continue. Also avoid nested mutex acquisition in GraphQLClientForRepo with a double-check cache pattern. * Report member enumeration failures and use nil-safe installation getters Surface per-org member enumeration failures through the unit reporter instead of only logging them, and use GetAccount() getters for installation account access. * Simplify GitHub App installation setup * Address GitHub App connector review followups Unify per-installation client state, centralize GitHub URL helpers, and tighten wiki/endpoint handling so multi-installation scans keep auth routing explicit and maintainable. * Harden GitHub App multi-installation scans Surface partial installation enumeration failures, tighten wiki URL disambiguation, and make rate-limit waits cancellation-aware so scan-all behavior is safer and easier to diagnose. * Fix GitHub App ID parse error message Report the original app ID string when parsing fails so invalid configuration errors are actionable. * Avoid bogus wiki alias mappings Only derive double-wiki installation aliases when repository metadata confirms the repo itself is named with a .wiki suffix.
31 lines
583 B
Go
31 lines
583 B
Go
package sources
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type ChunkFunc func(chunk *Chunk) error
|
|
|
|
// ErrMatch indicates a chunk did not match and the helper should keep waiting.
|
|
var ErrMatch = errors.New("chunk doesn't match")
|
|
|
|
func HandleTestChannel(chunksCh chan *Chunk, cf ChunkFunc) error {
|
|
for {
|
|
select {
|
|
case gotChunk := <-chunksCh:
|
|
err := cf(gotChunk)
|
|
if err != nil {
|
|
if errors.Is(err, ErrMatch) {
|
|
continue
|
|
}
|
|
return err
|
|
}
|
|
return nil
|
|
case <-time.After(10 * time.Second):
|
|
return fmt.Errorf("no new chunks received after 10 seconds")
|
|
}
|
|
}
|
|
}
|