Skip to content

Commit

Permalink
Move PullRequest to internal proto file (#5067)
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherias authored Nov 28, 2024
1 parent f916420 commit 7e41aa9
Show file tree
Hide file tree
Showing 23 changed files with 4,386 additions and 4,406 deletions.
23 changes: 0 additions & 23 deletions docs/docs/ref/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/eea/eea.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/mindersec/minder/internal/db"
"github.com/mindersec/minder/internal/engine/entities"
"github.com/mindersec/minder/internal/entities/properties/service"
pbinternal "github.com/mindersec/minder/internal/proto"
"github.com/mindersec/minder/internal/providers/manager"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
serverconfig "github.com/mindersec/minder/pkg/config/server"
Expand Down Expand Up @@ -344,7 +345,7 @@ func (e *EEA) buildPullRequestInfoWrapper(
return nil, fmt.Errorf("error converting entity to protobuf: %w", err)
}

pr, ok := rawPR.(*minderv1.PullRequest)
pr, ok := rawPR.(*pbinternal.PullRequest)
if !ok {
return nil, fmt.Errorf("error converting entity to pull request")
}
Expand Down
3 changes: 2 additions & 1 deletion internal/eea/eea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/mindersec/minder/internal/entities/properties"
psvc "github.com/mindersec/minder/internal/entities/properties/service"
propsvcmock "github.com/mindersec/minder/internal/entities/properties/service/mock"
pbinternal "github.com/mindersec/minder/internal/proto"
mockmanager "github.com/mindersec/minder/internal/providers/manager/mock"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
serverconfig "github.com/mindersec/minder/pkg/config/server"
Expand Down Expand Up @@ -324,7 +325,7 @@ func TestFlushAll(t *testing.T) {
}, nil)

mockPropSvc.EXPECT().EntityWithPropertiesAsProto(gomock.Any(), gomock.Any(), gomock.Any()).
Return(&minderv1.PullRequest{}, nil)
Return(&pbinternal.PullRequest{}, nil)
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/json"
"errors"
"fmt"
pbinternal "github.com/mindersec/minder/internal/proto"
htmltemplate "html/template"
"strings"

Expand Down Expand Up @@ -310,7 +311,7 @@ func (alert *Alert) getParamsForSecurityAdvisory(
case *pb.Repository:
result.Owner = entity.GetOwner()
result.Repo = entity.GetName()
case *pb.PullRequest:
case *pbinternal.PullRequest:
result.Owner = entity.GetRepoOwner()
result.Repo = entity.GetRepoName()
case *pb.Artifact:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/mindersec/minder/internal/db"
enginerr "github.com/mindersec/minder/internal/engine/errors"
"github.com/mindersec/minder/internal/engine/interfaces"
pbinternal "github.com/mindersec/minder/internal/proto"
mockghclient "github.com/mindersec/minder/internal/providers/github/mock"
pb "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
"github.com/mindersec/minder/pkg/profiles/models"
Expand Down Expand Up @@ -103,7 +104,7 @@ func TestSecurityAdvisoryAlert(t *testing.T) {
context.Background(),
interfaces.ActionCmdOn,
models.ActionOptOn,
&pb.PullRequest{},
&pbinternal.PullRequest{},
evalParams,
nil,
)
Expand Down
5 changes: 3 additions & 2 deletions internal/engine/entities/entity_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/reflect/protoreflect"

pbinternal "github.com/mindersec/minder/internal/proto"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
"github.com/mindersec/minder/pkg/eventer/constants"
"github.com/mindersec/minder/pkg/eventer/interfaces"
Expand Down Expand Up @@ -101,7 +102,7 @@ func (eiw *EntityInfoWrapper) WithRepository(r *minderv1.Repository) *EntityInfo
}

// WithPullRequest sets the entity to a repository
func (eiw *EntityInfoWrapper) WithPullRequest(p *minderv1.PullRequest) *EntityInfoWrapper {
func (eiw *EntityInfoWrapper) WithPullRequest(p *pbinternal.PullRequest) *EntityInfoWrapper {
eiw.Type = minderv1.Entity_ENTITY_PULL_REQUESTS
eiw.Entity = p

Expand Down Expand Up @@ -156,7 +157,7 @@ func (eiw *EntityInfoWrapper) AsArtifact() *EntityInfoWrapper {
// AsPullRequest sets the entity type to a pull request
func (eiw *EntityInfoWrapper) AsPullRequest() {
eiw.Type = minderv1.Entity_ENTITY_PULL_REQUESTS
eiw.Entity = &minderv1.PullRequest{}
eiw.Entity = &pbinternal.PullRequest{}
}

// AsEntityInstance sets the entity type to an entity instance
Expand Down
13 changes: 7 additions & 6 deletions internal/engine/entities/entity_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/reflect/protoreflect"

pbinternal "github.com/mindersec/minder/internal/proto"
pb "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
)

Expand Down Expand Up @@ -104,7 +105,7 @@ func Test_parseEntityEvent(t *testing.T) {
{
name: "legacy pull_request event",
args: args{
ent: &pb.PullRequest{
ent: &pbinternal.PullRequest{
Url: "https://api.github.com/repos/jakubtestorg/bad-npm/pulls/3",
CommitSha: "bd9958a63c9b95ccc2bc0cf1eef65a87529aed16",
Number: 3,
Expand All @@ -121,7 +122,7 @@ func Test_parseEntityEvent(t *testing.T) {
},
want: &EntityInfoWrapper{
ProjectID: projectID,
Entity: &pb.PullRequest{
Entity: &pbinternal.PullRequest{
Url: "https://api.github.com/repos/jakubtestorg/bad-npm/pulls/3",
CommitSha: "bd9958a63c9b95ccc2bc0cf1eef65a87529aed16",
Number: 3,
Expand Down Expand Up @@ -195,7 +196,7 @@ func Test_parseEntityEvent(t *testing.T) {
{
name: "pull_request event with entity ID",
args: args{
ent: &pb.PullRequest{
ent: &pbinternal.PullRequest{
Url: "https://api.github.com/repos/jakubtestorg/bad-npm/pulls/3",
CommitSha: "bd9958a63c9b95ccc2bc0cf1eef65a87529aed16",
Number: 3,
Expand All @@ -209,7 +210,7 @@ func Test_parseEntityEvent(t *testing.T) {
},
want: &EntityInfoWrapper{
ProjectID: projectID,
Entity: &pb.PullRequest{
Entity: &pbinternal.PullRequest{
Url: "https://api.github.com/repos/jakubtestorg/bad-npm/pulls/3",
CommitSha: "bd9958a63c9b95ccc2bc0cf1eef65a87529aed16",
Number: 3,
Expand Down Expand Up @@ -342,7 +343,7 @@ func TestEntityInfoWrapper_ToMessage(t *testing.T) {
eiw: NewEntityInfoWrapper().
WithProviderID(providerID).
WithProjectID(projectID).
WithProtoMessage(pb.Entity_ENTITY_PULL_REQUESTS, &pb.PullRequest{
WithProtoMessage(pb.Entity_ENTITY_PULL_REQUESTS, &pbinternal.PullRequest{
Url: "https://api.github.com/repos/jakubtestorg/bad-npm/pulls/3",
CommitSha: "bd9958a63c9b95ccc2bc0cf1eef65a87529aed16",
Number: 3,
Expand All @@ -362,7 +363,7 @@ func TestEntityInfoWrapper_ToMessage(t *testing.T) {
eiw: NewEntityInfoWrapper().
WithProviderID(providerID).
WithProjectID(projectID).
WithPullRequest(&pb.PullRequest{
WithPullRequest(&pbinternal.PullRequest{
Url: "https://api.github.com/repos/jakubtestorg/bad-npm/pulls/3",
CommitSha: "bd9958a63c9b95ccc2bc0cf1eef65a87529aed16",
Number: 3,
Expand Down
6 changes: 3 additions & 3 deletions internal/engine/eval/homoglyphs/communication/reviewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/rs/zerolog"

"github.com/mindersec/minder/internal/engine/eval/homoglyphs/util"
pb "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
pbinternal "github.com/mindersec/minder/internal/proto"
provifv1 "github.com/mindersec/minder/pkg/providers/v1"
)

Expand All @@ -22,7 +22,7 @@ type GhReviewPrHandler struct {
logger zerolog.Logger

ghClient provifv1.GitHub
pr *pb.PullRequest
pr *pbinternal.PullRequest

minderReview *github.PullRequestReview
comments []*github.DraftReviewComment
Expand Down Expand Up @@ -69,7 +69,7 @@ func (ra *GhReviewPrHandler) SubmitReview(ctx context.Context, reviewText string
}

// Hydrate hydrates the handler with a pull request
func (ra *GhReviewPrHandler) Hydrate(ctx context.Context, pr *pb.PullRequest) {
func (ra *GhReviewPrHandler) Hydrate(ctx context.Context, pr *pbinternal.PullRequest) {
logger := zerolog.Ctx(ctx).With().
Int64("pull-number", pr.Number).
Str("repo-owner", pr.RepoOwner).
Expand Down
3 changes: 2 additions & 1 deletion internal/engine/eval/rego/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

engerrors "github.com/mindersec/minder/internal/engine/errors"
"github.com/mindersec/minder/internal/engine/eval/templates"
pbinternal "github.com/mindersec/minder/internal/proto"
minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
)

Expand Down Expand Up @@ -301,7 +302,7 @@ func (jrb *jsonResultBuilder) formatResults() error {

func getEntityName(entity protoreflect.ProtoMessage) string {
switch inner := entity.(type) {
case *minderv1.PullRequest:
case *pbinternal.PullRequest:
return fmt.Sprintf("%s/%s#%d",
inner.RepoOwner,
inner.RepoName,
Expand Down
5 changes: 2 additions & 3 deletions internal/engine/eval/trusty/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/mindersec/minder/internal/constants"
"github.com/mindersec/minder/internal/engine/eval/pr_actions"
pbinternal "github.com/mindersec/minder/internal/proto"
pb "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
provifv1 "github.com/mindersec/minder/pkg/providers/v1"
)

Expand Down Expand Up @@ -198,7 +197,7 @@ type dependencyAlternatives struct {
// summaryPrHandler is a prStatusHandler that adds a summary text to the PR as a comment.
type summaryPrHandler struct {
cli provifv1.GitHub
pr *pb.PullRequest
pr *pbinternal.PullRequest
trustyUrl string

trackedAlternatives []dependencyAlternatives
Expand Down Expand Up @@ -430,7 +429,7 @@ func (sph *summaryPrHandler) compileTemplate(malicious []maliciousTemplateData,
}

func newSummaryPrHandler(
pr *pb.PullRequest,
pr *pbinternal.PullRequest,
cli provifv1.GitHub,
trustyUrl string,
) (*summaryPrHandler, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/eval/trusty/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

"github.com/stretchr/testify/require"

v1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
pbinternal "github.com/mindersec/minder/internal/proto"
)

func TestNewSummaryPrHandler(t *testing.T) {
t.Parallel()

// newSummaryPrHandler must never fail. The only failure point
// right now is the pr comment template
_, err := newSummaryPrHandler(&v1.PullRequest{}, nil, "")
_, err := newSummaryPrHandler(&pbinternal.PullRequest{}, nil, "")
require.NoError(t, err)
}

Expand Down
3 changes: 1 addition & 2 deletions internal/engine/eval/vulncheck/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/mindersec/minder/internal/engine/eval/pr_actions"
pbinternal "github.com/mindersec/minder/internal/proto"
pb "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
provifv1 "github.com/mindersec/minder/pkg/providers/v1"
)

Expand All @@ -29,7 +28,7 @@ type prStatusHandler interface {
func newPrStatusHandler(
ctx context.Context,
action pr_actions.Action,
pr *pb.PullRequest,
pr *pbinternal.PullRequest,
client provifv1.GitHub,
) (prStatusHandler, error) {
switch action {
Expand Down
11 changes: 5 additions & 6 deletions internal/engine/eval/vulncheck/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/rs/zerolog"

pbinternal "github.com/mindersec/minder/internal/proto"
pb "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
provifv1 "github.com/mindersec/minder/pkg/providers/v1"
)

Expand Down Expand Up @@ -105,7 +104,7 @@ func reviewBodyWithSuggestion(comment string) string {

type reviewPrHandler struct {
cli provifv1.GitHub
pr *pb.PullRequest
pr *pbinternal.PullRequest

trackedDeps []dependencyVulnerabilities

Expand All @@ -131,7 +130,7 @@ func withVulnsFoundReviewStatus(status *string) reviewPrHandlerOption {

func newReviewPrHandler(
ctx context.Context,
pr *pb.PullRequest,
pr *pbinternal.PullRequest,
cli provifv1.GitHub,
opts ...reviewPrHandlerOption,
) (*reviewPrHandler, error) {
Expand Down Expand Up @@ -469,7 +468,7 @@ type commitStatusPrHandler struct {

func newCommitStatusPrHandler(
ctx context.Context,
pr *pb.PullRequest,
pr *pbinternal.PullRequest,
client provifv1.GitHub,
) (prStatusHandler, error) {
// create a reviewPrHandler and embed it in the commitStatusPrHandler
Expand Down Expand Up @@ -531,7 +530,7 @@ func (csh *commitStatusPrHandler) setCommitStatus(
// summaryPrHandler is a prStatusHandler that adds a summary text to the PR as a comment.
type summaryPrHandler struct {
cli provifv1.GitHub
pr *pb.PullRequest
pr *pbinternal.PullRequest

logger zerolog.Logger
trackedDeps []dependencyVulnerabilities
Expand Down Expand Up @@ -577,7 +576,7 @@ func (sph *summaryPrHandler) submit(ctx context.Context) error {

func newSummaryPrHandler(
ctx context.Context,
pr *pb.PullRequest,
pr *pbinternal.PullRequest,
cli provifv1.GitHub,
) *summaryPrHandler {
logger := zerolog.Ctx(ctx).With().
Expand Down
Loading

0 comments on commit 7e41aa9

Please sign in to comment.