Skip to content

feat: Create SourceRepository interface for Go#4731

Merged
michaelkedar merged 7 commits into
google:masterfrom
michaelkedar:📥❌🐍
Feb 6, 2026

Hidden character warning

The head ref may contain hidden characters: "\ud83d\udce5\u274c\ud83d\udc0d"
Merged

feat: Create SourceRepository interface for Go#4731
michaelkedar merged 7 commits into
google:masterfrom
michaelkedar:📥❌🐍

Conversation

@michaelkedar

Copy link
Copy Markdown
Member

This is part of the Go rewrite of the Importer, but I thought I'd split up this PR to get some opinions on the database structure.

Adding a SourceRepository abstraction, and the bindings for the Datastore object to allow the source repos to be read from Datastore.
There's an abstraction layer to separate out the business logic (internal/models) from the Datastore API (internal/database/datastore) which should make migrating off of Datastore easier in the future.
I've moved & aliased the existing datastore models in osv/models into internal/database/datastore, and will eventually try abstract away the datastore usage from the exporter & relations computation.

@michaelkedar

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a SourceRepository abstraction and its Datastore implementation, which is a great step in refactoring the importer. The separation between the domain models in internal/models and the Datastore-specific models in internal/database/datastore is well-executed and will improve maintainability. The new tests are also comprehensive.

I have a few suggestions to improve the code further, mainly regarding a potential data loss bug with RepoUsername, a naming convention, and improving the clarity of test data. Overall, this is a solid contribution.

Comment on lines +14 to +57
func (sr *SourceRepository) toModel() *models.SourceRepository {
msr := &models.SourceRepository{
Name: sr.Name,
Type: sr.Type,
Strictness: sr.StrictValidation,
IgnorePatterns: sr.IgnorePatterns,
Extension: sr.Extension,
KeyPath: sr.KeyPath,
GitAnalysis: &models.GitAnalysisConfig{
IgnoreGit: sr.IgnoreGit,
DetectCherrypicks: sr.DetectCherrypicks,
ConsiderAllBranches: sr.ConsiderAllBranches,
VersionsFromRepo: sr.VersionsFromRepo,
},
Link: sr.Link,
HumanLink: sr.HumanLink,
IDPrefixes: sr.DBPrefix,
}
switch sr.Type {
case models.SourceRepositoryTypeGit:
msr.Git = &models.SourceRepoGit{
URL: sr.RepoURL,
Branch: sr.RepoBranch,
Path: sr.DirectoryPath,
LastSyncedCommit: sr.LastSyncedHash,
}
case models.SourceRepositoryTypeBucket:
msr.Bucket = &models.SourceRepoBucket{
Bucket: sr.Bucket,
Path: sr.DirectoryPath,
LastUpdated: sr.LastUpdateDate,
IgnoreLastImportTime: sr.IgnoreLastImportTime,
IgnoreDeletionThreshold: sr.IgnoreDeletionThreshold,
}
case models.SourceRepositoryTypeREST:
msr.REST = &models.SourceRepoREST{
URL: sr.RestApiUrl,
LastUpdated: sr.LastUpdateDate,
IgnoreLastImportTime: sr.IgnoreLastImportTime,
IgnoreDeletionThreshold: sr.IgnoreDeletionThreshold,
}
}
return msr
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The RepoUsername field from the datastore model is not being mapped to or from the domain model. This seems to be an omission as the Python model and datastore model both have this field for SSH authentication.

To fix this, you should:

  1. Add a Username field to models.SourceRepoGit in internal/models/source_repository.go.
  2. Update toModel() here to map sr.RepoUsername to msr.Git.Username.
  3. Update newSourceRepositoryFromModel() to map r.Git.Username to sr.RepoUsername.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm intentionally removing Username, since its purpose seems to be for SSH writing, and we no longer want the importer (or worker) to be able to modify repos.
Repos should be public anyway, so there's no need to have a username / key.

Comment thread go/internal/database/datastore/models.go Outdated
Comment thread go/internal/database/datastore/internal/validate/validate.go
Comment thread go/internal/database/datastore/internal/validate/validate.go
Comment thread go/internal/database/datastore/source_repository.go Outdated
Comment thread go/internal/database/datastore/internal/validate/validate.go

@another-rex another-rex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do quite like the abstracted models.

Comment thread go/internal/database/datastore/source_repository.go Outdated
@michaelkedar michaelkedar merged commit 13c2f47 into google:master Feb 6, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants