Skip to content

Commit

Permalink
downloads the appropriate file for the given platform and version com…
Browse files Browse the repository at this point in the history
…bination
  • Loading branch information
nickfloyd committed Jun 12, 2024
1 parent 78b0097 commit da4955b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapitools.json
nuget.exe
output.txt
schemas/downloaded.json
schemas/*.json

# GO Related
generated/go/*
Expand Down
32 changes: 12 additions & 20 deletions schemas/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,48 +61,40 @@ func realMain() error {
return fmt.Errorf("version may not be specified for given platform: %s", platform)
}

/*
switch platform {
case "ghes":
break
case "ghec":
break
case "dotcom":
break
default:
return fmt.Errorf("invalid platform provided. platform must be one of dotcom, ghes, ghec. given platform: %s", platform)
}*/

fileName := ""
fileExt := ".json"
fileName := "api.github.com"

if platform == "ghes" {
fileName = "schemas/" + platform + "-" + version + ".json"
fileName = platform + "-" + version
} else if platform == "ghec" {
fileName = "schemas/" + platform + ".json"
} else {
fileName = "schemas/api.github.com.json"
fileName = platform
}

out, err := os.Create(fileName)
out, err := os.Create("schemas/" + fileName + fileExt)
if err != nil {
return err
}

defer out.Close()

logMsg := "Downloading latest schema from descriptions directory"
url := "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json"
url := "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/" + fileName + "/" + fileName + fileExt
if useSchemaNext {
logMsg = "Downloading latest schema from descriptions-next directory"
url = "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.json"
url = "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/" + fileName + "/" + fileName + fileExt
}

log.Printf(logMsg)
resp, err := http.Get(url)

if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf("Received 404 Not Found for url: %s", url)
}
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-dotnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
go run schemas/main.go --schema-next=false

# Execute generation
kiota generate -l csharp --ll trace -o $(pwd)/stage/dotnet-sdk/src/GitHub -c GitHubClient -n GitHub -d schemas/downloaded.json --ebc
kiota generate -l csharp --ll trace -o $(pwd)/stage/dotnet-sdk/src/GitHub -c GitHubClient -n GitHub -d schemas/api.github.com.json --ebc

# Build and run post-processor
go build -o $(pwd)/post-processors/csharp/post-processor post-processors/csharp/main.go
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
set -ex

go run schemas/main.go --schema-next=false
kiota generate -l go --ll trace -o $(pwd)/stage/go-sdk/pkg/github -n github.com/octokit/go-sdk/pkg/github -d schemas/downloaded.json --ebc
kiota generate -l go --ll trace -o $(pwd)/stage/go-sdk/pkg/github -n github.com/octokit/go-sdk/pkg/github -d schemas/api.github.com.json --ebc
go build -o post-processors/go/post-processor post-processors/go/main.go
cd $(pwd)/stage/go-sdk
$(pwd)/../../post-processors/go/post-processor $(pwd)
Expand Down

0 comments on commit da4955b

Please sign in to comment.