diff --git a/internal/engine/eval/homoglyphs/application/homoglyphs_service.go b/internal/engine/eval/homoglyphs/application/homoglyphs_service.go index fb2588ba50..c1801b6ed7 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" 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.(*pbinternal.PrContents) + prContents, ok := res.Object.(*models.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 0dbe99a70f..6421cc8fc0 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" 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 *pbinternal.Dependency + Dependency *models.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: alternative.Dependency.Ecosystem.AsString(), + Ecosystem: string(alternative.Dependency.Ecosystem), PackageName: alternative.Dependency.Name, TrustyURL: fmt.Sprintf( "%s%s/%s", constants.TrustyHttpURL, - strings.ToLower(alternative.Dependency.Ecosystem.AsString()), + strings.ToLower(string(alternative.Dependency.Ecosystem)), url.PathEscape(alternative.trustyReply.PackageName), ), Score: score, @@ -326,11 +326,11 @@ func (sph *summaryPrHandler) generateSummary() (string, error) { altPackageData := templateAlternative{ templatePackageData: templatePackageData{ - Ecosystem: alternative.Dependency.Ecosystem.AsString(), + Ecosystem: string(alternative.Dependency.Ecosystem), PackageName: altData.PackageName, TrustyURL: fmt.Sprintf( "%s%s/%s", constants.TrustyHttpURL, - strings.ToLower(alternative.Dependency.Ecosystem.AsString()), + strings.ToLower(string(alternative.Dependency.Ecosystem)), url.PathEscape(altData.PackageName), ), Score: altData.Score, diff --git a/internal/engine/eval/trusty/config.go b/internal/engine/eval/trusty/config.go index 7128aa18c5..49c4409bb8 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" ) var ( @@ -110,8 +110,8 @@ func parseConfig(ruleCfg map[string]any) (*config, error) { return &conf, nil } -func (c *config) getEcosystemConfig(ecosystem pbinternal.DepEcosystem) *ecosystemConfig { - sEco := ecosystem.AsString() +func (c *config) getEcosystemConfig(ecosystem models.DependencyEcosystem) *ecosystemConfig { + sEco := string(ecosystem) if sEco == "" { return nil } diff --git a/internal/engine/eval/trusty/trusty.go b/internal/engine/eval/trusty/trusty.go index 5f31caa274..7683b16d47 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" 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 *pbinternal.PrDependencies_ContextualDependency, + logger *zerolog.Logger, ruleConfig *config, dep models.ContextualDependency, ) *ecosystemConfig { ecoConfig := ruleConfig.getEcosystemConfig(dep.Dep.Ecosystem) if ecoConfig == nil { logger.Info(). Str("dependency", dep.Dep.Name). - Str("ecosystem", dep.Dep.Ecosystem.AsString()). + Str("ecosystem", string(dep.Dep.Ecosystem)). Msgf("no config for ecosystem, skipping") return nil } return ecoConfig } -// readPullRequestDependencies returns the dependencies found in theingestion results -func readPullRequestDependencies(res *engif.Result) (*pbinternal.PrDependencies, error) { - prdeps, ok := res.Object.(*pbinternal.PrDependencies) +// readPullRequestDependencies returns the dependencies found in the ingestion results +func readPullRequestDependencies(res *engif.Result) (*models.PRDependencies, error) { + prdeps, ok := res.Object.(*models.PRDependencies) if !ok { return nil, fmt.Errorf("object type incompatible with the Trusty evaluator") } @@ -224,13 +224,17 @@ func buildEvalResult(prSummary *summaryPrHandler) error { } func getDependencyScore( - ctx context.Context, trustyClient *trusty.Trusty, dep *pbinternal.PrDependencies_ContextualDependency, + ctx context.Context, trustyClient *trusty.Trusty, dep *models.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: trustytypes.Ecosystem(dep.Dep.Ecosystem), + Ecosystem: trustyEcosystem, }) if err != nil { return nil, fmt.Errorf("failed to send request: %w", err) @@ -242,7 +246,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 *pbinternal.PrDependencies_ContextualDependency, + prSummary *summaryPrHandler, dep models.ContextualDependency, ) { // Check all the policy violations reasons := []RuleViolationReason{} @@ -311,7 +315,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, @@ -344,3 +348,16 @@ 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 e4095d2dd5..0518121e76 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" - pbinternal "github.com/stacklok/minder/internal/proto" - mock_github "github.com/stacklok/minder/internal/providers/github/mock" + "github.com/stacklok/minder/internal/engine/models" + mockgithub "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: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Dependency: &models.Dependency{ + Ecosystem: models.PyPIDependency, Name: "requests", Version: "0.0.1", }, trustyReply: &trustytypes.Reply{ PackageName: "requests", - PackageType: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI.AsString(), + PackageType: string(models.PyPIDependency), Summary: trustytypes.ScoreSummary{ Score: &sg, }, @@ -76,14 +76,14 @@ func TestBuildEvalResult(t *testing.T) { {"low-scored-package", &summaryPrHandler{ trackedAlternatives: []dependencyAlternatives{ { - Dependency: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Dependency: &models.Dependency{ + Ecosystem: models.PyPIDependency, Name: "requests", Version: "0.0.1", }, trustyReply: &trustytypes.Reply{ PackageName: "requests", - PackageType: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI.AsString(), + PackageType: string(models.PyPIDependency), Summary: trustytypes.ScoreSummary{ Score: &sg, }, @@ -94,28 +94,28 @@ func TestBuildEvalResult(t *testing.T) { {"malicious-and-low-score", &summaryPrHandler{ trackedAlternatives: []dependencyAlternatives{ { - Dependency: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Dependency: &models.Dependency{ + Ecosystem: models.PyPIDependency, Name: "python-oauth", Version: "0.0.1", }, trustyReply: &trustytypes.Reply{ PackageName: "requests", - PackageType: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI.AsString(), + PackageType: string(models.PyPIDependency), Summary: trustytypes.ScoreSummary{ Score: &sg, }, }, }, { - Dependency: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Dependency: &models.Dependency{ + Ecosystem: models.PyPIDependency, Name: "requestts", Version: "0.0.1", }, trustyReply: &trustytypes.Reply{ PackageName: "requests", - PackageType: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI.AsString(), + PackageType: string(models.PyPIDependency), 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: &pbinternal.PrDependencies{}}, mustErr: false}, + {name: "normal", sut: &engif.Result{Object: &models.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 := mock_github.NewMockGitHub(nil) + ghProvider := mockgithub.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 := &pbinternal.PrDependencies_ContextualDependency{ - Dep: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + dep := models.ContextualDependency{ + Dep: models.Dependency{ + Ecosystem: models.NPMDependency, Name: "test", Version: "v0.0.1", }, @@ -398,7 +398,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "no-description", sut: dependencyAlternatives{ - Dependency: &pbinternal.Dependency{}, + Dependency: &models.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{}, @@ -408,7 +408,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "normal-response", sut: dependencyAlternatives{ - Dependency: &pbinternal.Dependency{}, + Dependency: &models.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{ @@ -431,7 +431,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "normal-response", sut: dependencyAlternatives{ - Dependency: &pbinternal.Dependency{}, + Dependency: &models.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{ @@ -454,7 +454,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "typosquatting-low", sut: dependencyAlternatives{ - Dependency: &pbinternal.Dependency{}, + Dependency: &models.Dependency{}, Reasons: []RuleViolationReason{}, trustyReply: &trustytypes.Reply{ Summary: trustytypes.ScoreSummary{ @@ -469,7 +469,7 @@ func TestBuildScoreMatrix(t *testing.T) { { name: "typosquatting-high", sut: dependencyAlternatives{ - Dependency: &pbinternal.Dependency{}, + Dependency: &models.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 f6cbe1a53f..3542dd8c7a 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" 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 *pbinternal.PrDependencies_ContextualDependency, + dep models.ContextualDependency, vulnResp *VulnerabilityResponse, patch patchLocatorFormatter, ) error diff --git a/internal/engine/eval/vulncheck/config.go b/internal/engine/eval/vulncheck/config.go index 0dc510a236..5b4ac4a3ab 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" ) type vulnDbType string @@ -106,8 +106,8 @@ func parseConfig(ruleCfg map[string]any) (*config, error) { return &conf, nil } -func (c *config) getEcosystemConfig(ecosystem pbinternal.DepEcosystem) *ecosystemConfig { - sEco := ecosystem.AsString() +func (c *config) getEcosystemConfig(ecosystem models.DependencyEcosystem) *ecosystemConfig { + sEco := string(ecosystem) if sEco == "" { return nil } diff --git a/internal/engine/eval/vulncheck/pkgdb.go b/internal/engine/eval/vulncheck/pkgdb.go index ec34c99df7..17792d48eb 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" "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 *pbinternal.Dependency) string + IndentedString(indent int, oldDepLine string, oldDep models.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 *pbinternal.Dependency, patched string, latest bool) (patchLocatorFormatter, error) - NoPatchAvailableFormatter(dep *pbinternal.Dependency) patchLocatorFormatter - PkgRegistryErrorFormatter(dep *pbinternal.Dependency, registryErr error) patchLocatorFormatter + 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 } type repoCache struct { @@ -112,7 +112,7 @@ type packageJson struct { } `json:"dist"` } -func (pj *packageJson) IndentedString(indent int, oldDepLine string, _ *pbinternal.Dependency) string { +func (pj *packageJson) IndentedString(indent int, oldDepLine string, _ models.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 *pbinternal.Dependency) string { +func (p *PyPiReply) IndentedString(_ int, oldDepLine string, oldDep models.Dependency) string { return strings.Replace(oldDepLine, oldDep.Version, p.Info.Version, 1) } @@ -212,7 +212,11 @@ func (p *PyPiReply) GetFormatterMeta() formatterMeta { return p.formatterMeta } -func (p *pypiRepository) SendRecvRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, +func (p *pypiRepository) SendRecvRequest( + ctx context.Context, + dep models.Dependency, + patched string, + latest bool, ) (patchLocatorFormatter, error) { req, err := p.newRequest(ctx, dep, patched, latest) if err != nil { @@ -240,7 +244,7 @@ func (p *pypiRepository) SendRecvRequest(ctx context.Context, dep *pbinternal.De return &pkgJson, nil } -func (_ *pypiRepository) NoPatchAvailableFormatter(dep *pbinternal.Dependency) patchLocatorFormatter { +func (_ *pypiRepository) NoPatchAvailableFormatter(dep models.Dependency) patchLocatorFormatter { return &PyPiReply{ Info: struct { Name string `json:"name"` @@ -249,7 +253,7 @@ func (_ *pypiRepository) NoPatchAvailableFormatter(dep *pbinternal.Dependency) p } } -func (_ *pypiRepository) PkgRegistryErrorFormatter(dep *pbinternal.Dependency, registryErr error) patchLocatorFormatter { +func (_ *pypiRepository) PkgRegistryErrorFormatter(dep models.Dependency, registryErr error) patchLocatorFormatter { return &PyPiReply{ formatterMeta: formatterMeta{ pkgRegistryLookupError: registryErr, @@ -269,7 +273,10 @@ func newPyPIRepository(endpoint string) *pypiRepository { } func (p *pypiRepository) newRequest( - ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, + ctx context.Context, + dep models.Dependency, + patched string, + latest bool, ) (*http.Request, error) { var u *url.URL var err error @@ -308,7 +315,10 @@ func newNpmRepository(endpoint string) *npmRepository { var _ RepoQuerier = (*npmRepository)(nil) func (n *npmRepository) newRequest( - ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, + ctx context.Context, + dep models.Dependency, + patched string, + latest bool, ) (*http.Request, error) { var version string if latest { @@ -329,7 +339,11 @@ func (n *npmRepository) newRequest( return req, nil } -func (n *npmRepository) SendRecvRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, +func (n *npmRepository) SendRecvRequest( + ctx context.Context, + dep models.Dependency, + patched string, + latest bool, ) (patchLocatorFormatter, error) { req, err := n.newRequest(ctx, dep, patched, latest) if err != nil { @@ -357,14 +371,14 @@ func (n *npmRepository) SendRecvRequest(ctx context.Context, dep *pbinternal.Dep return &pkgJson, nil } -func (_ *npmRepository) NoPatchAvailableFormatter(dep *pbinternal.Dependency) patchLocatorFormatter { +func (_ *npmRepository) NoPatchAvailableFormatter(dep models.Dependency) patchLocatorFormatter { return &packageJson{ Name: dep.Name, Version: "", } } -func (_ *npmRepository) PkgRegistryErrorFormatter(dep *pbinternal.Dependency, registryErr error) patchLocatorFormatter { +func (_ *npmRepository) PkgRegistryErrorFormatter(dep models.Dependency, registryErr error) patchLocatorFormatter { return &packageJson{ formatterMeta: formatterMeta{ pkgRegistryLookupError: registryErr, @@ -386,7 +400,7 @@ type goModPackage struct { DependencyHash string `json:"dependency_hash"` } -func (gmp *goModPackage) IndentedString(indent int, _ string, _ *pbinternal.Dependency) string { +func (gmp *goModPackage) IndentedString(indent int, _ string, _ models.Dependency) string { return fmt.Sprintf("%s%s %s", strings.Repeat(" ", indent), gmp.Name, gmp.Version) } @@ -428,7 +442,11 @@ func newGoProxySumRepository(proxyEndpoint, sumEndpoint string) *goProxyReposito // check that npmRepository implements RepoQuerier var _ RepoQuerier = (*goProxyRepository)(nil) -func (r *goProxyRepository) goProxyRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, +func (r *goProxyRepository) goProxyRequest( + ctx context.Context, + dep models.Dependency, + patched string, + latest bool, ) (*http.Request, error) { var u *url.URL var err error @@ -509,7 +527,11 @@ func parseGoSumReply(goPkg *goModPackage, reply io.Reader) error { return nil } -func (r *goProxyRepository) SendRecvRequest(ctx context.Context, dep *pbinternal.Dependency, patched string, latest bool, +func (r *goProxyRepository) SendRecvRequest( + ctx context.Context, + dep models.Dependency, + patched string, + latest bool, ) (patchLocatorFormatter, error) { proxyReq, err := r.goProxyRequest(ctx, dep, patched, latest) if err != nil { @@ -565,14 +587,14 @@ func (r *goProxyRepository) SendRecvRequest(ctx context.Context, dep *pbinternal return goPackage, nil } -func (_ *goProxyRepository) NoPatchAvailableFormatter(dep *pbinternal.Dependency) patchLocatorFormatter { +func (_ *goProxyRepository) NoPatchAvailableFormatter(dep models.Dependency) patchLocatorFormatter { return &goModPackage{ Name: dep.Name, oldVersion: dep.Version, } } -func (_ *goProxyRepository) PkgRegistryErrorFormatter(dep *pbinternal.Dependency, registryErr error) patchLocatorFormatter { +func (_ *goProxyRepository) PkgRegistryErrorFormatter(dep models.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 c942c609e7..c7579f9f80 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" ) func TestNpmPkgDb(t *testing.T) { @@ -146,7 +146,7 @@ func TestNpmPkgDb(t *testing.T) { repo := newNpmRepository(server.URL) - dep := &pbinternal.Dependency{ + dep := models.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, "", nil), reply.IndentedString(0, "", nil), "expected reply to match mock data") + require.Equal(t, tt.expectReply.IndentedString(0, "", models.Dependency{}), reply.IndentedString(0, "", models.Dependency{}), "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 := &pbinternal.Dependency{ + dep := models.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", - &pbinternal.Dependency{ + models.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 := &pbinternal.Dependency{ + dep := models.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, "", nil), reply.IndentedString(0, "", nil), "expected reply to match mock data") + require.Equal(t, tt.expectReply.IndentedString(0, "", models.Dependency{}), reply.IndentedString(0, "", models.Dependency{}), "expected reply to match mock data") } }) } diff --git a/internal/engine/eval/vulncheck/report.go b/internal/engine/eval/vulncheck/report.go index d2bc22ad3a..16c5d3b244 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: dep.Dependency.Ecosystem.AsString(), + DependencyEcosystem: string(dep.Dependency.Ecosystem), 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 ee910d092b..889be70758 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" 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 *pbinternal.PrDependencies_ContextualDependency, + dep models.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,7 +88,8 @@ 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 == pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM && i+1 < len(lines) { + + if dep.Dep.Ecosystem == models.NPMDependency && i+1 < len(lines) { line = strings.Join([]string{line, lines[i+1], dep.Dep.Version}, "\n") loc.lineToChange = i + 2 } else { @@ -188,7 +189,7 @@ func newReviewPrHandler( func (ra *reviewPrHandler) trackVulnerableDep( ctx context.Context, - dep *pbinternal.PrDependencies_ContextualDependency, + dep models.ContextualDependency, vulnResp *VulnerabilityResponse, patch patchLocatorFormatter, ) error { @@ -235,7 +236,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(), }) @@ -510,19 +511,19 @@ type summaryPrHandler struct { } type dependencyVulnerabilities struct { - Dependency *pbinternal.Dependency + Dependency *models.Dependency Vulnerabilities []Vulnerability PatchVersion string } func (sph *summaryPrHandler) trackVulnerableDep( _ context.Context, - dep *pbinternal.PrDependencies_ContextualDependency, + dep models.ContextualDependency, vulnResp *VulnerabilityResponse, patch patchLocatorFormatter, ) error { sph.trackedDeps = append(sph.trackedDeps, dependencyVulnerabilities{ - Dependency: dep.Dep, + Dependency: &dep.Dep, Vulnerabilities: vulnResp.Vulns, PatchVersion: patch.GetPatchedVersion(), }) @@ -571,7 +572,7 @@ type profileOnlyPrHandler struct{} func (profileOnlyPrHandler) trackVulnerableDep( _ context.Context, - _ *pbinternal.PrDependencies_ContextualDependency, + _ models.ContextualDependency, _ *VulnerabilityResponse, _ patchLocatorFormatter, ) error { diff --git a/internal/engine/eval/vulncheck/review_test.go b/internal/engine/eval/vulncheck/review_test.go index 490d56b6e5..1cc76092c6 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" 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 := &pbinternal.PrDependencies_ContextualDependency{ - Dep: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + dep := models.ContextualDependency{ + Dep: models.Dependency{ + Ecosystem: models.NPMDependency, Name: "mongodb", Version: "0.5.0", }, - File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ + File: models.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 := &pbinternal.PrDependencies_ContextualDependency{ - Dep: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + dep := models.ContextualDependency{ + Dep: models.Dependency{ + Ecosystem: models.NPMDependency, Name: "mongodb", Version: "0.5.0", }, - File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ + File: models.FilePatch{ Name: "package-lock.json", - PatchUrl: server.URL, + PatchURL: server.URL, }, } @@ -316,15 +316,15 @@ func TestReviewPrHandlerVulnerabilitiesWithNoPatchVersion(t *testing.T) { })) defer server.Close() - dep := &pbinternal.PrDependencies_ContextualDependency{ - Dep: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + dep := models.ContextualDependency{ + Dep: models.Dependency{ + Ecosystem: models.NPMDependency, Name: "mongodb", Version: "0.5.0", }, - File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ + File: models.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 := &pbinternal.PrDependencies_ContextualDependency{ - Dep: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + dep := models.ContextualDependency{ + Dep: models.Dependency{ + Ecosystem: models.NPMDependency, Name: "mongodb", Version: "0.5.0", }, - File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ + File: models.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.GetDep(), + Dependency: &dep.Dep, Vulnerabilities: vulnResp.Vulns, PatchVersion: "", }) @@ -573,15 +573,15 @@ func TestCommitStatusPrHandlerWithVulnerabilities(t *testing.T) { })) defer server.Close() - dep := &pbinternal.PrDependencies_ContextualDependency{ - Dep: &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + dep := models.ContextualDependency{ + Dep: models.Dependency{ + Ecosystem: models.NPMDependency, Name: "mongodb", Version: "0.5.0", }, - File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ + File: models.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.GetDep(), + Dependency: &dep.Dep, Vulnerabilities: vulnResp.Vulns, PatchVersion: "0.6.0", }) diff --git a/internal/engine/eval/vulncheck/vulncheck.go b/internal/engine/eval/vulncheck/vulncheck.go index bcb8f2f183..65d01c32bb 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" 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.(*pbinternal.PrDependencies) + prdeps, ok := res.Object.(*models.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 == nil || dep.Dep.Version == "" { + if 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 *pbinternal.Dependency, - ecosystem pbinternal.DepEcosystem, + dep models.Dependency, + ecosystem models.DependencyEcosystem, ) (*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 *pbinternal.PrDependencies_ContextualDependency, + dep models.ContextualDependency, cfg *config, cache *repoCache, prHandler prStatusHandler, diff --git a/internal/engine/eval/vulncheck/vulndb.go b/internal/engine/eval/vulncheck/vulndb.go index 1297c78d4e..c7130bab80 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" ) // 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 *pbinternal.Dependency, eco pbinternal.DepEcosystem) (*http.Request, error) - SendRecvRequest(r *http.Request, dep *pbinternal.Dependency) (*VulnerabilityResponse, error) + NewQuery(ctx context.Context, dep models.Dependency, eco models.DependencyEcosystem) (*http.Request, error) + SendRecvRequest(r *http.Request, dep models.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 *pbinternal.Dependency) *VulnerabilityResponse { +func toVulnerabilityResponse(osvResp *OSVResponse, dep models.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 *pbinternal.Dependency, eco pbinternal.DepEcosystem) (*http.Request, error) { +func (o *osvdb) NewQuery(ctx context.Context, dep models.Dependency, eco models.DependencyEcosystem) (*http.Request, error) { reqBody := map[string]interface{}{ "version": dep.Version, "package": map[string]string{ "name": dep.Name, - "ecosystem": eco.AsString(), + "ecosystem": string(eco), }, } @@ -195,7 +195,7 @@ func (o *osvdb) NewQuery(ctx context.Context, dep *pbinternal.Dependency, eco pb return req, nil } -func (_ *osvdb) SendRecvRequest(r *http.Request, dep *pbinternal.Dependency) (*VulnerabilityResponse, error) { +func (_ *osvdb) SendRecvRequest(r *http.Request, dep models.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 81592afa70..49afbdd867 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" ) 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 := &pbinternal.Dependency{ + dep := models.Dependency{ Name: tt.depName, Version: tt.depVersion, } diff --git a/internal/engine/ingester/diff/diff.go b/internal/engine/ingester/diff/diff.go index 064cc50400..d1304840d4 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" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" 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([]*pbinternal.PrDependencies_ContextualDependency, 0) + allDiffs := make([]models.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: &pbinternal.PrDependencies{ - Pr: pr, + Object: &models.PRDependencies{ + PR: pr, Deps: allDiffs, }, }, nil case pb.DiffTypeFull: - allDiffs := make([]*pbinternal.PrContents_File, 0) + allDiffs := make([]models.PRFile, 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: &pbinternal.PrContents{ - Pr: pr, + Object: models.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, -) ([]*pbinternal.PrDependencies_ContextualDependency, error) { +) ([]models.ContextualDependency, error) { parser := di.getParserForFile(filename, logger) if parser == nil { return nil, nil @@ -173,14 +173,13 @@ func (di *Diff) ingestFileForDepDiff( return nil, fmt.Errorf("error parsing file %s: %w", filename, err) } - batchCtxDeps := make([]*pbinternal.PrDependencies_ContextualDependency, 0, len(depBatch)) - for i := range depBatch { - dep := depBatch[i] - batchCtxDeps = append(batchCtxDeps, &pbinternal.PrDependencies_ContextualDependency{ + batchCtxDeps := make([]models.ContextualDependency, 0, len(depBatch)) + for _, dep := range depBatch { + batchCtxDeps = append(batchCtxDeps, models.ContextualDependency{ Dep: dep, - File: &pbinternal.PrDependencies_ContextualDependency_FilePatch{ + File: models.FilePatch{ Name: filename, - PatchUrl: patchUrl, + PatchURL: patchUrl, }, }) } @@ -192,8 +191,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) (*pbinternal.PrContents_File, error) { - var result []*pbinternal.PrContents_File_Line +func ingestFileForFullDiff(filename, patch, patchUrl string) (*models.PRFile, error) { + var result []models.PRFileLine scanner := bufio.NewScanner(strings.NewReader(patch)) regex := regexp.MustCompile(`@@ -\d+,\d+ \+(\d+),\d+ @@`) @@ -209,7 +208,7 @@ func ingestFileForFullDiff(filename, patch, patchUrl string) (*pbinternal.PrCont return nil, fmt.Errorf("error parsing line number from the hunk header: %w", err) } } else if strings.HasPrefix(line, "+") { - result = append(result, &pbinternal.PrContents_File_Line{ + result = append(result, models.PRFileLine{ Content: line[1:], // see the use of strconv.ParseInt above: this is a safe downcast LineNumber: int32(currentLineNumber), @@ -225,9 +224,9 @@ func ingestFileForFullDiff(filename, patch, patchUrl string) (*pbinternal.PrCont return nil, fmt.Errorf("error reading patch: %w", err) } - return &pbinternal.PrContents_File{ + return &models.PRFile{ 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 ff6cae2bb4..9768157b85 100644 --- a/internal/engine/ingester/diff/parse.go +++ b/internal/engine/ingester/diff/parse.go @@ -22,7 +22,7 @@ import ( "slices" "strings" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" "github.com/stacklok/minder/internal/util" ) @@ -31,7 +31,7 @@ var ( dependencyNameRegex = regexp.MustCompile(`\s*"([^"]+)"\s*:\s*{\s*`) ) -type ecosystemParser func(string) ([]*pbinternal.Dependency, error) +type ecosystemParser func(string) ([]models.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) ([]*pbinternal.Dependency, error) { - var deps []*pbinternal.Dependency +func requirementsParse(patch string) ([]models.Dependency, error) { + var deps []models.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 []*pbinternal.Dependency, pkgName, version string) []*pbinternal.Dependency { - dep := &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, +func pyReqAddPkgName(depList []models.Dependency, pkgName, version string) []models.Dependency { + dep := models.Dependency{ + Ecosystem: models.PyPIDependency, Name: pyNormalizeName(pkgName), Version: version, } @@ -137,8 +137,8 @@ func pyNormalizeName(pkgName string) string { return strings.ToLower(result) } -func goParse(patch string) ([]*pbinternal.Dependency, error) { - var deps []*pbinternal.Dependency +func goParse(patch string) ([]models.Dependency, error) { + var deps []models.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) ([]*pbinternal.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 *pbinternal.Dependency) bool { + if dep == nil || slices.ContainsFunc(deps, func(n models.Dependency) bool { if n.Name == dep.Name && n.Version == dep.Version { return true } @@ -157,7 +157,7 @@ func goParse(patch string) ([]*pbinternal.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) ([]*pbinternal.Dependency, error) { return deps, nil } -func extractGoDepFromPatchLine(line string) *pbinternal.Dependency { +func extractGoDepFromPatchLine(line string) *models.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) *pbinternal.Dependency { return nil } - dep := &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_GO, + dep := &models.Dependency{ + Ecosystem: models.GoDependency, } if fields[0] == "require" && fields[1] != "(" && len(fields) >= 3 { dep.Name = fields[1] @@ -204,10 +204,10 @@ func extractGoDepFromPatchLine(line string) *pbinternal.Dependency { return nil } -func npmParse(patch string) ([]*pbinternal.Dependency, error) { +func npmParse(patch string) ([]models.Dependency, error) { lines := strings.Split(patch, "\n") - var deps []*pbinternal.Dependency + var deps []models.Dependency for i, line := range lines { // Check if the line contains a version @@ -218,8 +218,8 @@ func npmParse(patch string) ([]*pbinternal.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, &pbinternal.Dependency{ - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + deps = append(deps, models.Dependency{ + Ecosystem: models.NPMDependency, Name: name, Version: version, }) diff --git a/internal/engine/ingester/diff/parse_test.go b/internal/engine/ingester/diff/parse_test.go index 151e73183b..4690334a0b 100644 --- a/internal/engine/ingester/diff/parse_test.go +++ b/internal/engine/ingester/diff/parse_test.go @@ -19,9 +19,8 @@ import ( "testing" "github.com/stretchr/testify/assert" - "google.golang.org/protobuf/proto" - pbinternal "github.com/stacklok/minder/internal/proto" + "github.com/stacklok/minder/internal/engine/models" ) func TestGoParse(t *testing.T) { @@ -31,7 +30,7 @@ func TestGoParse(t *testing.T) { description string content string expectedCount int - expectedDependencies []*pbinternal.Dependency + expectedDependencies []models.Dependency }{ { description: "Single addition", @@ -41,9 +40,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: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_GO, + Ecosystem: models.GoDependency, Name: "github.com/openfga/openfga", Version: "v1.4.3", }, @@ -68,9 +67,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: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_GO, + Ecosystem: models.GoDependency, Name: "go.opentelemetry.io/proto/otlp", Version: "v1.0.0", }, @@ -86,7 +85,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: []*pbinternal.Dependency{}, + expectedDependencies: []models.Dependency{}, }, { description: "Replace", @@ -97,9 +96,9 @@ func TestGoParse(t *testing.T) { + +replace github.com/opencontainers/runc => github.com/stacklok/runc v1.1.12`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_GO, + Ecosystem: models.GoDependency, Name: "github.com/stacklok/runc", Version: "v1.1.12", }, @@ -114,7 +113,7 @@ func TestGoParse(t *testing.T) { + +replace github.com/opencontainers/runc => `, expectedCount: 0, - expectedDependencies: []*pbinternal.Dependency{}, + expectedDependencies: []models.Dependency{}, }, { description: "Bad Require", @@ -125,7 +124,7 @@ func TestGoParse(t *testing.T) { + +require github.com/opencontainers/runc`, expectedCount: 0, - expectedDependencies: []*pbinternal.Dependency{}, + expectedDependencies: []models.Dependency{}, }, } for _, tt := range tests { @@ -140,7 +139,7 @@ func TestGoParse(t *testing.T) { assert.Equal(t, tt.expectedCount, len(got), "mismatched dependency count") for i, expectedDep := range tt.expectedDependencies { - if !proto.Equal(expectedDep, got[i]) { + if expectedDep != got[i] { t.Errorf("mismatch at index %d: expected %v, got %v", i, expectedDep, got[i]) } } @@ -155,7 +154,7 @@ func TestPyPiParse(t *testing.T) { description string content string expectedCount int - expectedDependencies []*pbinternal.Dependency + expectedDependencies []models.Dependency }{ { description: "Single addition, exact version", @@ -163,9 +162,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests==2.19.0`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.19.0", }, @@ -178,9 +177,9 @@ func TestPyPiParse(t *testing.T) { +# this version has a CVE +requests==2.19.0`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.19.0", }, @@ -193,9 +192,9 @@ func TestPyPiParse(t *testing.T) { + +requests==2.19.0`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.19.0", }, @@ -207,9 +206,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests>=2.19.0`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.19.0", }, @@ -221,9 +220,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests>=2.19.0`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.19.0", }, @@ -235,9 +234,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests==2.19.0 # this version has a CVE`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.19.0", }, @@ -249,9 +248,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests==2.*`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2", }, @@ -263,9 +262,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "", }, @@ -277,9 +276,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests<=2.19.0`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.19.0", }, @@ -291,9 +290,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests<3,>=2.0`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.0", }, @@ -305,9 +304,9 @@ func TestPyPiParse(t *testing.T) { Flask +requests>=2.0,<3`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.0", }, @@ -321,19 +320,20 @@ func TestPyPiParse(t *testing.T) { +pandas<0.25.0,>=0.24.0 +numpy==1.16.0`, expectedCount: 3, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "requests", Version: "2.0", }, { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + + Ecosystem: models.PyPIDependency, Name: "pandas", Version: "0.24.0", }, { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, Name: "numpy", Version: "1.16.0", }, @@ -346,7 +346,7 @@ func TestPyPiParse(t *testing.T) { # just a comment `, expectedCount: 0, - expectedDependencies: []*pbinternal.Dependency{}, + expectedDependencies: []models.Dependency{}, }, { description: "Single addition, uppercase", @@ -354,9 +354,9 @@ func TestPyPiParse(t *testing.T) { Flask + Django==3.2.21`, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_PYPI, + Ecosystem: models.PyPIDependency, 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 !proto.Equal(expectedDep, got[i]) { + if 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 []*pbinternal.Dependency + expectedDependencies []models.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: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + Ecosystem: models.NPMDependency, Name: "chalk", Version: "5.3.0", }, @@ -443,9 +443,9 @@ func TestNpmParse(t *testing.T) { } `, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + Ecosystem: models.NPMDependency, Name: "lodash", Version: "4.17.21", }, @@ -477,9 +477,9 @@ func TestNpmParse(t *testing.T) { +} `, expectedCount: 1, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + Ecosystem: models.NPMDependency, Name: "lodash", Version: "4.17.21", }, @@ -517,14 +517,14 @@ func TestNpmParse(t *testing.T) { } `, expectedCount: 2, - expectedDependencies: []*pbinternal.Dependency{ + expectedDependencies: []models.Dependency{ { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + Ecosystem: models.NPMDependency, Name: "@types/node", Version: "20.9.0", }, { - Ecosystem: pbinternal.DepEcosystem_DEP_ECOSYSTEM_NPM, + Ecosystem: models.NPMDependency, 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 !proto.Equal(expectedDep, got[i]) { + if 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 new file mode 100644 index 0000000000..e04d6c74ab --- /dev/null +++ b/internal/engine/models/models.go @@ -0,0 +1,74 @@ +// 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 b2fb96739b..f1de3721a4 100644 --- a/internal/proto/internal.pb.go +++ b/internal/proto/internal.pb.go @@ -24,11 +24,9 @@ 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 ( @@ -38,566 +36,23 @@ 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, 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 + 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, } -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_goTypes = []any{} var file_internal_proto_depIdxs = []int32{ - 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 + 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 } func init() { file_internal_proto_init() } @@ -605,106 +60,18 @@ 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: 1, - NumMessages: 7, + NumEnums: 0, + NumMessages: 0, 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 771858e7a9..1903430a31 100644 --- a/internal/proto/internal.proto +++ b/internal/proto/internal.proto @@ -18,53 +18,10 @@ syntax = "proto3"; // buf:lint:ignore PACKAGE_VERSION_SUFFIX package internal; -import "minder/v1/minder.proto"; - option go_package = "github.com/stacklok/minder/internal/proto"; -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 +/* + * 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 diff --git a/internal/proto/pkg_ecosystems.go b/internal/proto/pkg_ecosystems.go deleted file mode 100644 index fe4f00b4e5..0000000000 --- a/internal/proto/pkg_ecosystems.go +++ /dev/null @@ -1,32 +0,0 @@ -// 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 "" - } -}