From ff8964a283b94643023c58075c0ebb8caa6d9369 Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Mon, 15 Jul 2024 11:42:52 +0300 Subject: [PATCH] Revert "Replace several internal protobufs with Go structs (#3878)" (#3890) This reverts commit 40cbccd24f8b8d1d732a290671535df8569fd961. This PR breaks the smoke tests. Explicitly the homoglyph and vulncheck tests. --- .../application/homoglyphs_service.go | 10 +- internal/engine/eval/trusty/actions.go | 12 +- internal/engine/eval/trusty/config.go | 6 +- internal/engine/eval/trusty/trusty.go | 47 +- internal/engine/eval/trusty/trusty_test.go | 48 +- internal/engine/eval/vulncheck/actions.go | 4 +- internal/engine/eval/vulncheck/config.go | 6 +- internal/engine/eval/vulncheck/pkgdb.go | 62 +- internal/engine/eval/vulncheck/pkgdb_test.go | 14 +- internal/engine/eval/vulncheck/report.go | 2 +- internal/engine/eval/vulncheck/review.go | 21 +- internal/engine/eval/vulncheck/review_test.go | 60 +- internal/engine/eval/vulncheck/vulncheck.go | 14 +- internal/engine/eval/vulncheck/vulndb.go | 14 +- internal/engine/eval/vulncheck/vulndb_test.go | 4 +- internal/engine/ingester/diff/diff.go | 39 +- internal/engine/ingester/diff/parse.go | 36 +- internal/engine/ingester/diff/parse_test.go | 110 +-- internal/engine/models/models.go | 74 -- internal/proto/internal.pb.go | 657 +++++++++++++++++- internal/proto/internal.proto | 53 +- internal/proto/pkg_ecosystems.go | 32 + 22 files changed, 960 insertions(+), 365 deletions(-) delete mode 100644 internal/engine/models/models.go create mode 100644 internal/proto/pkg_ecosystems.go diff --git a/internal/engine/eval/homoglyphs/application/homoglyphs_service.go b/internal/engine/eval/homoglyphs/application/homoglyphs_service.go index c1801b6ed7..fb2588ba50 100644 --- a/internal/engine/eval/homoglyphs/application/homoglyphs_service.go +++ b/internal/engine/eval/homoglyphs/application/homoglyphs_service.go @@ -25,7 +25,7 @@ import ( "github.com/stacklok/minder/internal/engine/eval/homoglyphs/communication" "github.com/stacklok/minder/internal/engine/eval/homoglyphs/domain" engif "github.com/stacklok/minder/internal/engine/interfaces" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" provifv1 "github.com/stacklok/minder/pkg/providers/v1" ) @@ -75,13 +75,13 @@ func evaluateHomoglyphs( } //nolint:govet - prContents, ok := res.Object.(*models.PRContents) + prContents, ok := res.Object.(*pbinternal.PrContents) if !ok { return false, fmt.Errorf("invalid object type for homoglyphs evaluator") } - if prContents.PR == nil || prContents.Files == nil { - return false, fmt.Errorf("invalid prContents fields: %v, %v", prContents.PR, prContents.Files) + if prContents.Pr == nil || prContents.Files == nil { + return false, fmt.Errorf("invalid prContents fields: %v, %v", prContents.Pr, prContents.Files) } if len(prContents.Files) == 0 { @@ -90,7 +90,7 @@ func evaluateHomoglyphs( // Note: This is a mandatory step to reassign certain fields in the handler. // This is a workaround to avoid recreating the object. - reviewHandler.Hydrate(ctx, prContents.PR) + reviewHandler.Hydrate(ctx, prContents.Pr) for _, file := range prContents.Files { for _, line := range file.PatchLines { diff --git a/internal/engine/eval/trusty/actions.go b/internal/engine/eval/trusty/actions.go index 6421cc8fc0..0dbe99a70f 100644 --- a/internal/engine/eval/trusty/actions.go +++ b/internal/engine/eval/trusty/actions.go @@ -32,7 +32,7 @@ import ( "github.com/stacklok/minder/internal/constants" "github.com/stacklok/minder/internal/engine/eval/pr_actions" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" provifv1 "github.com/stacklok/minder/pkg/providers/v1" ) @@ -194,7 +194,7 @@ type templateScoreComponent struct { } type dependencyAlternatives struct { - Dependency *models.Dependency + Dependency *pbinternal.Dependency // Reason captures the reason why a package was flagged Reasons []RuleViolationReason @@ -289,11 +289,11 @@ func (sph *summaryPrHandler) generateSummary() (string, error) { score = *alternative.trustyReply.Summary.Score } packageData := templatePackageData{ - Ecosystem: string(alternative.Dependency.Ecosystem), + Ecosystem: alternative.Dependency.Ecosystem.AsString(), PackageName: alternative.Dependency.Name, TrustyURL: fmt.Sprintf( "%s%s/%s", constants.TrustyHttpURL, - strings.ToLower(string(alternative.Dependency.Ecosystem)), + strings.ToLower(alternative.Dependency.Ecosystem.AsString()), url.PathEscape(alternative.trustyReply.PackageName), ), Score: score, @@ -326,11 +326,11 @@ func (sph *summaryPrHandler) generateSummary() (string, error) { altPackageData := templateAlternative{ templatePackageData: templatePackageData{ - Ecosystem: string(alternative.Dependency.Ecosystem), + Ecosystem: alternative.Dependency.Ecosystem.AsString(), PackageName: altData.PackageName, TrustyURL: fmt.Sprintf( "%s%s/%s", constants.TrustyHttpURL, - strings.ToLower(string(alternative.Dependency.Ecosystem)), + strings.ToLower(alternative.Dependency.Ecosystem.AsString()), url.PathEscape(altData.PackageName), ), Score: altData.Score, diff --git a/internal/engine/eval/trusty/config.go b/internal/engine/eval/trusty/config.go index 49c4409bb8..7128aa18c5 100644 --- a/internal/engine/eval/trusty/config.go +++ b/internal/engine/eval/trusty/config.go @@ -23,7 +23,7 @@ import ( "github.com/go-viper/mapstructure/v2" "github.com/stacklok/minder/internal/engine/eval/pr_actions" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" ) var ( @@ -110,8 +110,8 @@ func parseConfig(ruleCfg map[string]any) (*config, error) { return &conf, nil } -func (c *config) getEcosystemConfig(ecosystem models.DependencyEcosystem) *ecosystemConfig { - sEco := string(ecosystem) +func (c *config) getEcosystemConfig(ecosystem pbinternal.DepEcosystem) *ecosystemConfig { + sEco := ecosystem.AsString() if sEco == "" { return nil } diff --git a/internal/engine/eval/trusty/trusty.go b/internal/engine/eval/trusty/trusty.go index 7683b16d47..5f31caa274 100644 --- a/internal/engine/eval/trusty/trusty.go +++ b/internal/engine/eval/trusty/trusty.go @@ -28,7 +28,7 @@ import ( evalerrors "github.com/stacklok/minder/internal/engine/errors" "github.com/stacklok/minder/internal/engine/eval/pr_actions" engif "github.com/stacklok/minder/internal/engine/interfaces" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" provifv1 "github.com/stacklok/minder/pkg/providers/v1" ) @@ -87,9 +87,9 @@ func (e *Evaluator) Eval(ctx context.Context, pol map[string]any, res *engif.Res } logger := zerolog.Ctx(ctx).With(). - Int64("pull-number", prDependencies.PR.Number). - Str("repo-owner", prDependencies.PR.RepoOwner). - Str("repo-name", prDependencies.PR.RepoName).Logger() + Int64("pull-number", prDependencies.Pr.Number). + Str("repo-owner", prDependencies.Pr.RepoOwner). + Str("repo-name", prDependencies.Pr.RepoName).Logger() // Parse the profile data to get the policy configuration ruleConfig, err := parseRuleConfig(pol) @@ -97,14 +97,14 @@ func (e *Evaluator) Eval(ctx context.Context, pol map[string]any, res *engif.Res return fmt.Errorf("parsing policy configuration: %w", err) } - prSummaryHandler, err := newSummaryPrHandler(prDependencies.PR, e.cli, e.endpoint) + prSummaryHandler, err := newSummaryPrHandler(prDependencies.Pr, e.cli, e.endpoint) if err != nil { return fmt.Errorf("failed to create summary handler: %w", err) } // Classify all dependencies, tracking all that are malicious or scored low for _, dep := range prDependencies.Deps { - depscore, err := getDependencyScore(ctx, e.client, &dep) + depscore, err := getDependencyScore(ctx, e.client, dep) if err != nil { logger.Error().Msgf("error fetching trusty data: %s", err) return fmt.Errorf("getting dependency score: %w", err) @@ -135,22 +135,22 @@ func (e *Evaluator) Eval(ctx context.Context, pol map[string]any, res *engif.Res } func getEcosystemConfig( - logger *zerolog.Logger, ruleConfig *config, dep models.ContextualDependency, + logger *zerolog.Logger, ruleConfig *config, dep *pbinternal.PrDependencies_ContextualDependency, ) *ecosystemConfig { ecoConfig := ruleConfig.getEcosystemConfig(dep.Dep.Ecosystem) if ecoConfig == nil { logger.Info(). Str("dependency", dep.Dep.Name). - Str("ecosystem", string(dep.Dep.Ecosystem)). + Str("ecosystem", dep.Dep.Ecosystem.AsString()). Msgf("no config for ecosystem, skipping") return nil } return ecoConfig } -// readPullRequestDependencies returns the dependencies found in the ingestion results -func readPullRequestDependencies(res *engif.Result) (*models.PRDependencies, error) { - prdeps, ok := res.Object.(*models.PRDependencies) +// readPullRequestDependencies returns the dependencies found in theingestion results +func readPullRequestDependencies(res *engif.Result) (*pbinternal.PrDependencies, error) { + prdeps, ok := res.Object.(*pbinternal.PrDependencies) if !ok { return nil, fmt.Errorf("object type incompatible with the Trusty evaluator") } @@ -224,17 +224,13 @@ func buildEvalResult(prSummary *summaryPrHandler) error { } func getDependencyScore( - ctx context.Context, trustyClient *trusty.Trusty, dep *models.ContextualDependency, + ctx context.Context, trustyClient *trusty.Trusty, dep *pbinternal.PrDependencies_ContextualDependency, ) (*trustytypes.Reply, error) { - trustyEcosystem, err := toTrustyEcosystem(dep.Dep.Ecosystem) - if err != nil { - return nil, err - } // Call the Trusty API resp, err := trustyClient.Report(ctx, &trustytypes.Dependency{ Name: dep.Dep.Name, Version: dep.Dep.Version, - Ecosystem: trustyEcosystem, + Ecosystem: trustytypes.Ecosystem(dep.Dep.Ecosystem), }) if err != nil { return nil, fmt.Errorf("failed to send request: %w", err) @@ -246,7 +242,7 @@ func getDependencyScore( // low scores and adds them to the summary if needed func classifyDependency( _ context.Context, logger *zerolog.Logger, resp *trustytypes.Reply, ruleConfig *config, - prSummary *summaryPrHandler, dep models.ContextualDependency, + prSummary *summaryPrHandler, dep *pbinternal.PrDependencies_ContextualDependency, ) { // Check all the policy violations reasons := []RuleViolationReason{} @@ -315,7 +311,7 @@ func classifyDependency( Msgf("the dependency has lower score than threshold or is malicious, tracking") prSummary.trackAlternatives(dependencyAlternatives{ - Dependency: &dep.Dep, + Dependency: dep.Dep, Reasons: reasons, BlockPR: shouldBlockPR, trustyReply: resp, @@ -348,16 +344,3 @@ func readPackageDescription(resp *trustytypes.Reply) map[string]any { } return descr } - -func toTrustyEcosystem(ecosystem models.DependencyEcosystem) (trustytypes.Ecosystem, error) { - switch ecosystem { - case models.NPMDependency: - return trustytypes.ECOSYSTEM_NPM, nil - case models.PyPIDependency: - return trustytypes.ECOSYSTEM_PYPI, nil - case models.GoDependency: - return trustytypes.ECOSYSTEM_GO, nil - default: - return 0, fmt.Errorf("unexpected ecosystem %s", ecosystem) - } -} diff --git a/internal/engine/eval/trusty/trusty_test.go b/internal/engine/eval/trusty/trusty_test.go index 0518121e76..e4095d2dd5 100644 --- a/internal/engine/eval/trusty/trusty_test.go +++ b/internal/engine/eval/trusty/trusty_test.go @@ -27,8 +27,8 @@ import ( "github.com/stacklok/minder/internal/engine/eval/pr_actions" engif "github.com/stacklok/minder/internal/engine/interfaces" - "github.com/stacklok/minder/internal/engine/models" - mockgithub "github.com/stacklok/minder/internal/providers/github/mock" + pbinternal "github.com/stacklok/minder/internal/proto" + mock_github "github.com/stacklok/minder/internal/providers/github/mock" provifv1 "github.com/stacklok/minder/pkg/providers/v1" ) @@ -46,14 +46,14 @@ func TestBuildEvalResult(t *testing.T) { {"malicious-package", &summaryPrHandler{ trackedAlternatives: []dependencyAlternatives{ { - Dependency: &models.Dependency{ - Ecosystem: models.PyPIDependency, + Dependency: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "0.0.1", }, trustyReply: &trustytypes.Reply{ PackageName: "requests", - PackageType: string(models.PyPIDependency), + PackageType: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI.AsString(), Summary: trustytypes.ScoreSummary{ Score: &sg, }, @@ -76,14 +76,14 @@ func TestBuildEvalResult(t *testing.T) { {"low-scored-package", &summaryPrHandler{ trackedAlternatives: []dependencyAlternatives{ { - Dependency: &models.Dependency{ - Ecosystem: models.PyPIDependency, + Dependency: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "0.0.1", }, trustyReply: &trustytypes.Reply{ PackageName: "requests", - PackageType: string(models.PyPIDependency), + PackageType: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI.AsString(), Summary: trustytypes.ScoreSummary{ Score: &sg, }, @@ -94,28 +94,28 @@ func TestBuildEvalResult(t *testing.T) { {"malicious-and-low-score", &summaryPrHandler{ trackedAlternatives: []dependencyAlternatives{ { - Dependency: &models.Dependency{ - Ecosystem: models.PyPIDependency, + Dependency: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "python-oauth", Version: "0.0.1", }, trustyReply: &trustytypes.Reply{ PackageName: "requests", - PackageType: string(models.PyPIDependency), + PackageType: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI.AsString(), Summary: trustytypes.ScoreSummary{ Score: &sg, }, }, }, { - Dependency: &models.Dependency{ - Ecosystem: models.PyPIDependency, + Dependency: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requestts", Version: "0.0.1", }, trustyReply: &trustytypes.Reply{ PackageName: "requests", - PackageType: string(models.PyPIDependency), + PackageType: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI.AsString(), Summary: trustytypes.ScoreSummary{ Score: &sg, }, @@ -195,7 +195,7 @@ func TestReadPullRequestDependencies(t *testing.T) { sut *engif.Result mustErr bool }{ - {name: "normal", sut: &engif.Result{Object: &models.PRDependencies{}}, mustErr: false}, + {name: "normal", sut: &engif.Result{Object: &pbinternal.PrDependencies{}}, mustErr: false}, {name: "invalid-object", sut: &engif.Result{Object: context.Background()}, mustErr: true}, } { tc := tc @@ -213,7 +213,7 @@ func TestReadPullRequestDependencies(t *testing.T) { } func TestNewTrustyEvaluator(t *testing.T) { - ghProvider := mockgithub.NewMockGitHub(nil) + ghProvider := mock_github.NewMockGitHub(nil) t.Parallel() for _, tc := range []struct { name string @@ -243,9 +243,9 @@ func TestClassifyDependency(t *testing.T) { ctx := context.Background() logger := zerolog.Ctx(ctx).With().Logger() - dep := models.ContextualDependency{ - Dep: models.Dependency{ - Ecosystem: models.NPMDependency, + dep := &pbinternal.PrDependencies_ContextualDependency{ + Dep: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "test", Version: "v0.0.1", }, @@ -398,7 +398,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "no-description", sut: dependencyAlternatives{ - Dependency: &models.Dependency{}, + Dependency: &pbinternal.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{}, @@ -408,7 +408,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "normal-response", sut: dependencyAlternatives{ - Dependency: &models.Dependency{}, + Dependency: &pbinternal.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{ @@ -431,7 +431,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "normal-response", sut: dependencyAlternatives{ - Dependency: &models.Dependency{}, + Dependency: &pbinternal.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{ @@ -454,7 +454,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "typosquatting-low", sut: dependencyAlternatives{ - Dependency: &models.Dependency{}, + Dependency: &pbinternal.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{ @@ -469,7 +469,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "typosquatting-high", sut: dependencyAlternatives{ - Dependency: &models.Dependency{}, + Dependency: &pbinternal.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{ diff --git a/internal/engine/eval/vulncheck/actions.go b/internal/engine/eval/vulncheck/actions.go index 3542dd8c7a..f6cbe1a53f 100644 --- a/internal/engine/eval/vulncheck/actions.go +++ b/internal/engine/eval/vulncheck/actions.go @@ -22,7 +22,7 @@ import ( "github.com/google/go-github/v61/github" "github.com/stacklok/minder/internal/engine/eval/pr_actions" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" provifv1 "github.com/stacklok/minder/pkg/providers/v1" ) @@ -30,7 +30,7 @@ import ( type prStatusHandler interface { trackVulnerableDep( ctx context.Context, - dep models.ContextualDependency, + dep *pbinternal.PrDependencies_ContextualDependency, vulnResp *VulnerabilityResponse, patch patchLocatorFormatter, ) error diff --git a/internal/engine/eval/vulncheck/config.go b/internal/engine/eval/vulncheck/config.go index 5b4ac4a3ab..0dc510a236 100644 --- a/internal/engine/eval/vulncheck/config.go +++ b/internal/engine/eval/vulncheck/config.go @@ -23,7 +23,7 @@ import ( "github.com/go-viper/mapstructure/v2" "github.com/stacklok/minder/internal/engine/eval/pr_actions" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" ) type vulnDbType string @@ -106,8 +106,8 @@ func parseConfig(ruleCfg map[string]any) (*config, error) { return &conf, nil } -func (c *config) getEcosystemConfig(ecosystem models.DependencyEcosystem) *ecosystemConfig { - sEco := string(ecosystem) +func (c *config) getEcosystemConfig(ecosystem pbinternal.DepEcosystem) *ecosystemConfig { + sEco := ecosystem.AsString() if sEco == "" { return nil } diff --git a/internal/engine/eval/vulncheck/pkgdb.go b/internal/engine/eval/vulncheck/pkgdb.go index 17792d48eb..ec34c99df7 100644 --- a/internal/engine/eval/vulncheck/pkgdb.go +++ b/internal/engine/eval/vulncheck/pkgdb.go @@ -27,7 +27,7 @@ import ( "github.com/puzpuzpuz/xsync/v3" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" "github.com/stacklok/minder/internal/util" ) @@ -57,7 +57,7 @@ type formatterMeta struct { // than the review handler. type patchLocatorFormatter interface { LineHasDependency(line string) bool - IndentedString(indent int, oldDepLine string, oldDep models.Dependency) string + IndentedString(indent int, oldDepLine string, oldDep *pbinternal.Dependency) string HasPatchedVersion() bool GetPatchedVersion() string GetFormatterMeta() formatterMeta @@ -65,9 +65,9 @@ type patchLocatorFormatter interface { // RepoQuerier is the interface for querying a repository type RepoQuerier interface { - SendRecvRequest(ctx context.Context, dep models.Dependency, patched string, latest bool) (patchLocatorFormatter, error) - NoPatchAvailableFormatter(dep models.Dependency) patchLocatorFormatter - PkgRegistryErrorFormatter(dep models.Dependency, registryErr error) patchLocatorFormatter + SendRecvRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool) (patchLocatorFormatter, error) + NoPatchAvailableFormatter(dep *pbinternal.Dependency) patchLocatorFormatter + PkgRegistryErrorFormatter(dep *pbinternal.Dependency, registryErr error) patchLocatorFormatter } type repoCache struct { @@ -112,7 +112,7 @@ type packageJson struct { } `json:"dist"` } -func (pj *packageJson) IndentedString(indent int, oldDepLine string, _ models.Dependency) string { +func (pj *packageJson) IndentedString(indent int, oldDepLine string, _ *pbinternal.Dependency) string { padding := fmt.Sprintf("%*s", indent, "") innerPadding := padding + " " // Add 2 extra spaces @@ -179,7 +179,7 @@ type PyPiReply struct { // them. Since PyPi doesn't indent, but can specify zero or multiple versions, we // don't care about the indent parameter. This is ripe for refactoring, though, // see the comment in the patchLocatorFormatter interface. -func (p *PyPiReply) IndentedString(_ int, oldDepLine string, oldDep models.Dependency) string { +func (p *PyPiReply) IndentedString(_ int, oldDepLine string, oldDep *pbinternal.Dependency) string { return strings.Replace(oldDepLine, oldDep.Version, p.Info.Version, 1) } @@ -212,11 +212,7 @@ func (p *PyPiReply) GetFormatterMeta() formatterMeta { return p.formatterMeta } -func (p *pypiRepository) SendRecvRequest( - ctx context.Context, - dep models.Dependency, - patched string, - latest bool, +func (p *pypiRepository) SendRecvRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, ) (patchLocatorFormatter, error) { req, err := p.newRequest(ctx, dep, patched, latest) if err != nil { @@ -244,7 +240,7 @@ func (p *pypiRepository) SendRecvRequest( return &pkgJson, nil } -func (_ *pypiRepository) NoPatchAvailableFormatter(dep models.Dependency) patchLocatorFormatter { +func (_ *pypiRepository) NoPatchAvailableFormatter(dep *pbinternal.Dependency) patchLocatorFormatter { return &PyPiReply{ Info: struct { Name string `json:"name"` @@ -253,7 +249,7 @@ func (_ *pypiRepository) NoPatchAvailableFormatter(dep models.Dependency) patchL } } -func (_ *pypiRepository) PkgRegistryErrorFormatter(dep models.Dependency, registryErr error) patchLocatorFormatter { +func (_ *pypiRepository) PkgRegistryErrorFormatter(dep *pbinternal.Dependency, registryErr error) patchLocatorFormatter { return &PyPiReply{ formatterMeta: formatterMeta{ pkgRegistryLookupError: registryErr, @@ -273,10 +269,7 @@ func newPyPIRepository(endpoint string) *pypiRepository { } func (p *pypiRepository) newRequest( - ctx context.Context, - dep models.Dependency, - patched string, - latest bool, + ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, ) (*http.Request, error) { var u *url.URL var err error @@ -315,10 +308,7 @@ func newNpmRepository(endpoint string) *npmRepository { var _ RepoQuerier = (*npmRepository)(nil) func (n *npmRepository) newRequest( - ctx context.Context, - dep models.Dependency, - patched string, - latest bool, + ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, ) (*http.Request, error) { var version string if latest { @@ -339,11 +329,7 @@ func (n *npmRepository) newRequest( return req, nil } -func (n *npmRepository) SendRecvRequest( - ctx context.Context, - dep models.Dependency, - patched string, - latest bool, +func (n *npmRepository) SendRecvRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, ) (patchLocatorFormatter, error) { req, err := n.newRequest(ctx, dep, patched, latest) if err != nil { @@ -371,14 +357,14 @@ func (n *npmRepository) SendRecvRequest( return &pkgJson, nil } -func (_ *npmRepository) NoPatchAvailableFormatter(dep models.Dependency) patchLocatorFormatter { +func (_ *npmRepository) NoPatchAvailableFormatter(dep *pbinternal.Dependency) patchLocatorFormatter { return &packageJson{ Name: dep.Name, Version: "", } } -func (_ *npmRepository) PkgRegistryErrorFormatter(dep models.Dependency, registryErr error) patchLocatorFormatter { +func (_ *npmRepository) PkgRegistryErrorFormatter(dep *pbinternal.Dependency, registryErr error) patchLocatorFormatter { return &packageJson{ formatterMeta: formatterMeta{ pkgRegistryLookupError: registryErr, @@ -400,7 +386,7 @@ type goModPackage struct { DependencyHash string `json:"dependency_hash"` } -func (gmp *goModPackage) IndentedString(indent int, _ string, _ models.Dependency) string { +func (gmp *goModPackage) IndentedString(indent int, _ string, _ *pbinternal.Dependency) string { return fmt.Sprintf("%s%s %s", strings.Repeat(" ", indent), gmp.Name, gmp.Version) } @@ -442,11 +428,7 @@ func newGoProxySumRepository(proxyEndpoint, sumEndpoint string) *goProxyReposito // check that npmRepository implements RepoQuerier var _ RepoQuerier = (*goProxyRepository)(nil) -func (r *goProxyRepository) goProxyRequest( - ctx context.Context, - dep models.Dependency, - patched string, - latest bool, +func (r *goProxyRepository) goProxyRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, ) (*http.Request, error) { var u *url.URL var err error @@ -527,11 +509,7 @@ func parseGoSumReply(goPkg *goModPackage, reply io.Reader) error { return nil } -func (r *goProxyRepository) SendRecvRequest( - ctx context.Context, - dep models.Dependency, - patched string, - latest bool, +func (r *goProxyRepository) SendRecvRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, ) (patchLocatorFormatter, error) { proxyReq, err := r.goProxyRequest(ctx, dep, patched, latest) if err != nil { @@ -587,14 +565,14 @@ func (r *goProxyRepository) SendRecvRequest( return goPackage, nil } -func (_ *goProxyRepository) NoPatchAvailableFormatter(dep models.Dependency) patchLocatorFormatter { +func (_ *goProxyRepository) NoPatchAvailableFormatter(dep *pbinternal.Dependency) patchLocatorFormatter { return &goModPackage{ Name: dep.Name, oldVersion: dep.Version, } } -func (_ *goProxyRepository) PkgRegistryErrorFormatter(dep models.Dependency, registryErr error) patchLocatorFormatter { +func (_ *goProxyRepository) PkgRegistryErrorFormatter(dep *pbinternal.Dependency, registryErr error) patchLocatorFormatter { return &goModPackage{ formatterMeta: formatterMeta{ pkgRegistryLookupError: registryErr, diff --git a/internal/engine/eval/vulncheck/pkgdb_test.go b/internal/engine/eval/vulncheck/pkgdb_test.go index c7579f9f80..c942c609e7 100644 --- a/internal/engine/eval/vulncheck/pkgdb_test.go +++ b/internal/engine/eval/vulncheck/pkgdb_test.go @@ -25,7 +25,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" ) func TestNpmPkgDb(t *testing.T) { @@ -146,7 +146,7 @@ func TestNpmPkgDb(t *testing.T) { repo := newNpmRepository(server.URL) - dep := models.Dependency{ + dep := &pbinternal.Dependency{ Name: tt.depName, } @@ -162,7 +162,7 @@ func TestNpmPkgDb(t *testing.T) { assert.Error(t, err, "Expected error") } else { assert.NoError(t, err, "Expected no error") - require.Equal(t, tt.expectReply.IndentedString(0, "", models.Dependency{}), reply.IndentedString(0, "", models.Dependency{}), "expected reply to match mock data") + require.Equal(t, tt.expectReply.IndentedString(0, "", nil), reply.IndentedString(0, "", nil), "expected reply to match mock data") } }) } @@ -383,7 +383,7 @@ func TestPyPiPkgDb(t *testing.T) { repo := newPyPIRepository(pyPiMockServer.URL) assert.NotNil(t, repo, "Failed to create repository") - dep := models.Dependency{ + dep := &pbinternal.Dependency{ Name: tt.depName, } @@ -401,7 +401,7 @@ func TestPyPiPkgDb(t *testing.T) { assert.NoError(t, err, "Expected no error") actualReply := reply.IndentedString(0, "requests>=2.19.0", - models.Dependency{ + &pbinternal.Dependency{ Name: "requests", Version: "2.19.0", }) @@ -592,7 +592,7 @@ golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=`)) repo := newGoProxySumRepository(proxyServer.URL, sumServer.URL) assert.NotNil(t, repo, "Failed to create repository") - dep := models.Dependency{ + dep := &pbinternal.Dependency{ Name: tt.depName, } @@ -608,7 +608,7 @@ golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=`)) assert.Error(t, err, "Expected error") } else { assert.NoError(t, err, "Expected no error") - require.Equal(t, tt.expectReply.IndentedString(0, "", models.Dependency{}), reply.IndentedString(0, "", models.Dependency{}), "expected reply to match mock data") + require.Equal(t, tt.expectReply.IndentedString(0, "", nil), reply.IndentedString(0, "", nil), "expected reply to match mock data") } }) } diff --git a/internal/engine/eval/vulncheck/report.go b/internal/engine/eval/vulncheck/report.go index 16c5d3b244..d2bc22ad3a 100644 --- a/internal/engine/eval/vulncheck/report.go +++ b/internal/engine/eval/vulncheck/report.go @@ -147,7 +147,7 @@ func (r *vulnSummaryReport) render() (string, error) { DependencyVersion string Vulnerabilities []Vulnerability }{ - DependencyEcosystem: string(dep.Dependency.Ecosystem), + DependencyEcosystem: dep.Dependency.Ecosystem.AsString(), DependencyName: dep.Dependency.Name, DependencyVersion: dep.Dependency.Version, Vulnerabilities: dep.Vulnerabilities, diff --git a/internal/engine/eval/vulncheck/review.go b/internal/engine/eval/vulncheck/review.go index 889be70758..ee910d092b 100644 --- a/internal/engine/eval/vulncheck/review.go +++ b/internal/engine/eval/vulncheck/review.go @@ -25,7 +25,7 @@ import ( "github.com/google/go-github/v61/github" "github.com/rs/zerolog" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" provifv1 "github.com/stacklok/minder/pkg/providers/v1" ) @@ -62,10 +62,10 @@ func countLeadingWhitespace(line string) int { func locateDepInPr( ctx context.Context, client provifv1.GitHub, - dep models.ContextualDependency, + dep *pbinternal.PrDependencies_ContextualDependency, patch patchLocatorFormatter, ) (*reviewLocation, error) { - req, err := client.NewRequest("GET", dep.File.PatchURL, nil) + req, err := client.NewRequest("GET", dep.File.PatchUrl, nil) if err != nil { return nil, fmt.Errorf("could not create request: %w", err) } @@ -88,8 +88,7 @@ func locateDepInPr( // was causing 422 issues with GitHub when trying to submit a review. // Also, to ensure we are grabbing the correct line, we need to check if the // versions align. - - if dep.Dep.Ecosystem == models.NPMDependency && i+1 < len(lines) { + if dep.Dep.Ecosystem == pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM && i+1 < len(lines) { line = strings.Join([]string{line, lines[i+1], dep.Dep.Version}, "\n") loc.lineToChange = i + 2 } else { @@ -189,7 +188,7 @@ func newReviewPrHandler( func (ra *reviewPrHandler) trackVulnerableDep( ctx context.Context, - dep models.ContextualDependency, + dep *pbinternal.PrDependencies_ContextualDependency, vulnResp *VulnerabilityResponse, patch patchLocatorFormatter, ) error { @@ -236,7 +235,7 @@ func (ra *reviewPrHandler) trackVulnerableDep( Msg("vulnerable dependency found") ra.trackedDeps = append(ra.trackedDeps, dependencyVulnerabilities{ - Dependency: &dep.Dep, + Dependency: dep.Dep, Vulnerabilities: vulnResp.Vulns, PatchVersion: patch.GetPatchedVersion(), }) @@ -511,19 +510,19 @@ type summaryPrHandler struct { } type dependencyVulnerabilities struct { - Dependency *models.Dependency + Dependency *pbinternal.Dependency Vulnerabilities []Vulnerability PatchVersion string } func (sph *summaryPrHandler) trackVulnerableDep( _ context.Context, - dep models.ContextualDependency, + dep *pbinternal.PrDependencies_ContextualDependency, vulnResp *VulnerabilityResponse, patch patchLocatorFormatter, ) error { sph.trackedDeps = append(sph.trackedDeps, dependencyVulnerabilities{ - Dependency: &dep.Dep, + Dependency: dep.Dep, Vulnerabilities: vulnResp.Vulns, PatchVersion: patch.GetPatchedVersion(), }) @@ -572,7 +571,7 @@ type profileOnlyPrHandler struct{} func (profileOnlyPrHandler) trackVulnerableDep( _ context.Context, - _ models.ContextualDependency, + _ *pbinternal.PrDependencies_ContextualDependency, _ *VulnerabilityResponse, _ patchLocatorFormatter, ) error { diff --git a/internal/engine/eval/vulncheck/review_test.go b/internal/engine/eval/vulncheck/review_test.go index 1cc76092c6..490d56b6e5 100644 --- a/internal/engine/eval/vulncheck/review_test.go +++ b/internal/engine/eval/vulncheck/review_test.go @@ -29,7 +29,7 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" mock_ghclient "github.com/stacklok/minder/internal/providers/github/mock" pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" ) @@ -113,15 +113,15 @@ func TestReviewPrHandlerVulnerabilitiesDifferentIdentities(t *testing.T) { })) defer server.Close() - dep := models.ContextualDependency{ - Dep: models.Dependency{ - Ecosystem: models.NPMDependency, + dep := &pbinternal.PrDependencies_ContextualDependency{ + Dep: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "mongodb", Version: "0.5.0", }, - File: models.FilePatch{ + File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ Name: "package-lock.json", - PatchURL: server.URL, + PatchUrl: server.URL, }, } @@ -155,7 +155,7 @@ func TestReviewPrHandlerVulnerabilitiesDifferentIdentities(t *testing.T) { require.NoError(t, err) statusReport := createStatusReport(vulnsFoundText, commitSHA, 0, dependencyVulnerabilities{ - Dependency: &dep.Dep, + Dependency: dep.Dep, Vulnerabilities: vulnResp.Vulns, PatchVersion: "0.6.0", }, @@ -222,15 +222,15 @@ func TestReviewPrHandlerVulnerabilitiesErrLookUpPackage(t *testing.T) { })) defer server.Close() - dep := models.ContextualDependency{ - Dep: models.Dependency{ - Ecosystem: models.NPMDependency, + dep := &pbinternal.PrDependencies_ContextualDependency{ + Dep: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "mongodb", Version: "0.5.0", }, - File: models.FilePatch{ + File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ Name: "package-lock.json", - PatchURL: server.URL, + PatchUrl: server.URL, }, } @@ -316,15 +316,15 @@ func TestReviewPrHandlerVulnerabilitiesWithNoPatchVersion(t *testing.T) { })) defer server.Close() - dep := models.ContextualDependency{ - Dep: models.Dependency{ - Ecosystem: models.NPMDependency, + dep := &pbinternal.PrDependencies_ContextualDependency{ + Dep: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "mongodb", Version: "0.5.0", }, - File: models.FilePatch{ + File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ Name: "package-lock.json", - PatchURL: server.URL, + PatchUrl: server.URL, }, } @@ -348,7 +348,7 @@ func TestReviewPrHandlerVulnerabilitiesWithNoPatchVersion(t *testing.T) { require.NoError(t, err) statusReport := createStatusReport(vulnsFoundText, commitSHA, 0, dependencyVulnerabilities{ - Dependency: &dep.Dep, + Dependency: dep.Dep, Vulnerabilities: vulnResp.Vulns, PatchVersion: "", }, @@ -422,15 +422,15 @@ func TestReviewPrHandlerVulnerabilitiesDismissReview(t *testing.T) { })) defer server.Close() - dep := models.ContextualDependency{ - Dep: models.Dependency{ - Ecosystem: models.NPMDependency, + dep := &pbinternal.PrDependencies_ContextualDependency{ + Dep: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "mongodb", Version: "0.5.0", }, - File: models.FilePatch{ + File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ Name: "package-lock.json", - PatchURL: server.URL, + PatchUrl: server.URL, }, } @@ -446,7 +446,7 @@ func TestReviewPrHandlerVulnerabilitiesDismissReview(t *testing.T) { }, nil) statusReport := createStatusReport(vulnsFoundText, commitSHA, minderReviewID, dependencyVulnerabilities{ - Dependency: &dep.Dep, + Dependency: dep.GetDep(), Vulnerabilities: vulnResp.Vulns, PatchVersion: "", }) @@ -573,15 +573,15 @@ func TestCommitStatusPrHandlerWithVulnerabilities(t *testing.T) { })) defer server.Close() - dep := models.ContextualDependency{ - Dep: models.Dependency{ - Ecosystem: models.NPMDependency, + dep := &pbinternal.PrDependencies_ContextualDependency{ + Dep: &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "mongodb", Version: "0.5.0", }, - File: models.FilePatch{ + File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ Name: "package-lock.json", - PatchURL: server.URL, + PatchUrl: server.URL, }, } @@ -615,7 +615,7 @@ func TestCommitStatusPrHandlerWithVulnerabilities(t *testing.T) { require.NoError(t, err) statusReport := createStatusReport(vulnsFoundText, commitSHA, 0, dependencyVulnerabilities{ - Dependency: &dep.Dep, + Dependency: dep.GetDep(), Vulnerabilities: vulnResp.Vulns, PatchVersion: "0.6.0", }) diff --git a/internal/engine/eval/vulncheck/vulncheck.go b/internal/engine/eval/vulncheck/vulncheck.go index 65d01c32bb..bcb8f2f183 100644 --- a/internal/engine/eval/vulncheck/vulncheck.go +++ b/internal/engine/eval/vulncheck/vulncheck.go @@ -25,7 +25,7 @@ import ( evalerrors "github.com/stacklok/minder/internal/engine/errors" engif "github.com/stacklok/minder/internal/engine/interfaces" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" provifv1 "github.com/stacklok/minder/pkg/providers/v1" ) @@ -70,7 +70,7 @@ func (e *Evaluator) getVulnerableDependencies(ctx context.Context, pol map[strin // TODO(jhrozek): Fix this! //nolint:govet - prdeps, ok := res.Object.(*models.PRDependencies) + prdeps, ok := res.Object.(*pbinternal.PrDependencies) if !ok { return nil, fmt.Errorf("invalid object type for vulncheck evaluator") } @@ -84,7 +84,7 @@ func (e *Evaluator) getVulnerableDependencies(ctx context.Context, pol map[strin return nil, fmt.Errorf("failed to parse config: %w", err) } - prReplyHandler, err := newPrStatusHandler(ctx, ruleConfig.Action, prdeps.PR, e.cli) + prReplyHandler, err := newPrStatusHandler(ctx, ruleConfig.Action, prdeps.Pr, e.cli) if err != nil { return nil, fmt.Errorf("failed to create pr action: %w", err) } @@ -92,7 +92,7 @@ func (e *Evaluator) getVulnerableDependencies(ctx context.Context, pol map[strin pkgRepoCache := newRepoCache() for _, dep := range prdeps.Deps { - if dep.Dep.Version == "" { + if dep.Dep == nil || dep.Dep.Version == "" { continue } @@ -153,8 +153,8 @@ func (_ *Evaluator) getVulnDb(dbType vulnDbType, endpoint string) (vulnDb, error func (_ *Evaluator) queryVulnDb( ctx context.Context, db vulnDb, - dep models.Dependency, - ecosystem models.DependencyEcosystem, + dep *pbinternal.Dependency, + ecosystem pbinternal.DepEcosystem, ) (*VulnerabilityResponse, error) { req, err := db.NewQuery(ctx, dep, ecosystem) if err != nil { @@ -172,7 +172,7 @@ func (_ *Evaluator) queryVulnDb( // checkVulnerabilities checks whether a PR dependency contains any vulnerabilities. func (e *Evaluator) checkVulnerabilities( ctx context.Context, - dep models.ContextualDependency, + dep *pbinternal.PrDependencies_ContextualDependency, cfg *config, cache *repoCache, prHandler prStatusHandler, diff --git a/internal/engine/eval/vulncheck/vulndb.go b/internal/engine/eval/vulncheck/vulndb.go index c7130bab80..1297c78d4e 100644 --- a/internal/engine/eval/vulncheck/vulndb.go +++ b/internal/engine/eval/vulncheck/vulndb.go @@ -26,7 +26,7 @@ import ( "github.com/hashicorp/go-version" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" ) // Vulnerability is a vulnerability JSON representation @@ -46,8 +46,8 @@ type VulnerabilityResponse struct { // TODO(jakub): it's ugly that we depend on types from ingester/diff type vulnDb interface { - NewQuery(ctx context.Context, dep models.Dependency, eco models.DependencyEcosystem) (*http.Request, error) - SendRecvRequest(r *http.Request, dep models.Dependency) (*VulnerabilityResponse, error) + NewQuery(ctx context.Context, dep *pbinternal.Dependency, eco pbinternal.DepEcosystem) (*http.Request, error) + SendRecvRequest(r *http.Request, dep *pbinternal.Dependency) (*VulnerabilityResponse, error) } // OSVResponse is a response from the OSV database @@ -95,7 +95,7 @@ type OSVResponse struct { } `json:"vulns"` } -func toVulnerabilityResponse(osvResp *OSVResponse, dep models.Dependency) *VulnerabilityResponse { +func toVulnerabilityResponse(osvResp *OSVResponse, dep *pbinternal.Dependency) *VulnerabilityResponse { var vulnResp VulnerabilityResponse for _, osvVuln := range osvResp.Vulns { @@ -171,12 +171,12 @@ func newOsvDb(endpoint string) *osvdb { } } -func (o *osvdb) NewQuery(ctx context.Context, dep models.Dependency, eco models.DependencyEcosystem) (*http.Request, error) { +func (o *osvdb) NewQuery(ctx context.Context, dep *pbinternal.Dependency, eco pbinternal.DepEcosystem) (*http.Request, error) { reqBody := map[string]interface{}{ "version": dep.Version, "package": map[string]string{ "name": dep.Name, - "ecosystem": string(eco), + "ecosystem": eco.AsString(), }, } @@ -195,7 +195,7 @@ func (o *osvdb) NewQuery(ctx context.Context, dep models.Dependency, eco models. return req, nil } -func (_ *osvdb) SendRecvRequest(r *http.Request, dep models.Dependency) (*VulnerabilityResponse, error) { +func (_ *osvdb) SendRecvRequest(r *http.Request, dep *pbinternal.Dependency) (*VulnerabilityResponse, error) { client := &http.Client{} resp, err := client.Do(r) if err != nil { diff --git a/internal/engine/eval/vulncheck/vulndb_test.go b/internal/engine/eval/vulncheck/vulndb_test.go index 49afbdd867..81592afa70 100644 --- a/internal/engine/eval/vulncheck/vulndb_test.go +++ b/internal/engine/eval/vulncheck/vulndb_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" ) const multipleRanges = ` @@ -306,7 +306,7 @@ func TestGoVulnDb(t *testing.T) { db := newOsvDb(vulnServer.URL) assert.NotNil(t, db, "Failed to create OSV DB") - dep := models.Dependency{ + dep := &pbinternal.Dependency{ Name: tt.depName, Version: tt.depVersion, } diff --git a/internal/engine/ingester/diff/diff.go b/internal/engine/ingester/diff/diff.go index d1304840d4..064cc50400 100644 --- a/internal/engine/ingester/diff/diff.go +++ b/internal/engine/ingester/diff/diff.go @@ -28,7 +28,7 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" engif "github.com/stacklok/minder/internal/engine/interfaces" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" provifv1 "github.com/stacklok/minder/pkg/providers/v1" ) @@ -95,7 +95,7 @@ func (di *Diff) Ingest( page := 0 switch di.cfg.GetType() { case "", pb.DiffTypeDep: - allDiffs := make([]models.ContextualDependency, 0) + allDiffs := make([]*pbinternal.PrDependencies_ContextualDependency, 0) for { prFiles, resp, err := di.cli.ListFiles(ctx, pr.RepoOwner, pr.RepoName, int(pr.Number), prFilesPerPage, page) if err != nil { @@ -118,14 +118,14 @@ func (di *Diff) Ingest( } return &engif.Result{ - Object: &models.PRDependencies{ - PR: pr, + Object: &pbinternal.PrDependencies{ + Pr: pr, Deps: allDiffs, }, }, nil case pb.DiffTypeFull: - allDiffs := make([]models.PRFile, 0) + allDiffs := make([]*pbinternal.PrContents_File, 0) for { prFiles, resp, err := di.cli.ListFiles(ctx, pr.RepoOwner, pr.RepoName, int(pr.Number), prFilesPerPage, page) if err != nil { @@ -137,7 +137,7 @@ func (di *Diff) Ingest( if err != nil { return nil, fmt.Errorf("error ingesting file %s: %w", file.GetFilename(), err) } - allDiffs = append(allDiffs, *fileDiffs) + allDiffs = append(allDiffs, fileDiffs) } if resp.NextPage == 0 { @@ -148,8 +148,8 @@ func (di *Diff) Ingest( } return &engif.Result{ - Object: models.PRContents{ - PR: pr, + Object: &pbinternal.PrContents{ + Pr: pr, Files: allDiffs, }, }, nil @@ -162,7 +162,7 @@ func (di *Diff) Ingest( func (di *Diff) ingestFileForDepDiff( filename, patchContents, patchUrl string, logger zerolog.Logger, -) ([]models.ContextualDependency, error) { +) ([]*pbinternal.PrDependencies_ContextualDependency, error) { parser := di.getParserForFile(filename, logger) if parser == nil { return nil, nil @@ -173,13 +173,14 @@ func (di *Diff) ingestFileForDepDiff( return nil, fmt.Errorf("error parsing file %s: %w", filename, err) } - batchCtxDeps := make([]models.ContextualDependency, 0, len(depBatch)) - for _, dep := range depBatch { - batchCtxDeps = append(batchCtxDeps, models.ContextualDependency{ + batchCtxDeps := make([]*pbinternal.PrDependencies_ContextualDependency, 0, len(depBatch)) + for i := range depBatch { + dep := depBatch[i] + batchCtxDeps = append(batchCtxDeps, &pbinternal.PrDependencies_ContextualDependency{ Dep: dep, - File: models.FilePatch{ + File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ Name: filename, - PatchURL: patchUrl, + PatchUrl: patchUrl, }, }) } @@ -191,8 +192,8 @@ func (di *Diff) ingestFileForDepDiff( // It scans through the patch line by line, identifying the changes made. // If it's a hunk header, it extracts the starting line number. If it's an addition, it records the line content and its number. // The function also increments the line number for context lines (lines that provide context but haven't been modified). -func ingestFileForFullDiff(filename, patch, patchUrl string) (*models.PRFile, error) { - var result []models.PRFileLine +func ingestFileForFullDiff(filename, patch, patchUrl string) (*pbinternal.PrContents_File, error) { + var result []*pbinternal.PrContents_File_Line scanner := bufio.NewScanner(strings.NewReader(patch)) regex := regexp.MustCompile(`@@ -\d+,\d+ \+(\d+),\d+ @@`) @@ -208,7 +209,7 @@ func ingestFileForFullDiff(filename, patch, patchUrl string) (*models.PRFile, er return nil, fmt.Errorf("error parsing line number from the hunk header: %w", err) } } else if strings.HasPrefix(line, "+") { - result = append(result, models.PRFileLine{ + result = append(result, &pbinternal.PrContents_File_Line{ Content: line[1:], // see the use of strconv.ParseInt above: this is a safe downcast LineNumber: int32(currentLineNumber), @@ -224,9 +225,9 @@ func ingestFileForFullDiff(filename, patch, patchUrl string) (*models.PRFile, er return nil, fmt.Errorf("error reading patch: %w", err) } - return &models.PRFile{ + return &pbinternal.PrContents_File{ Name: filename, - FilePatchURL: patchUrl, + FilePatchUrl: patchUrl, PatchLines: result, }, nil } diff --git a/internal/engine/ingester/diff/parse.go b/internal/engine/ingester/diff/parse.go index 9768157b85..ff6cae2bb4 100644 --- a/internal/engine/ingester/diff/parse.go +++ b/internal/engine/ingester/diff/parse.go @@ -22,7 +22,7 @@ import ( "slices" "strings" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" "github.com/stacklok/minder/internal/util" ) @@ -31,7 +31,7 @@ var ( dependencyNameRegex = regexp.MustCompile(`\s*"([^"]+)"\s*:\s*{\s*`) ) -type ecosystemParser func(string) ([]models.Dependency, error) +type ecosystemParser func(string) ([]*pbinternal.Dependency, error) func newEcosystemParser(eco DependencyEcosystem) ecosystemParser { switch strings.ToLower(string(eco)) { @@ -50,8 +50,8 @@ func newEcosystemParser(eco DependencyEcosystem) ecosystemParser { } } -func requirementsParse(patch string) ([]models.Dependency, error) { - var deps []models.Dependency +func requirementsParse(patch string) ([]*pbinternal.Dependency, error) { + var deps []*pbinternal.Dependency scanner := bufio.NewScanner(strings.NewReader(patch)) for scanner.Scan() { @@ -122,9 +122,9 @@ func pyReqNormalizeLine(line string) string { return strings.TrimSpace(line) } -func pyReqAddPkgName(depList []models.Dependency, pkgName, version string) []models.Dependency { - dep := models.Dependency{ - Ecosystem: models.PyPIDependency, +func pyReqAddPkgName(depList []*pbinternal.Dependency, pkgName, version string) []*pbinternal.Dependency { + dep := &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: pyNormalizeName(pkgName), Version: version, } @@ -137,8 +137,8 @@ func pyNormalizeName(pkgName string) string { return strings.ToLower(result) } -func goParse(patch string) ([]models.Dependency, error) { - var deps []models.Dependency +func goParse(patch string) ([]*pbinternal.Dependency, error) { + var deps []*pbinternal.Dependency scanner := bufio.NewScanner(strings.NewReader(patch)) // Iterate over the lines of the go.mod patch and parse the dependencies @@ -147,7 +147,7 @@ func goParse(patch string) ([]models.Dependency, error) { dep := extractGoDepFromPatchLine(scanner.Text()) // If we failed to extract a dependency, or if it's already in the slice, skip it - if dep == nil || slices.ContainsFunc(deps, func(n models.Dependency) bool { + if dep == nil || slices.ContainsFunc(deps, func(n *pbinternal.Dependency) bool { if n.Name == dep.Name && n.Version == dep.Version { return true } @@ -157,7 +157,7 @@ func goParse(patch string) ([]models.Dependency, error) { } // Add the dependency to the slice - deps = append(deps, *dep) + deps = append(deps, dep) } if err := scanner.Err(); err != nil { return nil, err @@ -165,7 +165,7 @@ func goParse(patch string) ([]models.Dependency, error) { return deps, nil } -func extractGoDepFromPatchLine(line string) *models.Dependency { +func extractGoDepFromPatchLine(line string) *pbinternal.Dependency { // Look for lines that add dependencies. // We ignore lines that contain "// indirect" because they are transitive dependencies, and therefore // not actionable. @@ -179,8 +179,8 @@ func extractGoDepFromPatchLine(line string) *models.Dependency { return nil } - dep := &models.Dependency{ - Ecosystem: models.GoDependency, + dep := &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_GO, } if fields[0] == "require" && fields[1] != "(" && len(fields) >= 3 { dep.Name = fields[1] @@ -204,10 +204,10 @@ func extractGoDepFromPatchLine(line string) *models.Dependency { return nil } -func npmParse(patch string) ([]models.Dependency, error) { +func npmParse(patch string) ([]*pbinternal.Dependency, error) { lines := strings.Split(patch, "\n") - var deps []models.Dependency + var deps []*pbinternal.Dependency for i, line := range lines { // Check if the line contains a version @@ -218,8 +218,8 @@ func npmParse(patch string) ([]models.Dependency, error) { // The version is not always a dependency version. It may also be the version of the package in this repo, // or the version of the root project. See https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json if name != "" { - deps = append(deps, models.Dependency{ - Ecosystem: models.NPMDependency, + deps = append(deps, &pbinternal.Dependency{ + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: name, Version: version, }) diff --git a/internal/engine/ingester/diff/parse_test.go b/internal/engine/ingester/diff/parse_test.go index 4690334a0b..151e73183b 100644 --- a/internal/engine/ingester/diff/parse_test.go +++ b/internal/engine/ingester/diff/parse_test.go @@ -19,8 +19,9 @@ import ( "testing" "github.com/stretchr/testify/assert" + "google.golang.org/protobuf/proto" - "github.com/stacklok/minder/internal/engine/models" + pbinternal "github.com/stacklok/minder/internal/proto" ) func TestGoParse(t *testing.T) { @@ -30,7 +31,7 @@ func TestGoParse(t *testing.T) { description string content string expectedCount int - expectedDependencies []models.Dependency + expectedDependencies []*pbinternal.Dependency }{ { description: "Single addition", @@ -40,9 +41,9 @@ func TestGoParse(t *testing.T) { github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/prometheus/client_golang v1.18.0`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.GoDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_GO, Name: "github.com/openfga/openfga", Version: "v1.4.3", }, @@ -67,9 +68,9 @@ func TestGoParse(t *testing.T) { - gotest.tools/v3 v3.4.0 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.GoDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_GO, Name: "go.opentelemetry.io/proto/otlp", Version: "v1.0.0", }, @@ -85,7 +86,7 @@ func TestGoParse(t *testing.T) { - gotest.tools/v3 v3.4.0 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect`, expectedCount: 0, - expectedDependencies: []models.Dependency{}, + expectedDependencies: []*pbinternal.Dependency{}, }, { description: "Replace", @@ -96,9 +97,9 @@ func TestGoParse(t *testing.T) { + +replace github.com/opencontainers/runc => github.com/stacklok/runc v1.1.12`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.GoDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_GO, Name: "github.com/stacklok/runc", Version: "v1.1.12", }, @@ -113,7 +114,7 @@ func TestGoParse(t *testing.T) { + +replace github.com/opencontainers/runc => `, expectedCount: 0, - expectedDependencies: []models.Dependency{}, + expectedDependencies: []*pbinternal.Dependency{}, }, { description: "Bad Require", @@ -124,7 +125,7 @@ func TestGoParse(t *testing.T) { + +require github.com/opencontainers/runc`, expectedCount: 0, - expectedDependencies: []models.Dependency{}, + expectedDependencies: []*pbinternal.Dependency{}, }, } for _, tt := range tests { @@ -139,7 +140,7 @@ func TestGoParse(t *testing.T) { assert.Equal(t, tt.expectedCount, len(got), "mismatched dependency count") for i, expectedDep := range tt.expectedDependencies { - if expectedDep != got[i] { + if !proto.Equal(expectedDep, got[i]) { t.Errorf("mismatch at index %d: expected %v, got %v", i, expectedDep, got[i]) } } @@ -154,7 +155,7 @@ func TestPyPiParse(t *testing.T) { description string content string expectedCount int - expectedDependencies []models.Dependency + expectedDependencies []*pbinternal.Dependency }{ { description: "Single addition, exact version", @@ -162,9 +163,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests==2.19.0`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.19.0", }, @@ -177,9 +178,9 @@ func TestPyPiParse(t *testing.T) { +# this version has a CVE +requests==2.19.0`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.19.0", }, @@ -192,9 +193,9 @@ func TestPyPiParse(t *testing.T) { + +requests==2.19.0`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.19.0", }, @@ -206,9 +207,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests>=2.19.0`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.19.0", }, @@ -220,9 +221,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests>=2.19.0`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.19.0", }, @@ -234,9 +235,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests==2.19.0 # this version has a CVE`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.19.0", }, @@ -248,9 +249,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests==2.*`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2", }, @@ -262,9 +263,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "", }, @@ -276,9 +277,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests<=2.19.0`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.19.0", }, @@ -290,9 +291,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests<3,>=2.0`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.0", }, @@ -304,9 +305,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests>=2.0,<3`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.0", }, @@ -320,20 +321,19 @@ func TestPyPiParse(t *testing.T) { +pandas<0.25.0,>=0.24.0 +numpy==1.16.0`, expectedCount: 3, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "requests", Version: "2.0", }, { - - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "pandas", Version: "0.24.0", }, { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "numpy", Version: "1.16.0", }, @@ -346,7 +346,7 @@ func TestPyPiParse(t *testing.T) { # just a comment `, expectedCount: 0, - expectedDependencies: []models.Dependency{}, + expectedDependencies: []*pbinternal.Dependency{}, }, { description: "Single addition, uppercase", @@ -354,9 +354,9 @@ func TestPyPiParse(t *testing.T) { Flask + Django==3.2.21`, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.PyPIDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, Name: "django", Version: "3.2.21", }, @@ -375,7 +375,7 @@ func TestPyPiParse(t *testing.T) { assert.Equal(t, tt.expectedCount, len(got), "mismatched dependency count") for i, expectedDep := range tt.expectedDependencies { - if expectedDep != got[i] { + if !proto.Equal(expectedDep, got[i]) { t.Errorf("mismatch at index %d: expected %v, got %v", i, expectedDep, got[i]) } } @@ -390,7 +390,7 @@ func TestNpmParse(t *testing.T) { description string content string expectedCount int - expectedDependencies []models.Dependency + expectedDependencies []*pbinternal.Dependency }{ { description: "New dependency addition", @@ -418,9 +418,9 @@ func TestNpmParse(t *testing.T) { "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", `, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.NPMDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "chalk", Version: "5.3.0", }, @@ -443,9 +443,9 @@ func TestNpmParse(t *testing.T) { } `, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.NPMDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "lodash", Version: "4.17.21", }, @@ -477,9 +477,9 @@ func TestNpmParse(t *testing.T) { +} `, expectedCount: 1, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.NPMDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "lodash", Version: "4.17.21", }, @@ -517,14 +517,14 @@ func TestNpmParse(t *testing.T) { } `, expectedCount: 2, - expectedDependencies: []models.Dependency{ + expectedDependencies: []*pbinternal.Dependency{ { - Ecosystem: models.NPMDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "@types/node", Version: "20.9.0", }, { - Ecosystem: models.NPMDependency, + Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, Name: "undici-types", Version: "5.26.5", }, @@ -543,7 +543,7 @@ func TestNpmParse(t *testing.T) { assert.Equal(t, tt.expectedCount, len(got), "mismatched dependency count") for i, expectedDep := range tt.expectedDependencies { - if expectedDep != got[i] { + if !proto.Equal(expectedDep, got[i]) { t.Errorf("mismatch at index %d: expected %v, got %v", i, expectedDep, got[i]) } } diff --git a/internal/engine/models/models.go b/internal/engine/models/models.go deleted file mode 100644 index e04d6c74ab..0000000000 --- a/internal/engine/models/models.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2024 Stacklok, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package models contains domain models used by the engine -package models - -import pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" - -// DependencyEcosystem represents an enum of dependency languages -type DependencyEcosystem string - -// Enumerated values of DependencyEcosystem -const ( - NPMDependency DependencyEcosystem = "npm" - GoDependency DependencyEcosystem = "go" - PyPIDependency DependencyEcosystem = "pypi" -) - -// Dependency represents a package -type Dependency struct { - Ecosystem DependencyEcosystem - Name string - Version string -} - -// FilePatch represents the patch which introduced a dependency -type FilePatch struct { - Name string - PatchURL string -} - -// ContextualDependency represents a dependency along with where it was imported -type ContextualDependency struct { - Dep Dependency - File FilePatch -} - -// PRDependencies represents the dependencies introduced in a PR -type PRDependencies struct { - PR *pb.PullRequest - Deps []ContextualDependency -} - -// PRFileLine represents a changed line in a file in a PR -type PRFileLine struct { - // Deliberately left as an int32: a diff with more than 2^31 lines - // could lead to various problems while processing. - LineNumber int32 - Content string -} - -// PRFile represents a file within a PR -type PRFile struct { - Name string - FilePatchURL string - PatchLines []PRFileLine -} - -// PRContents represents a PR and its changes -type PRContents struct { - PR *pb.PullRequest - Files []PRFile -} diff --git a/internal/proto/internal.pb.go b/internal/proto/internal.pb.go index f1de3721a4..b2fb96739b 100644 --- a/internal/proto/internal.pb.go +++ b/internal/proto/internal.pb.go @@ -24,9 +24,11 @@ package proto import ( + v1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" + sync "sync" ) const ( @@ -36,23 +38,566 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type DepEcosystem int32 + +const ( + DepEcosystem_DEP_ECOSYSTEM_UNSPECIFIED DepEcosystem = 0 + DepEcosystem_DEP_ECOSYSTEM_NPM DepEcosystem = 1 + DepEcosystem_DEP_ECOSYSTEM_GO DepEcosystem = 2 + DepEcosystem_DEP_ECOSYSTEM_PYPI DepEcosystem = 3 +) + +// Enum value maps for DepEcosystem. +var ( + DepEcosystem_name = map[int32]string{ + 0: "DEP_ECOSYSTEM_UNSPECIFIED", + 1: "DEP_ECOSYSTEM_NPM", + 2: "DEP_ECOSYSTEM_GO", + 3: "DEP_ECOSYSTEM_PYPI", + } + DepEcosystem_value = map[string]int32{ + "DEP_ECOSYSTEM_UNSPECIFIED": 0, + "DEP_ECOSYSTEM_NPM": 1, + "DEP_ECOSYSTEM_GO": 2, + "DEP_ECOSYSTEM_PYPI": 3, + } +) + +func (x DepEcosystem) Enum() *DepEcosystem { + p := new(DepEcosystem) + *p = x + return p +} + +func (x DepEcosystem) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (DepEcosystem) Descriptor() protoreflect.EnumDescriptor { + return file_internal_proto_enumTypes[0].Descriptor() +} + +func (DepEcosystem) Type() protoreflect.EnumType { + return &file_internal_proto_enumTypes[0] +} + +func (x DepEcosystem) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use DepEcosystem.Descriptor instead. +func (DepEcosystem) EnumDescriptor() ([]byte, []int) { + return file_internal_proto_rawDescGZIP(), []int{0} +} + +type Dependency struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Ecosystem DepEcosystem `protobuf:"varint,1,opt,name=ecosystem,proto3,enum=internal.DepEcosystem" json:"ecosystem,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` +} + +func (x *Dependency) Reset() { + *x = Dependency{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Dependency) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Dependency) ProtoMessage() {} + +func (x *Dependency) ProtoReflect() protoreflect.Message { + mi := &file_internal_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Dependency.ProtoReflect.Descriptor instead. +func (*Dependency) Descriptor() ([]byte, []int) { + return file_internal_proto_rawDescGZIP(), []int{0} +} + +func (x *Dependency) GetEcosystem() DepEcosystem { + if x != nil { + return x.Ecosystem + } + return DepEcosystem_DEP_ECOSYSTEM_UNSPECIFIED +} + +func (x *Dependency) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Dependency) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +type PrDependencies struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Pr *v1.PullRequest `protobuf:"bytes,1,opt,name=pr,proto3" json:"pr,omitempty"` + Deps []*PrDependencies_ContextualDependency `protobuf:"bytes,2,rep,name=deps,proto3" json:"deps,omitempty"` +} + +func (x *PrDependencies) Reset() { + *x = PrDependencies{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrDependencies) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrDependencies) ProtoMessage() {} + +func (x *PrDependencies) ProtoReflect() protoreflect.Message { + mi := &file_internal_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrDependencies.ProtoReflect.Descriptor instead. +func (*PrDependencies) Descriptor() ([]byte, []int) { + return file_internal_proto_rawDescGZIP(), []int{1} +} + +func (x *PrDependencies) GetPr() *v1.PullRequest { + if x != nil { + return x.Pr + } + return nil +} + +func (x *PrDependencies) GetDeps() []*PrDependencies_ContextualDependency { + if x != nil { + return x.Deps + } + return nil +} + +type PrContents struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Pr *v1.PullRequest `protobuf:"bytes,1,opt,name=pr,proto3" json:"pr,omitempty"` + Files []*PrContents_File `protobuf:"bytes,2,rep,name=files,proto3" json:"files,omitempty"` +} + +func (x *PrContents) Reset() { + *x = PrContents{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrContents) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrContents) ProtoMessage() {} + +func (x *PrContents) ProtoReflect() protoreflect.Message { + mi := &file_internal_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrContents.ProtoReflect.Descriptor instead. +func (*PrContents) Descriptor() ([]byte, []int) { + return file_internal_proto_rawDescGZIP(), []int{2} +} + +func (x *PrContents) GetPr() *v1.PullRequest { + if x != nil { + return x.Pr + } + return nil +} + +func (x *PrContents) GetFiles() []*PrContents_File { + if x != nil { + return x.Files + } + return nil +} + +type PrDependencies_ContextualDependency struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Dep *Dependency `protobuf:"bytes,1,opt,name=dep,proto3" json:"dep,omitempty"` + File *PrDependencies_ContextualDependency_FilePatch `protobuf:"bytes,2,opt,name=file,proto3" json:"file,omitempty"` +} + +func (x *PrDependencies_ContextualDependency) Reset() { + *x = PrDependencies_ContextualDependency{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrDependencies_ContextualDependency) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrDependencies_ContextualDependency) ProtoMessage() {} + +func (x *PrDependencies_ContextualDependency) ProtoReflect() protoreflect.Message { + mi := &file_internal_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrDependencies_ContextualDependency.ProtoReflect.Descriptor instead. +func (*PrDependencies_ContextualDependency) Descriptor() ([]byte, []int) { + return file_internal_proto_rawDescGZIP(), []int{1, 0} +} + +func (x *PrDependencies_ContextualDependency) GetDep() *Dependency { + if x != nil { + return x.Dep + } + return nil +} + +func (x *PrDependencies_ContextualDependency) GetFile() *PrDependencies_ContextualDependency_FilePatch { + if x != nil { + return x.File + } + return nil +} + +type PrDependencies_ContextualDependency_FilePatch struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // file changed, e.g. package-lock.json + PatchUrl string `protobuf:"bytes,2,opt,name=patch_url,json=patchUrl,proto3" json:"patch_url,omitempty"` // points to the the raw patchfile +} + +func (x *PrDependencies_ContextualDependency_FilePatch) Reset() { + *x = PrDependencies_ContextualDependency_FilePatch{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrDependencies_ContextualDependency_FilePatch) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrDependencies_ContextualDependency_FilePatch) ProtoMessage() {} + +func (x *PrDependencies_ContextualDependency_FilePatch) ProtoReflect() protoreflect.Message { + mi := &file_internal_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrDependencies_ContextualDependency_FilePatch.ProtoReflect.Descriptor instead. +func (*PrDependencies_ContextualDependency_FilePatch) Descriptor() ([]byte, []int) { + return file_internal_proto_rawDescGZIP(), []int{1, 0, 0} +} + +func (x *PrDependencies_ContextualDependency_FilePatch) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *PrDependencies_ContextualDependency_FilePatch) GetPatchUrl() string { + if x != nil { + return x.PatchUrl + } + return "" +} + +type PrContents_File struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + FilePatchUrl string `protobuf:"bytes,2,opt,name=file_patch_url,json=filePatchUrl,proto3" json:"file_patch_url,omitempty"` + PatchLines []*PrContents_File_Line `protobuf:"bytes,3,rep,name=patch_lines,json=patchLines,proto3" json:"patch_lines,omitempty"` +} + +func (x *PrContents_File) Reset() { + *x = PrContents_File{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrContents_File) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrContents_File) ProtoMessage() {} + +func (x *PrContents_File) ProtoReflect() protoreflect.Message { + mi := &file_internal_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrContents_File.ProtoReflect.Descriptor instead. +func (*PrContents_File) Descriptor() ([]byte, []int) { + return file_internal_proto_rawDescGZIP(), []int{2, 0} +} + +func (x *PrContents_File) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *PrContents_File) GetFilePatchUrl() string { + if x != nil { + return x.FilePatchUrl + } + return "" +} + +func (x *PrContents_File) GetPatchLines() []*PrContents_File_Line { + if x != nil { + return x.PatchLines + } + return nil +} + +type PrContents_File_Line struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Deliberately left as an int32: a diff with more than 2^31 lines + // could lead to various problems while processing. + LineNumber int32 `protobuf:"varint,1,opt,name=line_number,json=lineNumber,proto3" json:"line_number,omitempty"` + Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"` +} + +func (x *PrContents_File_Line) Reset() { + *x = PrContents_File_Line{} + if protoimpl.UnsafeEnabled { + mi := &file_internal_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrContents_File_Line) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrContents_File_Line) ProtoMessage() {} + +func (x *PrContents_File_Line) ProtoReflect() protoreflect.Message { + mi := &file_internal_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrContents_File_Line.ProtoReflect.Descriptor instead. +func (*PrContents_File_Line) Descriptor() ([]byte, []int) { + return file_internal_proto_rawDescGZIP(), []int{2, 0, 0} +} + +func (x *PrContents_File_Line) GetLineNumber() int32 { + if x != nil { + return x.LineNumber + } + return 0 +} + +func (x *PrContents_File_Line) GetContent() string { + if x != nil { + return x.Content + } + return "" +} + var File_internal_proto protoreflect.FileDescriptor var file_internal_proto_rawDesc = []byte{ 0x0a, 0x0e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x12, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x6c, 0x6f, - 0x6b, 0x2f, 0x6d, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, - 0x6c, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x1a, 0x16, 0x6d, 0x69, 0x6e, 0x64, + 0x65, 0x72, 0x2f, 0x76, 0x31, 0x2f, 0x6d, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x70, 0x0a, 0x0a, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, + 0x12, 0x34, 0x0a, 0x09, 0x65, 0x63, 0x6f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0e, 0x32, 0x16, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x44, + 0x65, 0x70, 0x45, 0x63, 0x6f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x52, 0x09, 0x65, 0x63, 0x6f, + 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x22, 0xc7, 0x02, 0x0a, 0x0e, 0x50, 0x72, 0x44, 0x65, 0x70, 0x65, 0x6e, + 0x64, 0x65, 0x6e, 0x63, 0x69, 0x65, 0x73, 0x12, 0x26, 0x0a, 0x02, 0x70, 0x72, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x6d, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, + 0x50, 0x75, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x02, 0x70, 0x72, 0x12, + 0x41, 0x0a, 0x04, 0x64, 0x65, 0x70, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x50, 0x72, 0x44, 0x65, 0x70, 0x65, 0x6e, + 0x64, 0x65, 0x6e, 0x63, 0x69, 0x65, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x75, + 0x61, 0x6c, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, 0x52, 0x04, 0x64, 0x65, + 0x70, 0x73, 0x1a, 0xc9, 0x01, 0x0a, 0x14, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x75, 0x61, + 0x6c, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x26, 0x0a, 0x03, 0x64, + 0x65, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x2e, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, 0x52, 0x03, + 0x64, 0x65, 0x70, 0x12, 0x4b, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x37, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x50, 0x72, 0x44, + 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x69, 0x65, 0x73, 0x2e, 0x43, 0x6f, 0x6e, 0x74, + 0x65, 0x78, 0x74, 0x75, 0x61, 0x6c, 0x44, 0x65, 0x70, 0x65, 0x6e, 0x64, 0x65, 0x6e, 0x63, 0x79, + 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x63, 0x68, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, + 0x1a, 0x3c, 0x0a, 0x09, 0x46, 0x69, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x63, 0x68, 0x12, 0x12, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x74, 0x63, 0x68, 0x55, 0x72, 0x6c, 0x22, 0xac, + 0x02, 0x0a, 0x0a, 0x50, 0x72, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x26, 0x0a, + 0x02, 0x70, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x6d, 0x69, 0x6e, 0x64, + 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x75, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x52, 0x02, 0x70, 0x72, 0x12, 0x2f, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, + 0x50, 0x72, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, + 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x1a, 0xc4, 0x01, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x12, 0x24, 0x0a, 0x0e, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x63, + 0x68, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x69, 0x6c, + 0x65, 0x50, 0x61, 0x74, 0x63, 0x68, 0x55, 0x72, 0x6c, 0x12, 0x3f, 0x0a, 0x0b, 0x70, 0x61, 0x74, + 0x63, 0x68, 0x5f, 0x6c, 0x69, 0x6e, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, + 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x50, 0x72, 0x43, 0x6f, 0x6e, 0x74, + 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x2e, 0x4c, 0x69, 0x6e, 0x65, 0x52, 0x0a, + 0x70, 0x61, 0x74, 0x63, 0x68, 0x4c, 0x69, 0x6e, 0x65, 0x73, 0x1a, 0x41, 0x0a, 0x04, 0x4c, 0x69, + 0x6e, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x6c, 0x69, 0x6e, 0x65, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2a, 0x72, 0x0a, + 0x0c, 0x44, 0x65, 0x70, 0x45, 0x63, 0x6f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x12, 0x1d, 0x0a, + 0x19, 0x44, 0x45, 0x50, 0x5f, 0x45, 0x43, 0x4f, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x55, + 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x15, 0x0a, 0x11, + 0x44, 0x45, 0x50, 0x5f, 0x45, 0x43, 0x4f, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x4e, 0x50, + 0x4d, 0x10, 0x01, 0x12, 0x14, 0x0a, 0x10, 0x44, 0x45, 0x50, 0x5f, 0x45, 0x43, 0x4f, 0x53, 0x59, + 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x47, 0x4f, 0x10, 0x02, 0x12, 0x16, 0x0a, 0x12, 0x44, 0x45, 0x50, + 0x5f, 0x45, 0x43, 0x4f, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x5f, 0x50, 0x59, 0x50, 0x49, 0x10, + 0x03, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x73, 0x74, 0x61, 0x63, 0x6b, 0x6c, 0x6f, 0x6b, 0x2f, 0x6d, 0x69, 0x6e, 0x64, 0x65, 0x72, 0x2f, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_internal_proto_rawDescOnce sync.Once + file_internal_proto_rawDescData = file_internal_proto_rawDesc +) + +func file_internal_proto_rawDescGZIP() []byte { + file_internal_proto_rawDescOnce.Do(func() { + file_internal_proto_rawDescData = protoimpl.X.CompressGZIP(file_internal_proto_rawDescData) + }) + return file_internal_proto_rawDescData } -var file_internal_proto_goTypes = []any{} +var file_internal_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_internal_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_internal_proto_goTypes = []any{ + (DepEcosystem)(0), // 0: internal.DepEcosystem + (*Dependency)(nil), // 1: internal.Dependency + (*PrDependencies)(nil), // 2: internal.PrDependencies + (*PrContents)(nil), // 3: internal.PrContents + (*PrDependencies_ContextualDependency)(nil), // 4: internal.PrDependencies.ContextualDependency + (*PrDependencies_ContextualDependency_FilePatch)(nil), // 5: internal.PrDependencies.ContextualDependency.FilePatch + (*PrContents_File)(nil), // 6: internal.PrContents.File + (*PrContents_File_Line)(nil), // 7: internal.PrContents.File.Line + (*v1.PullRequest)(nil), // 8: minder.v1.PullRequest +} var file_internal_proto_depIdxs = []int32{ - 0, // [0:0] is the sub-list for method output_type - 0, // [0:0] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 0, // 0: internal.Dependency.ecosystem:type_name -> internal.DepEcosystem + 8, // 1: internal.PrDependencies.pr:type_name -> minder.v1.PullRequest + 4, // 2: internal.PrDependencies.deps:type_name -> internal.PrDependencies.ContextualDependency + 8, // 3: internal.PrContents.pr:type_name -> minder.v1.PullRequest + 6, // 4: internal.PrContents.files:type_name -> internal.PrContents.File + 1, // 5: internal.PrDependencies.ContextualDependency.dep:type_name -> internal.Dependency + 5, // 6: internal.PrDependencies.ContextualDependency.file:type_name -> internal.PrDependencies.ContextualDependency.FilePatch + 7, // 7: internal.PrContents.File.patch_lines:type_name -> internal.PrContents.File.Line + 8, // [8:8] is the sub-list for method output_type + 8, // [8:8] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name } func init() { file_internal_proto_init() } @@ -60,18 +605,106 @@ func file_internal_proto_init() { if File_internal_proto != nil { return } + if !protoimpl.UnsafeEnabled { + file_internal_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*Dependency); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_internal_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*PrDependencies); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_internal_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*PrContents); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_internal_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*PrDependencies_ContextualDependency); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_internal_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*PrDependencies_ContextualDependency_FilePatch); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_internal_proto_msgTypes[5].Exporter = func(v any, i int) any { + switch v := v.(*PrContents_File); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_internal_proto_msgTypes[6].Exporter = func(v any, i int) any { + switch v := v.(*PrContents_File_Line); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_internal_proto_rawDesc, - NumEnums: 0, - NumMessages: 0, + NumEnums: 1, + NumMessages: 7, NumExtensions: 0, NumServices: 0, }, GoTypes: file_internal_proto_goTypes, DependencyIndexes: file_internal_proto_depIdxs, + EnumInfos: file_internal_proto_enumTypes, + MessageInfos: file_internal_proto_msgTypes, }.Build() File_internal_proto = out.File file_internal_proto_rawDesc = nil diff --git a/internal/proto/internal.proto b/internal/proto/internal.proto index 1903430a31..771858e7a9 100644 --- a/internal/proto/internal.proto +++ b/internal/proto/internal.proto @@ -18,10 +18,53 @@ syntax = "proto3"; // buf:lint:ignore PACKAGE_VERSION_SUFFIX package internal; +import "minder/v1/minder.proto"; + option go_package = "github.com/stacklok/minder/internal/proto"; -/* - * NOTE: Prefer Go structs over internal-only protobuf definitions unless - * there is a really strong case for using protobufs, e.g. interacting - * with a library which expects protobuf structs. - */ \ No newline at end of file +enum DepEcosystem { + DEP_ECOSYSTEM_UNSPECIFIED = 0; + DEP_ECOSYSTEM_NPM = 1; + DEP_ECOSYSTEM_GO = 2; + DEP_ECOSYSTEM_PYPI = 3; +} + +message Dependency { + DepEcosystem ecosystem = 1; + + string name = 2; + string version = 3; +} + +message PrDependencies { + message ContextualDependency { + message FilePatch { + string name = 1; // file changed, e.g. package-lock.json + string patch_url = 2; // points to the the raw patchfile + } + + Dependency dep = 1; + FilePatch file = 2; + } + + minder.v1.PullRequest pr = 1; + repeated ContextualDependency deps = 2; +} + +message PrContents { + message File { + string name = 1; + string file_patch_url = 2; + repeated Line patch_lines = 3; + + message Line { + // Deliberately left as an int32: a diff with more than 2^31 lines + // could lead to various problems while processing. + int32 line_number = 1; + string content = 2; + } + } + + minder.v1.PullRequest pr = 1; + repeated File files = 2; +} \ No newline at end of file diff --git a/internal/proto/pkg_ecosystems.go b/internal/proto/pkg_ecosystems.go new file mode 100644 index 0000000000..fe4f00b4e5 --- /dev/null +++ b/internal/proto/pkg_ecosystems.go @@ -0,0 +1,32 @@ +// Copyright 2023 Stacklok, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package proto + +// AsString returns the string representation of the DepEcosystem +func (ecosystem DepEcosystem) AsString() string { + switch ecosystem { + case DepEcosystem_DEP_ECOSYSTEM_NPM: + return "npm" + case DepEcosystem_DEP_ECOSYSTEM_GO: + return "Go" + case DepEcosystem_DEP_ECOSYSTEM_PYPI: + return "PyPI" + case DepEcosystem_DEP_ECOSYSTEM_UNSPECIFIED: + // this shouldn't happen + return "" + default: + return "" + } +}