From b4fc9e370f8d3996a4ed8fc417aeae3a8eb84bcd Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Thu, 5 Dec 2024 16:19:23 +0200 Subject: [PATCH] Don't force default branch in deps ingest and fix segfaults (#5143) This allows us to auto-discover a default branch if the user does not set it. The previous setup was forcing that we'd always use the "default" branch, thus bypassing autodiscovery. It also had segfaults in the case where the repo configuration was not set. Signed-off-by: Juan Antonio Osorio --- internal/engine/ingester/deps/deps.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/engine/ingester/deps/deps.go b/internal/engine/ingester/deps/deps.go index 9ff372d449..bc001592c7 100644 --- a/internal/engine/ingester/deps/deps.go +++ b/internal/engine/ingester/deps/deps.go @@ -83,9 +83,9 @@ func (gi *Deps) Ingest(ctx context.Context, ent protoreflect.ProtoMessage, param func (gi *Deps) ingestRepository(ctx context.Context, repo *pb.Repository, params map[string]any) (*interfaces.Result, error) { var logger = zerolog.Ctx(ctx) - userCfg := &Config{ - Branch: defaultBranch, - } + // the branch is left unset since we want to auto-discover it + // in case it's not explicitly set + userCfg := &Config{} if err := mapstructure.Decode(params, userCfg); err != nil { return nil, fmt.Errorf("failed to read dependency ingester configuration from params: %w", err) } @@ -143,16 +143,16 @@ func (gi *Deps) ingestRepository(ctx context.Context, repo *pb.Repository, param }, nil } -func (gi *Deps) getBranch(repo *pb.Repository, branch string) string { +func (gi *Deps) getBranch(repo *pb.Repository, userConfigBranch string) string { // If the user has specified a branch, use that - if branch != "" { - return branch + if userConfigBranch != "" { + return userConfigBranch } // If the branch is provided in the rule-type // configuration, use that - if gi.cfg.GetRepo().Branch != "" { - return gi.cfg.GetRepo().Branch + if gi.cfg.GetRepo().GetBranch() != "" { + return gi.cfg.GetRepo().GetBranch() } if repo.GetDefaultBranch() != "" { return repo.GetDefaultBranch()