diff --git a/internal/providers/github/common.go b/internal/providers/github/common.go index a0c8fa8e99..0d2611baeb 100644 --- a/internal/providers/github/common.go +++ b/internal/providers/github/common.go @@ -59,6 +59,8 @@ var ( ErrNotFound = errors.New("not found") // ErrBranchNotFound denotes if the branch was not found ErrBranchNotFound = errors.New("branch not found") + // ErrNoPackageListingClient denotes if there is no package listing client available + ErrNoPackageListingClient = errors.New("no package listing client available") ) // GitHub is the struct that contains the shared GitHub client operations @@ -171,6 +173,11 @@ func (c *GitHub) ListPackagesByRepository( // create a slice to hold the containers var allContainers []*github.Package + if c.packageListingClient == nil { + zerolog.Ctx(ctx).Error().Msg("No client available for listing packages") + return allContainers, ErrNoPackageListingClient + } + type listPackagesRespWrapper struct { artifacts []*github.Package resp *github.Response @@ -205,7 +212,7 @@ func (c *GitHub) ListPackagesByRepository( for { result, err := performWithRetry(ctx, op) if err != nil { - if result.resp.StatusCode == http.StatusNotFound { + if result.resp != nil && result.resp.StatusCode == http.StatusNotFound { return allContainers, fmt.Errorf("packages not found for repository %d: %w", repositoryId, ErrNotFound) } diff --git a/internal/reconcilers/repository.go b/internal/reconcilers/repository.go index 59dd51c0c3..6ab77a8927 100644 --- a/internal/reconcilers/repository.go +++ b/internal/reconcilers/repository.go @@ -24,6 +24,7 @@ import ( "github.com/ThreeDotsLabs/watermill/message" "github.com/go-playground/validator/v10" "github.com/google/uuid" + "github.com/rs/zerolog" "github.com/rs/zerolog/log" "google.golang.org/protobuf/types/known/timestamppb" @@ -137,6 +138,13 @@ func (r *Reconciler) handleArtifactsReconcilerEvent(ctx context.Context, evt *Re // we do not return error since it's a valid use case for a repository to not have artifacts log.Printf("error retrieving artifacts for RepoID %d: %v", repository.RepoID, err) return nil + } else if errors.Is(err, github.ErrNoPackageListingClient) { + // not a hard error, just misconfiguration or the user doesn't want to put a token + // into the provider config + zerolog.Ctx(ctx).Info(). + Str("provider", prov.ID.String()). + Msg("No package listing client available for provider") + return nil } return err }