-
Notifications
You must be signed in to change notification settings - Fork 82
Fix issue of filtering sig,att,sbom image tags when searching SHA and Tag/SemVer, enable regex filtering with SHA searching too, for additional exclusions #349
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package errors | ||
|
|
||
| import ( | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestIsNoVersionFound(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| err error | ||
| expectRes bool | ||
| }{ | ||
| { | ||
| name: "error is of type ErrorVersionNotFound", | ||
| err: NewVersionErrorNotFound("version not found"), | ||
| expectRes: true, | ||
| }, | ||
| { | ||
| name: "error is not of type ErrorVersionNotFound", | ||
| err: errors.New("some other error"), | ||
| expectRes: false, | ||
| }, | ||
| { | ||
| name: "error is nil", | ||
| err: nil, | ||
| expectRes: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| result := IsNoVersionFound(test.err) | ||
| assert.Equal(t, result, test.expectRes) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package version | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/jetstack/version-checker/pkg/api" | ||
| "github.com/jetstack/version-checker/pkg/version/semver" | ||
| ) | ||
|
|
||
| func isSBOMAttestationOrSig(tag string) bool { | ||
| return strings.HasSuffix(tag, ".att") || | ||
| strings.HasSuffix(tag, ".sig") || | ||
| strings.HasSuffix(tag, ".sbom") | ||
| } | ||
|
|
||
| // Used when filtering Tags as a SemVer | ||
| func shouldSkipTag(opts *api.Options, v *semver.SemVer) bool { | ||
| // Handle Regex matching | ||
| if opts.RegexMatcher != nil { | ||
| return !opts.RegexMatcher.MatchString(v.String()) | ||
| } | ||
|
|
||
| // Handle metadata and version pinning | ||
| return (!opts.UseMetaData && v.HasMetaData()) || | ||
| (opts.PinMajor != nil && *opts.PinMajor != v.Major()) || | ||
| (opts.PinMinor != nil && *opts.PinMinor != v.Minor()) || | ||
| (opts.PinPatch != nil && *opts.PinPatch != v.Patch()) | ||
| } | ||
|
|
||
| // Used when filtering SHA Tags | ||
| func shouldSkipSHA(opts *api.Options, sha string) bool { | ||
| // Filter out Sbom and Attestation/Signatures | ||
| if isSBOMAttestationOrSig(sha) { | ||
| return true | ||
| } | ||
|
|
||
| // Allow for Regex Filtering | ||
| if opts != nil && opts.RegexMatcher != nil { | ||
| return !opts.RegexMatcher.MatchString(sha) | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| // isBetterSemVer compares two semantic version numbers and | ||
| // associated image tags to determine if one is considered better than the other. | ||
| func isBetterSemVer(_ *api.Options, latestV, v *semver.SemVer, latestImageTag, currentImageTag *api.ImageTag) bool { | ||
| // No latest version set yet | ||
| if latestV == nil { | ||
| return true | ||
| } | ||
|
|
||
| // If the current version is greater than the latest | ||
| if latestV.LessThan(v) { | ||
| return true | ||
| } | ||
|
|
||
| // If the versions are equal, prefer the one with a later timestamp | ||
| if latestV.Equal(v) && currentImageTag.Timestamp.After(latestImageTag.Timestamp) { | ||
| return true | ||
| } | ||
|
|
||
| return false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.