Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the new handlers when evaluating repo webhooks #4565

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions internal/controlplane/handlers_githubwebhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/stacklok/minder/internal/controlplane/metrics"
"github.com/stacklok/minder/internal/db"
"github.com/stacklok/minder/internal/engine/entities"
entityMessage "github.com/stacklok/minder/internal/entities/handlers/message"
"github.com/stacklok/minder/internal/entities/models"
"github.com/stacklok/minder/internal/entities/properties"
"github.com/stacklok/minder/internal/entities/properties/service"
Expand Down Expand Up @@ -944,29 +945,7 @@ func (s *Server) processRepositoryEvent(

l.Info().Msg("handling event for repository")

repoEnt, err := s.fetchRepo(ctx, event.GetRepo())
if err != nil {
return nil, err
}

// protobufs are our API, so we always execute on these instead of the DB directly.
pbMsg, err := s.props.EntityWithPropertiesAsProto(ctx, repoEnt, s.providerManager)
if err != nil {
return nil, fmt.Errorf("error converting repository to protobuf: %w", err)
}

pbRepo, ok := pbMsg.(*pb.Repository)
if !ok {
return nil, errors.New("error converting proto message to protobuf")
}

eiw := entities.NewEntityInfoWrapper().
WithProjectID(repoEnt.Entity.ProjectID).
WithProviderID(repoEnt.Entity.ProviderID).
WithRepository(pbRepo).
WithRepositoryID(repoEnt.Entity.ID)

return &processingResult{topic: events.TopicQueueEntityEvaluate, wrapper: eiw}, nil
return s.sendEvaluateRepoMessage(event.GetRepo(), events.TopicQueueRefreshEntityAndEvaluate)
}

// nolint:gocyclo // This function will be re-simplified real soon
Expand Down Expand Up @@ -1252,6 +1231,28 @@ func (_ *Server) repositoryAdded(
}, nil
}

func (_ *Server) sendEvaluateRepoMessage(
repo *repo,
handler string,
) (*processingResult, error) {
lookByProps, err := properties.NewProperties(map[string]any{
// the PropertyUpstreamID is always a string
properties.PropertyUpstreamID: strconv.FormatInt(repo.GetID(), 10),
})
if err != nil {
return nil, fmt.Errorf("error creating repository properties: %w", err)
}

entRefresh := entityMessage.NewEntityRefreshAndDoMessage().
WithEntity(pb.Entity_ENTITY_REPOSITORIES, lookByProps).
WithProviderImplementsHint(string(db.ProviderTypeGithub))

return &processingResult{
topic: handler,
wrapper: entRefresh},
nil
}

func (s *Server) fetchRepo(
ctx context.Context,
repo *repo,
Expand Down
Loading