From 417c7e10762ce340550cecff7ed1bbdf311ae214 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Sun, 18 Aug 2024 21:34:08 +0200 Subject: [PATCH] Store repo license again We used to store repo license since 5a78abc38d3608b9e77d11042aaaf6eea04f6763 but then stopping saving the attribute in d68e8e697dcd36f8c1fd9ec9d8a894903c4f2827. We still have ruletypes that rely on that attribute, so let's just re-add it. Side-note: Saving generic attributes will get way easier once we implement properties fully. --- internal/providers/github/properties.go | 4 ++++ internal/repositories/github/service.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/internal/providers/github/properties.go b/internal/providers/github/properties.go index 2f7bee92aa..9380637bed 100644 --- a/internal/providers/github/properties.go +++ b/internal/providers/github/properties.go @@ -38,6 +38,8 @@ const ( RepoPropertyCloneURL = "github/clone_url" // RepoPropertyDefaultBranch represents the github repository default branch RepoPropertyDefaultBranch = "github/default_branch" + // RepoPropertyLicense represents the github repository license + RepoPropertyLicense = "github/license" ) type propertyWrapper func(ctx context.Context, ghCli *GitHub, name string) (map[string]any, error) @@ -70,6 +72,7 @@ var repoPropertyDefinitions = []propertyOrigin{ RepoPropertyDeployURL, RepoPropertyCloneURL, RepoPropertyDefaultBranch, + RepoPropertyLicense, }, wrapper: getRepoWrapper, }, @@ -117,6 +120,7 @@ func getRepoWrapper(ctx context.Context, ghCli *GitHub, name string) (map[string RepoPropertyDeployURL: repo.GetDeploymentsURL(), RepoPropertyCloneURL: repo.GetCloneURL(), RepoPropertyDefaultBranch: repo.GetDefaultBranch(), + RepoPropertyLicense: repo.GetLicense().GetSPDXID(), } return repoProps, nil diff --git a/internal/repositories/github/service.go b/internal/repositories/github/service.go index 8870d08ce3..f7f2d01477 100644 --- a/internal/repositories/github/service.go +++ b/internal/repositories/github/service.go @@ -402,6 +402,12 @@ func (r *repositoryService) persistRepository( return nil, fmt.Errorf("error creating repository object: %w", err) } + License := sql.NullString{} + if pbRepo.License != "" { + License.String = pbRepo.License + License.Valid = true + } + // update the database dbRepo, err := t.CreateRepository(ctx, db.CreateRepositoryParams{ Provider: provider.Name, @@ -423,6 +429,7 @@ func (r *repositoryService) persistRepository( String: pbRepo.DefaultBranch, Valid: true, }, + License: License, }) if err != nil { return pbRepo, err @@ -493,6 +500,7 @@ func pbRepoFromProperties( IsPrivate: isPrivate, IsFork: isFork, DefaultBranch: repoProperties.GetProperty(ghprov.RepoPropertyDefaultBranch).GetString(), + License: repoProperties.GetProperty(ghprov.RepoPropertyLicense).GetString(), } return pbRepo, nil