Skip to content

Commit 68d5792

Browse files
authored
refactor(internal/repometadata): make FromAPI private (#4794)
FromAPI is made private and renamed to fromAPI within the repometadata package. All external callers are updated to use the more comprehensive FromLibrary function which handles API lookup internally. This refactoring ensures that API discovery and validation are handled consistently by the repometadata package. Tests for the Java post-processor are updated to provide the required language configuration for the new FromLibrary calls. Fixes #4428
1 parent 1598047 commit 68d5792

4 files changed

Lines changed: 10 additions & 14 deletions

File tree

internal/librarian/java/postprocess.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,10 @@ func postProcessLibrary(cfg *config.Config, library *config.Library, outDir, goo
237237
// information from the primary service configuration and library-level overrides.
238238
func deriveRepoMetadata(cfg *config.Config, library *config.Library, googleapisDir string) (*repoMetadata, error) {
239239
serviceconfig.SortAPIs(library.APIs)
240-
api, err := serviceconfig.Find(googleapisDir, library.APIs[0].Path, config.LanguageJava)
240+
sharedMetadata, err := repometadata.FromLibrary(cfg, library, googleapisDir)
241241
if err != nil {
242-
return nil, fmt.Errorf("failed to find primary API for path %s: %w", library.APIs[0].Path, err)
242+
return nil, err
243243
}
244-
if api == nil {
245-
return nil, fmt.Errorf("failed to find primary API for path %s: not found", library.APIs[0].Path)
246-
}
247-
sharedMetadata := repometadata.FromAPI(cfg, api, library)
248244

249245
metadata := &repoMetadata{
250246
APIShortname: sharedMetadata.APIShortname,
@@ -316,7 +312,7 @@ func deriveRepoMetadata(cfg *config.Config, library *config.Library, googleapisD
316312
metadata.ClientDocumentation = fmt.Sprintf("https://cloud.google.com/java/docs/reference/%s/latest/overview", artifactID)
317313
}
318314
// transport
319-
apiCfg, err := serviceconfig.Find(googleapisDir, api.Path, config.LanguageJava)
315+
apiCfg, err := serviceconfig.Find(googleapisDir, library.APIs[0].Path, config.LanguageJava)
320316
if err != nil {
321317
return nil, fmt.Errorf("failed to find api config: %w", err)
322318
}

internal/librarian/java/postprocess_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ func TestDeriveRepoMetadata_Overrides(t *testing.T) {
314314
googleapis := "internal/testdata/googleapis"
315315

316316
cfg := &config.Config{
317-
Repo: "googleapis/google-cloud-java",
317+
Language: config.LanguageJava,
318+
Repo: "googleapis/google-cloud-java",
318319
}
319320
library := &config.Library{
320321
Name: "secretmanager",

internal/librarian/nodejs/generate.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,10 @@ func writeRepoMetadata(cfg *config.Config, library *config.Library, googleapisDi
343343
if len(library.APIs) == 0 {
344344
return nil
345345
}
346-
api, err := serviceconfig.Find(googleapisDir, library.APIs[0].Path, cfg.Language)
346+
metadata, err := repometadata.FromLibrary(cfg, library, googleapisDir)
347347
if err != nil {
348-
return fmt.Errorf("failed to find API metadata: %w", err)
348+
return err
349349
}
350-
metadata := repometadata.FromAPI(cfg, api, library)
351350
metadata.DistributionName = DerivePackageName(library)
352351
metadata.DefaultVersion = filepath.Base(library.APIs[0].Path)
353352
metadata.LibraryType = repometadata.GAPICAutoLibraryType

internal/repometadata/repometadata.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ func FromLibrary(cfg *config.Config, library *config.Library, googleapisDir stri
121121
if err != nil {
122122
return nil, fmt.Errorf("failed to find API for path %s: %w", firstAPIPath, err)
123123
}
124-
return FromAPI(cfg, api, library), nil
124+
return fromAPI(cfg, api, library), nil
125125
}
126126

127-
// FromAPI generates the .repo-metadata.json file from a serviceconfig.API and library information.
128-
func FromAPI(config *config.Config, api *serviceconfig.API, library *config.Library) *RepoMetadata {
127+
// fromAPI generates the .repo-metadata.json file from a serviceconfig.API and library information.
128+
func fromAPI(config *config.Config, api *serviceconfig.API, library *config.Library) *RepoMetadata {
129129
apiDescription := api.Description
130130
if library.DescriptionOverride != "" {
131131
apiDescription = library.DescriptionOverride

0 commit comments

Comments
 (0)