-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store properties for artifacts (#4345)
* Add isOrg to the property wrapper signature The wrapper for artifacts will call a different github provider call depending on whether we need to fetch an property for a user artifact or an organizational artifact. Let's extend the wrapper with a bool to allow that. Related: #4339 * Add property fetching for artifacts Adds the properties that will be fetched and stored for artifacts as well as the wrapper fetching it. Fixes: #4339 * Use properties for artifacts in the github webhook Amends the webhook code to refresh artifact properties in the webhook handler and store them for later use. Fixes: #4339
- Loading branch information
Showing
7 changed files
with
316 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -93,7 +93,12 @@ func newPropSvcMock(opts ...func(mck propSvcMock)) propSvcMockBuilder { | |
} | ||
} | ||
|
||
func withSuccessRetrieveAllProperties(entity v1.Entity, retProps *properties.Properties) func(mck propSvcMock) { | ||
func withSuccessRetrieveAllProperties(entity v1.Entity, retPropsMap map[string]any) func(mck propSvcMock) { | ||
retProps, err := properties.NewProperties(retPropsMap) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return func(mock propSvcMock) { | ||
mock.EXPECT(). | ||
RetrieveAllProperties(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), entity). | ||
|
@@ -564,7 +569,6 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { | |
repositoryID := uuid.New() | ||
projectID := uuid.New() | ||
providerID := uuid.New() | ||
artifactID := uuid.New() | ||
visibility := "visibility" | ||
|
||
tests := []struct { | ||
|
@@ -638,6 +642,7 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { | |
payload: &packageEvent{ | ||
Action: github.String("published"), | ||
Package: &pkg{ | ||
ID: github.Int64(123), | ||
Name: github.String("package-name"), | ||
PackageType: github.String("package-type"), | ||
// .package.package_version.container_metadata.tag.name | ||
|
@@ -661,6 +666,23 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { | |
"https://github.com/stacklok/minder", | ||
), | ||
}, | ||
mockPropsBld: newPropSvcMock( | ||
withSuccessRetrieveAllProperties(v1.Entity_ENTITY_ARTIFACTS, map[string]any{ | ||
properties.PropertyUpstreamID: "123", | ||
ghprop.ArtifactPropertyOwner: "login", | ||
ghprop.ArtifactPropertyName: "package-name", | ||
ghprop.ArtifactPropertyCreatedAt: "2024-05-22T07:35:16Z", | ||
}), | ||
withSuccessRetrieveAllProperties(v1.Entity_ENTITY_ARTIFACTS, map[string]any{ | ||
properties.PropertyUpstreamID: "123", | ||
ghprop.ArtifactPropertyOwner: "login", | ||
ghprop.ArtifactPropertyName: "package-name", | ||
ghprop.ArtifactPropertyCreatedAt: "2024-05-22T07:35:16Z", | ||
}), | ||
), | ||
ghMocks: []func(hubMock gf.GitHubMock){ | ||
gf.WithSuccessfulGetEntityName("login/package-name"), | ||
}, | ||
mockRepoBld: newRepoSvcMock( | ||
withSuccessRepoById( | ||
models.EntityInstance{ | ||
|
@@ -687,11 +709,6 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { | |
}, | ||
providerID, | ||
), | ||
df.WithSuccessfulGetArtifactByID( | ||
db.Artifact{ | ||
ID: artifactID, | ||
}, | ||
), | ||
df.WithSuccessfulUpsertArtifact( | ||
db.Artifact{ | ||
ID: uuid.New(), | ||
|
@@ -720,6 +737,23 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { | |
event: "package", | ||
// https://pkg.go.dev/github.com/google/go-github/[email protected]/github#PackageEvent | ||
rawPayload: []byte(rawPackageEventPublished), | ||
mockPropsBld: newPropSvcMock( | ||
withSuccessRetrieveAllProperties(v1.Entity_ENTITY_ARTIFACTS, map[string]any{ | ||
properties.PropertyUpstreamID: "12345", | ||
ghprop.ArtifactPropertyOwner: "stacklok", | ||
ghprop.ArtifactPropertyName: "demo-repo-go-debug", | ||
ghprop.ArtifactPropertyCreatedAt: "2024-05-22T07:35:16Z", | ||
}), | ||
withSuccessRetrieveAllProperties(v1.Entity_ENTITY_ARTIFACTS, map[string]any{ | ||
properties.PropertyUpstreamID: "12345", | ||
ghprop.ArtifactPropertyOwner: "stacklok", | ||
ghprop.ArtifactPropertyName: "demo-repo-go-debug", | ||
ghprop.ArtifactPropertyCreatedAt: "2024-05-22T07:35:16Z", | ||
}), | ||
), | ||
ghMocks: []func(hubMock gf.GitHubMock){ | ||
gf.WithSuccessfulGetEntityName("stacklok/minder"), | ||
}, | ||
mockRepoBld: newRepoSvcMock( | ||
withSuccessRepoById( | ||
models.EntityInstance{ | ||
|
@@ -746,11 +780,6 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { | |
}, | ||
providerID, | ||
), | ||
df.WithSuccessfulGetArtifactByID( | ||
db.Artifact{ | ||
ID: artifactID, | ||
}, | ||
), | ||
df.WithSuccessfulUpsertArtifact( | ||
db.Artifact{ | ||
ID: uuid.New(), | ||
|
This file contains 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.