Skip to content

Commit

Permalink
Don't force default branch in deps ingest and fix segfaults (#5143)
Browse files Browse the repository at this point in the history
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 <ozz@stacklok.com>
  • Loading branch information
JAORMX authored Dec 5, 2024
1 parent edf31a2 commit b4fc9e3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/engine/ingester/deps/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b4fc9e3

Please sign in to comment.