Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Extend selectors to include provider name and class #4583

Merged
merged 7 commits into from
Oct 1, 2024

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Sep 30, 2024

Summary

We had included provider name and class bundled into an internal proto message already initially when implementing the first pass on selectors.
But we never filled in the structures, so the provider selectors didn't really work.

I took the opportunity to remove one interface that we don't need anymore that was converting the typed protobuf messages to selector entitites.
This is not needed anymore since all entities can be expressed as properties.

This is a large PR, but most of the diff is deletions of obsolete code and adding tests. I will point out in the PR what is what.

Fixes #4564

Change Type

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

unit tests + manual testing

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

//go:generate go run go.uber.org/mock/mockgen -package mock_$GOPACKAGE -destination=./mock/$GOFILE -source=./$GOFILE

// RepoSelectorConverter is an interface for converting a repository to a repository selector
type RepoSelectorConverter interface {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These interfaces are no longer needed because we're operating on properties only and there is nothing provider-specific at this point.

)

func repoToSelectorEntity(t *testing.T, name, class string, repoEntWithProps *models.EntityWithProperties) *internalpb.SelectorEntity {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is removal of the provider interface that is no longer needed.

prWithProperties(map[string]any{
"github": map[string]any{"is_draft": true},
}),
),
selected: false,
},
{
name: "Use an artifact property that is defined and true result",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests are not related to this PR, but the linter was yelling at me that the artifacts options are not used, so I added cases using them

@@ -45,6 +48,8 @@ Let's break down the example above:
- The first selector filters repositories to include only those that are not forks and whose name starts with stacklok. In other words, those that are part of the stacklok organization.
- The second selector filters artifacts to include only those provided by `github-app-stacklok`.
- The third selector filters repositories to include only those with a GPL license and the fourth selector filters repositories to include only those written in Go. These two selectors use the properties map which is provider-specific.
- The fourth selector filters repositories to include only that use Go as the primary language.
- The fifth selector filters repositories to include only those provided by the GitHub provider.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit embarassing but we already had documentation on the provider fields. So the only docs I added are examples.

@jhrozek
Copy link
Contributor Author

jhrozek commented Sep 30, 2024

oops forgot to adjust that unit test apparently. Fixing!

@coveralls
Copy link

coveralls commented Sep 30, 2024

Coverage Status

coverage: 53.087% (+0.1%) from 52.957%
when pulling 5319c56 on jhrozek:selector_provider
into 706d781 on stacklok:main.

JAORMX
JAORMX previously approved these changes Oct 1, 2024
…equestSelectorConverter provider-specific interfaces

Before properties we were filling the SelectorEntity proto message from
bespoke combinations constructed from the entity protobufs like
pb.Repository. Since we now handle entities in a generic manner we don't
need this interface at all.

Related: mindersec#4564
We want to use it in code that we are moving to be provider-agnostic.
Plus, it makes sense, artifacts from any provider will always have a
'type'.

Related: mindersec#4564
… period of time

In the unlikely case anyone still relies on the old property, let's fall
back to it until it disappears.

Related: mindersec#4564
In order to be able to evaluate selectors including the provider, we
need to fill in the provider information.

Related: mindersec#4564
Embarassingly enough we already had some documentation on the provider
selectors before we implemented them, so let's just add an example.

Related: mindersec#4564
@jhrozek
Copy link
Contributor Author

jhrozek commented Oct 1, 2024

I rebased atop the current main. There are no other changes.

@jhrozek jhrozek merged commit ca957cb into mindersec:main Oct 1, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ProfileSelectos's SelectorProvider
3 participants