From 343b66f1958b4d5ba49bc5007cb6d469f9a69e2b Mon Sep 17 00:00:00 2001 From: Tomasz Barwicki Date: Mon, 15 Jul 2024 10:30:27 +0200 Subject: [PATCH] chore: revert api checs and getAPISpecFromDir removal --- src/api-collector/main.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/api-collector/main.go b/src/api-collector/main.go index 7643c1c..77a9f82 100644 --- a/src/api-collector/main.go +++ b/src/api-collector/main.go @@ -149,20 +149,14 @@ func getAPISpecsUrlsFromMetadata(ctx context.Context, client *github.Client, own } func downloadAPISpecs(ctx context.Context, client *github.Client, owner string, repo string) []string { - content, err := getAPISpecFromDir(ctx, client, owner, repo) - if err == nil { - specPath, err := saveAPISpec(content, repo) - if err != nil { - log.Fatalf("%v\n", err) - } - return []string{specPath} - } - log.Printf("OpenAPI specs not found in the default location docs/api/openAPI.yaml. Proceeding with .tractusx metadata.") var downloadedSpecs []string specsUrls, err := getAPISpecsUrlsFromMetadata(ctx, client, owner, repo) if err != nil { log.Printf("%v\n", err) } + if len(specsUrls) == 0 { + specsUrls = append(specsUrls, fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/main/%s", owner, repo, API_SPEC_PATH)) + } for _, url := range specsUrls { specContent, err := getAPISpecFromUrl(url) if err != nil { @@ -180,17 +174,6 @@ func downloadAPISpecs(ctx context.Context, client *github.Client, owner string, return downloadedSpecs } -func getAPISpecFromDir(ctx context.Context, client *github.Client, owner string, repo string) ([]byte, error) { - apiContent, _, _, err := client.Repositories.GetContents(ctx, owner, repo, API_SPEC_PATH, &github.RepositoryContentGetOptions{ - Ref: "main", - }) - if err != nil { - return []byte{}, fmt.Errorf("error getting file content: %v", err) - } - content, err := apiContent.GetContent() - return []byte(content), err -} - func getAPISpecFromUrl(url string) ([]byte, error) { resp, err := http.Get(url) if err != nil {