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

Support the release entity for the GitHub provider #4921

Merged
merged 4 commits into from
Dec 17, 2024

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Nov 8, 2024

Summary

Change Type

Mark the type of change your PR introduces:

  • 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

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

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.

@JAORMX JAORMX force-pushed the github-releases branch 2 times, most recently from 843b3f0 to 6f98655 Compare November 29, 2024 10:39
@coveralls
Copy link

coveralls commented Nov 29, 2024

Coverage Status

coverage: 55.003% (-0.4%) from 55.367%
when pulling d1078f4 on JAORMX:github-releases
into d843a45 on mindersec:main.

@JAORMX JAORMX force-pushed the github-releases branch 2 times, most recently from ec7b12f to d0081f5 Compare December 2, 2024 09:56
@JAORMX JAORMX marked this pull request as ready for review December 2, 2024 09:56
@JAORMX JAORMX requested a review from a team as a code owner December 2, 2024 09:56
@JAORMX JAORMX changed the title WIP: Support the release entity for the GitHub provider Support the release entity for the GitHub provider Dec 2, 2024
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

Does this create release entities, or just set us up for doing so in the future?

It looks (right now), like there's still more work before you can write a rule against these release objects -- are they created automatically (like PRs) after registering a repo?

I'm assuming (like PRs), that we will only start looking at releases that are modified after Minder is installed?

v1 "github.com/mindersec/minder/pkg/providers/v1"
)

// Release Properties
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming this will grow over time as we find the other useful properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's right. This applies to all of our entity properties.

}

func getReleaseNameFromParams(owner, repo, tag string) string {
if owner == "" {
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a weird case -- does it actually happen, or could we put in a complaint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll be honest, I cargo-culted this. I'm not sure 😄

Copy link
Member

Choose a reason for hiding this comment

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

Let's make this an error and/or log at warning/error -- I think it's valid input to the GitHub API, but we shouldn't be getting output in this non-normalized form.

@JAORMX
Copy link
Contributor Author

JAORMX commented Dec 9, 2024

Does this create release entities, or just set us up for doing so in the future?

It creates the release entities.

It looks (right now), like there's still more work before you can write a rule against these release objects -- are they created automatically (like PRs) after registering a repo?

I'm assuming (like PRs), that we will only start looking at releases that are modified after Minder is installed?

Like PRs, these are created after registering a repo, as they get created. You could already start writing policies for these; the main issue we have right now is that we don't have an API to get general entities like these.

@JAORMX JAORMX self-assigned this Dec 10, 2024
evankanderson
evankanderson previously approved these changes Dec 11, 2024
}

func getReleaseNameFromParams(owner, repo, tag string) string {
if owner == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this an error and/or log at warning/error -- I think it's valid input to the GitHub API, but we shouldn't be getting output in this non-normalized form.

Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

A few more comments.

It looks like GitHub uses the tag name as the unique identifier for releases, and you can have duplicate "name" (titles, really) for releases, but that my not be universal -- it feels like getReleaseNameFromParams will probably need to vary based on provider.


return map[string]any{
properties.PropertyUpstreamID: properties.NumericalValueToUpstreamID(release.GetID()),
properties.PropertyName: getReleaseNameFromParams(owner, repo, release.GetTagName()),
Copy link
Member

Choose a reason for hiding this comment

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

It looks like GitHub's name here is non-unique, but may still be worth exposing for e.g. filtering with CEL. (Apply / omit evalution only to releases with certain names)

Comment on lines 24 to 27
// ReleasePropertyTag represents the github release tag name.
ReleasePropertyTag = "github/tag"
// ReleasePropertyBranch represents the github release branch
ReleasePropertyBranch = "github/branch"
Copy link
Member

Choose a reason for hiding this comment

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

It was suggested we should have a common-top-level property for these, and for the commit SHA.

evankanderson
evankanderson previously approved these changes Dec 12, 2024
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

One nit on https://github.com/mindersec/minder/pull/4921/files#r1871541959 that I'd like to see us track (because having two different name formats makes everything else harder).

@evankanderson
Copy link
Member

If we merge this, we should make sure to follow up with a PR to restore the -0.4% code coverage drop from adding this new code.

Signed-off-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
@JAORMX JAORMX merged commit c1f1acd into mindersec:main Dec 17, 2024
25 of 26 checks passed
@JAORMX JAORMX deleted the github-releases branch December 17, 2024 09:11
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.

4 participants