-
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.
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
2 changed files
with
104 additions
and
91 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(), | ||
|