Skip to content

Commit

Permalink
chore: revert api checs and getAPISpecFromDir removal
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszbarwicki committed Jul 15, 2024
1 parent 5cd385d commit 343b66f
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/api-collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 343b66f

Please sign in to comment.