Skip to content

Commit

Permalink
GHES 3.13: Changes in generated code (#29)
Browse files Browse the repository at this point in the history
* New updates to generated code

* New updates to generated code

* New updates to generated code

* New updates to generated code

* New updates to generated code

* New updates to generated code

* New updates to generated code

* New updates to generated code

* New updates to generated code

* New updates to generated code
  • Loading branch information
octokitbot committed Aug 15, 2024
1 parent 4476ffe commit a019be4
Show file tree
Hide file tree
Showing 25 changed files with 2,439 additions and 2,559 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
> [!IMPORTANT]
> This SDK is not yet stable. Breaking changes may occur at any time.
# github.com/octokit/go-sdk-enterprise-server

An "alpha" version of a generated Go SDK for GitHub's Enterprise Server products, generated from [GitHub's OpenAPI spec](https://github.com/github/rest-api-description), built on [Kiota](https://github.com/microsoft/kiota).
Expand All @@ -20,20 +23,21 @@ You may also want:
- [NuGet link](https://www.nuget.org/packages/GitHub.Octokit.SDK)
- For GitHub Enterprise Cloud
- [dotnet-sdk-enterprise-cloud repository](https://github.com/octokit/dotnet-sdk-enterprise-cloud)
- [NuGet link](https://www.nuget.org/packages/GitHub.Octokit.GHEC.SDK/)
- For GitHub Enterprise Server
- [dotnet-sdk-enterprise-server repository](https://github.com/octokit/dotnet-sdk-enterprise-server)
- [NuGet link](https://www.nuget.org/packages?q=GitHub.Octokit.GHES.SDK)
- For our classic non-generated, hand-maintained Octokit.net project
- [Octokit.net repository](https://github.com/octokit/octokit.net)
- For why we're building generative SDKs, see [Why a generated SDK?](#why-a-generated-sdk) below
- [NuGet link](https://www.nuget.org/packages/Octokit/)
- [source-generator](https://github.com/octokit/source-generator) (the repository that creates these generated SDKs)
- Contributions to this repository should take place in source-generator instead, as they'll be distributed here through mechanisms there.
- For why we're building generative SDKs, see [Why a generated SDK?](#why-a-generated-sdk) below

## How do I use it?

See example client instantiations and requests in [example_test.go](pkg/example_test.go) or in the [cmd/ directory](cmd/).

⚠️ **Note**: This SDK is not yet stable. Breaking changes may occur at any time.

### Building and testing

- Build the SDK: `go build ./...`
Expand Down Expand Up @@ -69,6 +73,8 @@ adapter.SetBaseUrl("https://hosted.instance")
client := github.NewApiClient(adapter)
```

Note: The examples in [the cmd/ directory in this repo](cmd/) use an enviromnent variable named `GITHUB_BASE_URL` if you'd prefer to set the base url of your hosted GitHub instance there while using the examples.

### Authentication

This SDK supports [Personal Access Tokens (classic)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic), [fine-grained Personal Access Tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#fine-grained-personal-access-tokens), and [GitHub Apps](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/about-authentication-with-a-github-app) authentication.
Expand Down Expand Up @@ -110,9 +116,7 @@ Authenticating as an App installation can be done using the `WithGitHubAppAuthen

## Why a generated SDK?

We want to...
1. provide 100% coverage of the API in our SDK
2. use this as a building block for future SDK tooling.
Please take a moment and head over to the GitHub blog to read more about the [why's and how's behind our move to Generative SDKs](https://github.blog/news-insights/product-news/our-move-to-generated-sdks/).

## Why Go?

Expand Down
7 changes: 6 additions & 1 deletion cmd/app-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ func main() {
log.Fatalf("error parsing installation ID from string to int64: %v", err)
}

baseURL := os.Getenv("GITHUB_BASE_URL")
if baseURL == "" {
baseURL = "https://api.github.com"
}

client, err := pkg.NewApiClient(
pkg.WithUserAgent("my-user-agent"),
pkg.WithRequestTimeout(5*time.Second),
pkg.WithBaseUrl("https://api.github.com"),
pkg.WithBaseUrl(baseURL),
pkg.WithGitHubAppAuthentication(os.Getenv("PATH_TO_PEM_FILE"), os.Getenv("CLIENT_ID"), installationID),
)

Expand Down
8 changes: 7 additions & 1 deletion cmd/token-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import (
)

func main() {

baseURL := os.Getenv("GITHUB_BASE_URL")
if baseURL == "" {
baseURL = "https://api.github.com"
}

client, err := pkg.NewApiClient(
pkg.WithUserAgent("my-user-agent"),
pkg.WithRequestTimeout(5*time.Second),
pkg.WithBaseUrl("https://api.github.com"),
pkg.WithBaseUrl(baseURL),
pkg.WithTokenAuthentication(os.Getenv("GITHUB_TOKEN")),
)

Expand Down
19 changes: 14 additions & 5 deletions pkg/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ import (
// ExampleApiClient_Octocat constructs an unauthenticated API client
// and makes a simple API request.
func ExampleApiClient_Octocat() {

baseURL := os.Getenv("GITHUB_BASE_URL")
if baseURL == "" {
baseURL = "https://api.github.com"
}

client, err := pkg.NewApiClient(
pkg.WithUserAgent("octokit/go-sdk.example-functions"),
pkg.WithRequestTimeout(5*time.Second),
pkg.WithBaseUrl("https://api.github.com"),
pkg.WithBaseUrl(baseURL),
pkg.WithTokenAuthentication(os.Getenv("GITHUB_TOKEN")),
)

Expand Down Expand Up @@ -91,12 +97,15 @@ func ExampleApiClient_Octocat_withoutConvenienceConstructor() {
// TODO: Rework this test to fit the platform needs of GHES
baseUrl := adapter.GetBaseUrl()

// Note: This SDK should be used against a GitHub Enterprise instance, and the below URL is the public GitHub one. It's here only so that tests pass when running `go test ./...`, as the OpenAPI schema for GHES understandably does not include a baseURL.
// When setting up this package for your own usage, call `adapter.SetBaseUrl` or `pkg.WithBaseUrl` with your own GHES base URL.
if baseUrl == "" {
adapter.SetBaseUrl("https://api.github.com")
// Note: This SDK should be used against a GitHub Enterprise instance, and the below URL is the public GitHub one. It's here only so that tests pass when running `go test ./...`, as the OpenAPI schema for GHES understandably does not include a baseURL.
// When setting up this package for your own usage, call `adapter.SetBaseUrl` or `pkg.WithBaseUrl` with your own GHES base URL.
baseURL := os.Getenv("GITHUB_BASE_URL")
if baseURL == "" {
baseURL = "https://api.github.com"
}
adapter.SetBaseUrl(baseURL)
}

client := github.NewApiClient(adapter)

s := "Salutations"
Expand Down
Loading

0 comments on commit a019be4

Please sign in to comment.