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

Store repo license again #4190

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/providers/github/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -70,6 +72,7 @@ var repoPropertyDefinitions = []propertyOrigin{
RepoPropertyDeployURL,
RepoPropertyCloneURL,
RepoPropertyDefaultBranch,
RepoPropertyLicense,
},
wrapper: getRepoWrapper,
},
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal/repositories/github/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -423,6 +429,7 @@ func (r *repositoryService) persistRepository(
String: pbRepo.DefaultBranch,
Valid: true,
},
License: License,
})
if err != nil {
return pbRepo, err
Expand Down Expand Up @@ -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
Expand Down