Skip to content

Commit

Permalink
Allow git ingester to work on Pull Requests as well (#5170)
Browse files Browse the repository at this point in the history
This is useful for writing simple rules that check out the git repo for
a pull request.

Signed-off-by: Juan Antonio Osorio <[email protected]>
  • Loading branch information
JAORMX authored Dec 10, 2024
1 parent 4e29d37 commit a0d9e90
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/engine/ingester/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"

engerrors "github.com/mindersec/minder/internal/engine/errors"
pbinternal "github.com/mindersec/minder/internal/proto"
pb "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
"github.com/mindersec/minder/pkg/engine/v1/interfaces"
"github.com/mindersec/minder/pkg/entities/v1/checkpoints"
Expand Down Expand Up @@ -122,12 +123,12 @@ func (gi *Git) getBranch(ent protoreflect.ProtoMessage, userCfg *IngesterConfig)
return gi.cfg.Branch
}

// If the entity is a repository get it from the entity
// else, use the default
if repo, ok := ent.(*pb.Repository); ok {
if repo.GetDefaultBranch() != "" {
return repo.GetDefaultBranch()
}
} else if pr, ok := ent.(*pbinternal.PullRequest); ok {
return pr.GetTargetRef()
}

// If the branch is not provided in the rule-type
Expand All @@ -140,10 +141,10 @@ func getCloneUrl(ent protoreflect.ProtoMessage, cfg *IngesterConfig) string {
return cfg.CloneURL
}

// If the entity is a repository get it from the entity
// else, get it from the configuration
if repo, ok := ent.(*pb.Repository); ok {
return repo.GetCloneUrl()
} else if pr, ok := ent.(*pbinternal.PullRequest); ok {
return pr.GetTargetCloneUrl()
}

return ""
Expand Down

0 comments on commit a0d9e90

Please sign in to comment.