Skip to content

Commit

Permalink
GHES 3.13: Changes in generated code (#35)
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
  • Loading branch information
octokitbot authored Aug 15, 2024
1 parent bf8b0b1 commit b67bfc4
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 209 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
> [!IMPORTANT]
> This SDK is not yet stable. Breaking changes may occur at any time.
# Octokit: .NET SDK

[![Build and test .NET SDK](https://github.com/octokit/dotnet-sdk/actions/workflows/build.yml/badge.svg)](https://github.com/octokit/dotnet-sdk/actions/workflows/build.yml) [![CodeQL](https://github.com/octokit/dotnet-sdk/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/octokit/dotnet-sdk/actions/workflows/github-code-scanning/codeql) [![Publish Release to NuGet](https://github.com/octokit/dotnet-sdk/actions/workflows/publish.yml/badge.svg)](https://github.com/octokit/dotnet-sdk/actions/workflows/publish.yml)
[![Build and test .NET SDK](https://github.com/octokit/dotnet-sdk-enterprise-server/actions/workflows/build.yml/badge.svg)](https://github.com/octokit/dotnet-sdk-enterprise-server/actions/workflows/build.yml) [![CodeQL](https://github.com/octokit/dotnet-sdk-enterprise-server/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/octokit/dotnet-sdk-enterprise-server/actions/workflows/github-code-scanning/codeql) [![Publish Release to NuGet](https://github.com/octokit/dotnet-sdk-enterprise-server/actions/workflows/publish.yml/badge.svg)](https://github.com/octokit/dotnet-sdk-enterprise-server/actions/workflows/publish.yml)

An "alpha" version of a generated .NET SDK in C# 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). View on [NuGet](https://www.nuget.org/packages/GitHub.Octokit.SDK/).

Expand All @@ -12,11 +15,13 @@ 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/)
- Go
- For the standard GitHub.com product
- [go-sdk repository](https://github.com/octokit/go-sdk)
Expand All @@ -29,6 +34,7 @@ You may also want:
- [pkg.go.dev docs link](https://pkg.go.dev/github.com/octokit/go-sdk-enterprise-server)
- [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?

Expand Down Expand Up @@ -70,9 +76,6 @@ foreach (var pullRequest in pullRequests)
}
```

> [!IMPORTANT]
> This SDK is not yet stable. Breaking changes may occur at any time.
### 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,17 +113,15 @@ Note that the SDK **does not yet** support authenticating as the App itself and

## Why a generated SDK?

We want to...
1. provide 100% coverage of the API in our SDK
1. 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 .NET?

We have a substantial userbase that uses .NET and we wanted them to get access to our generated SDK as early as possible.

## How can I report on my experience or issues with the SDK?

Please use this project's [issues](https://github.com/octokit/dotnet-sdk/issues)!
Please use this project's [issues](https://github.com/octokit/dotnet-sdk-enterprise-server/issues)!

## Source organization

Expand All @@ -138,7 +139,7 @@ Currently this project is fairly simple (we hope it can stay that way). All of
- Generate test report: `dotnet reportgenerator -targetdir:$(pwd)/test/coverage/Report/ -reports:$(pwd)/test/coverage/coverage.opencover.xml`
- Note that this requires installing [ReportGenerator](https://github.com/danielpalme/ReportGenerator), whose installation instructions can be found [here](https://github.com/danielpalme/ReportGenerator?tab=readme-ov-file#install-the-package-matching-your-platform-and-needs)
- We're using the `dotnet-reportgenerator-globaltool`, so follow that set of installation instructions
- The test report can be viewed by opening the generated report file (logged to CLI output, something like `/path/to/your/repo/dotnet-sdk/test/coverage/Report/index.html`) in a browser
- The test report can be viewed by opening the generated report file (logged to CLI output, something like `/path/to/your/repo/dotnet-sdk-enterprise-server/test/coverage/Report/index.html`) in a browser

## More details on this SDK and repo

Expand Down
6 changes: 5 additions & 1 deletion cli/Authentication/AppInstallationToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ public class AppInstallationToken

public static async Task Run()
{
// The GitHub Enterprise Server URL
var baseUrl = Environment.GetEnvironmentVariable("GITHUB_BASE_URL") ?? "https://api.github.com";


var githubAppTokenProvider = new GitHubAppTokenProvider();
var rsa = RSA.Create();
rsa.ImportFromPem(PRIVATE_KEY_PATH);

var aiAccessTokenProvider = new AppInstallationTokenProvider(CLIENT_ID, rsa, INSTALLATION_ID, githubAppTokenProvider);
var aiAdapter = RequestAdapter.Create(new AppInstallationAuthProvider(aiAccessTokenProvider));
var aiAdapter = RequestAdapter.Create(new AppInstallationAuthProvider(aiAccessTokenProvider), baseUrl);
var aiGitHubClient = new GitHubClient(aiAdapter);

try
Expand Down
4 changes: 3 additions & 1 deletion cli/Authentication/PersonalAccessToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static async Task Run()
{
// Personal Access Token authentication
var tokenProvider = new TokenProvider(Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? "");
var adapter = RequestAdapter.Create(new TokenAuthProvider(tokenProvider), "https://api.github.com");
// The GitHub Enterprise Server URL
var baseUrl = Environment.GetEnvironmentVariable("GITHUB_BASE_URL") ?? "https://api.github.com";
var adapter = RequestAdapter.Create(new TokenAuthProvider(tokenProvider), baseUrl);
var gitHubClient = new GitHubClient(adapter);

try
Expand Down
20 changes: 0 additions & 20 deletions src/GitHub/Models/ApiOverview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,8 @@ namespace GitHub.Models {
/// </summary>
public class ApiOverview : IAdditionalDataHolder, IParsable
{
/// <summary>The actions_macos property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public List<string>? ActionsMacos { get; set; }
#nullable restore
#else
public List<string> ActionsMacos { get; set; }
#endif
/// <summary>Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.</summary>
public IDictionary<string, object> AdditionalData { get; set; }
/// <summary>The dependabot property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public List<string>? Dependabot { get; set; }
#nullable restore
#else
public List<string> Dependabot { get; set; }
#endif
/// <summary>The domains property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
Expand Down Expand Up @@ -79,8 +63,6 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{
return new Dictionary<string, Action<IParseNode>>
{
{"actions_macos", n => { ActionsMacos = n.GetCollectionOfPrimitiveValues<string>()?.ToList(); } },
{"dependabot", n => { Dependabot = n.GetCollectionOfPrimitiveValues<string>()?.ToList(); } },
{"domains", n => { Domains = n.GetObjectValue<ApiOverview_domains>(ApiOverview_domains.CreateFromDiscriminatorValue); } },
{"installed_version", n => { InstalledVersion = n.GetStringValue(); } },
{"packages", n => { Packages = n.GetCollectionOfPrimitiveValues<string>()?.ToList(); } },
Expand All @@ -94,8 +76,6 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
public virtual void Serialize(ISerializationWriter writer)
{
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteCollectionOfPrimitiveValues<string>("actions_macos", ActionsMacos);
writer.WriteCollectionOfPrimitiveValues<string>("dependabot", Dependabot);
writer.WriteObjectValue<ApiOverview_domains>("domains", Domains);
writer.WriteStringValue("installed_version", InstalledVersion);
writer.WriteCollectionOfPrimitiveValues<string>("packages", Packages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace GitHub.Models {
/// <summary>
/// Custom property defined on an organization
/// </summary>
public class OrgCustomProperty : IAdditionalDataHolder, IParsable
public class CustomProperty : IAdditionalDataHolder, IParsable
{
/// <summary>Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.</summary>
public IDictionary<string, object> AdditionalData { get; set; }
Expand All @@ -23,10 +23,10 @@ public class OrgCustomProperty : IAdditionalDataHolder, IParsable
/// <summary>Default value of the property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public OrgCustomProperty_default_value? DefaultValue { get; set; }
public CustomProperty_default_value? DefaultValue { get; set; }
#nullable restore
#else
public OrgCustomProperty_default_value DefaultValue { get; set; }
public CustomProperty_default_value DefaultValue { get; set; }
#endif
/// <summary>Short description of the property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
Expand All @@ -46,26 +46,34 @@ public class OrgCustomProperty : IAdditionalDataHolder, IParsable
#endif
/// <summary>Whether the property is required.</summary>
public bool? Required { get; set; }
/// <summary>The URL that can be used to fetch, update, or delete info about this property via the API.</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? Url { get; set; }
#nullable restore
#else
public string Url { get; set; }
#endif
/// <summary>Who can edit the values of the property</summary>
public OrgCustomProperty_values_editable_by? ValuesEditableBy { get; set; }
public CustomProperty_values_editable_by? ValuesEditableBy { get; set; }
/// <summary>The type of the value for the property</summary>
public OrgCustomProperty_value_type? ValueType { get; set; }
public CustomProperty_value_type? ValueType { get; set; }
/// <summary>
/// Instantiates a new <see cref="OrgCustomProperty"/> and sets the default values.
/// Instantiates a new <see cref="CustomProperty"/> and sets the default values.
/// </summary>
public OrgCustomProperty()
public CustomProperty()
{
AdditionalData = new Dictionary<string, object>();
}
/// <summary>
/// Creates a new instance of the appropriate class based on discriminator value
/// </summary>
/// <returns>A <see cref="OrgCustomProperty"/></returns>
/// <returns>A <see cref="CustomProperty"/></returns>
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
public static OrgCustomProperty CreateFromDiscriminatorValue(IParseNode parseNode)
public static CustomProperty CreateFromDiscriminatorValue(IParseNode parseNode)
{
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
return new OrgCustomProperty();
return new CustomProperty();
}
/// <summary>
/// The deserialization information for the current model
Expand All @@ -76,12 +84,13 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
return new Dictionary<string, Action<IParseNode>>
{
{"allowed_values", n => { AllowedValues = n.GetCollectionOfPrimitiveValues<string>()?.ToList(); } },
{"default_value", n => { DefaultValue = n.GetObjectValue<OrgCustomProperty_default_value>(OrgCustomProperty_default_value.CreateFromDiscriminatorValue); } },
{"default_value", n => { DefaultValue = n.GetObjectValue<CustomProperty_default_value>(CustomProperty_default_value.CreateFromDiscriminatorValue); } },
{"description", n => { Description = n.GetStringValue(); } },
{"property_name", n => { PropertyName = n.GetStringValue(); } },
{"required", n => { Required = n.GetBoolValue(); } },
{"value_type", n => { ValueType = n.GetEnumValue<OrgCustomProperty_value_type>(); } },
{"values_editable_by", n => { ValuesEditableBy = n.GetEnumValue<OrgCustomProperty_values_editable_by>(); } },
{"url", n => { Url = n.GetStringValue(); } },
{"value_type", n => { ValueType = n.GetEnumValue<CustomProperty_value_type>(); } },
{"values_editable_by", n => { ValuesEditableBy = n.GetEnumValue<CustomProperty_values_editable_by>(); } },
};
}
/// <summary>
Expand All @@ -92,18 +101,19 @@ public virtual void Serialize(ISerializationWriter writer)
{
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteCollectionOfPrimitiveValues<string>("allowed_values", AllowedValues);
writer.WriteObjectValue<OrgCustomProperty_default_value>("default_value", DefaultValue);
writer.WriteObjectValue<CustomProperty_default_value>("default_value", DefaultValue);
writer.WriteStringValue("description", Description);
writer.WriteStringValue("property_name", PropertyName);
writer.WriteBoolValue("required", Required);
writer.WriteEnumValue<OrgCustomProperty_values_editable_by>("values_editable_by", ValuesEditableBy);
writer.WriteEnumValue<OrgCustomProperty_value_type>("value_type", ValueType);
writer.WriteStringValue("url", Url);
writer.WriteEnumValue<CustomProperty_values_editable_by>("values_editable_by", ValuesEditableBy);
writer.WriteEnumValue<CustomProperty_value_type>("value_type", ValueType);
writer.WriteAdditionalData(AdditionalData);
}
/// <summary>
/// Composed type wrapper for classes <see cref="string"/>
/// </summary>
public class OrgCustomProperty_default_value : IComposedTypeWrapper, IParsable
public class CustomProperty_default_value : IComposedTypeWrapper, IParsable
{
/// <summary>Composed type representation for type <see cref="string"/></summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
Expand All @@ -116,13 +126,13 @@ public class OrgCustomProperty_default_value : IComposedTypeWrapper, IParsable
/// <summary>
/// Creates a new instance of the appropriate class based on discriminator value
/// </summary>
/// <returns>A <see cref="OrgCustomProperty_default_value"/></returns>
/// <returns>A <see cref="CustomProperty_default_value"/></returns>
/// <param name="parseNode">The parse node to use to read the discriminator value and create the object</param>
public static OrgCustomProperty_default_value CreateFromDiscriminatorValue(IParseNode parseNode)
public static CustomProperty_default_value CreateFromDiscriminatorValue(IParseNode parseNode)
{
_ = parseNode ?? throw new ArgumentNullException(nameof(parseNode));
var mappingValue = parseNode.GetChildNode("")?.GetStringValue();
var result = new OrgCustomProperty_default_value();
var result = new CustomProperty_default_value();
if(parseNode.GetStringValue() is string stringValue)
{
result.String = stringValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
namespace GitHub.Models {
/// <summary>The type of the value for the property</summary>
public enum OrgCustomProperty_value_type
public enum CustomProperty_value_type
{
[EnumMember(Value = "string")]
#pragma warning disable CS1591
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
namespace GitHub.Models {
/// <summary>Who can edit the values of the property</summary>
public enum OrgCustomProperty_values_editable_by
public enum CustomProperty_values_editable_by
{
[EnumMember(Value = "org_actors")]
#pragma warning disable CS1591
Expand Down
Loading

0 comments on commit b67bfc4

Please sign in to comment.