Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHES 3.10: Changes in generated code #29

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
push:
branches:
- 3.10

jobs:
build:
runs-on: ubuntu-latest
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ To install the package, you can use either of the following options:
- Type `Install-Package GitHub.Octokit.SDK` into the Package Manager Console, or
- Type `dotnet add ./path/to/myproject.csproj package GitHub.Octokit.SDK` in a terminal (replace `./path/to/myproject.csproj` by the path to the _*.csproj_ file you want to add the dependency)


### Initializing

Given that the GHES platform is a self hosted instance when using this SDK you'll need to initialize it with your host and protocol:

```csharp
var tokenProvider = new TokenProvider(Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? "");
var adapter = RequestAdapter.Create(new TokenAuthProvider(tokenProvider), "https://hosted.instance");
var gitHubClient = new GitHubClient(adapter);
```

### Make your first request

```csharp
Expand All @@ -48,8 +59,8 @@ using GitHub.Octokit.Client;
using GitHub.Octokit.Client.Authentication;

var token = Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? "";
var request = RequestAdapter.Create(new TokenAuthProvider(new TokenProvider(token)));
var gitHubClient = new GitHubClient(request);
var adapter = RequestAdapter.Create(new TokenAuthProvider(tokenProvider), "https://hosted.instance");
var gitHubClient = new GitHubClient(adapter);

var pullRequests = await gitHubClient.Repos["octokit"]["octokit.net"].Pulls.GetAsync();

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

try
Expand Down
21 changes: 21 additions & 0 deletions src/Client/RequestAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ public static HttpClientRequestAdapter Create(IAuthenticationProvider authentica
clientFactory,
null);

return gitHubRequestAdapter;
}
public static HttpClientRequestAdapter Create(IAuthenticationProvider authenticationProvider, string baseUrl, HttpClient? clientFactory = null)
{
if (string.IsNullOrEmpty(baseUrl))
{
throw new ArgumentException("Base URL cannot be null or empty.", nameof(baseUrl));
}

clientFactory ??= ClientFactory.Create();

var gitHubRequestAdapter = new HttpClientRequestAdapter(
authenticationProvider,
null, // Node Parser
null, // Serializer
clientFactory,
null)
{
BaseUrl = baseUrl
};

return gitHubRequestAdapter;
}
}
6 changes: 3 additions & 3 deletions src/GitHub/Events/EventsRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public EventsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : bas
{
}
/// <summary>
/// We delay the public events feed by five minutes, which means the most recent event returned by the public events API actually occurred at least five minutes ago.
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// API method documentation <see href="https://docs.github.com/[email protected]/rest/activity/events#list-public-events" />
/// </summary>
/// <returns>A List&lt;Event&gt;</returns>
Expand All @@ -58,7 +58,7 @@ public async Task<List<Event>> GetAsync(Action<RequestConfiguration<EventsReques
return collectionResult?.ToList();
}
/// <summary>
/// We delay the public events feed by five minutes, which means the most recent event returned by the public events API actually occurred at least five minutes ago.
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// </summary>
/// <returns>A <see cref="RequestInformation"/></returns>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
Expand Down Expand Up @@ -86,7 +86,7 @@ public EventsRequestBuilder WithUrl(string rawUrl)
return new EventsRequestBuilder(rawUrl, RequestAdapter);
}
/// <summary>
/// We delay the public events feed by five minutes, which means the most recent event returned by the public events API actually occurred at least five minutes ago.
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// </summary>
public class EventsRequestBuilderGetQueryParameters
{
Expand Down
6 changes: 3 additions & 3 deletions src/GitHub/Models/PullRequestReview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class PullRequestReview : IAdditionalDataHolder, IParsable
public string HtmlUrl { get; set; }
#endif
/// <summary>Unique identifier of the review</summary>
public int? Id { get; set; }
public long? Id { get; set; }
/// <summary>The _links property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
Expand Down Expand Up @@ -129,7 +129,7 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{"body_text", n => { BodyText = n.GetStringValue(); } },
{"commit_id", n => { CommitId = n.GetStringValue(); } },
{"html_url", n => { HtmlUrl = n.GetStringValue(); } },
{"id", n => { Id = n.GetIntValue(); } },
{"id", n => { Id = n.GetLongValue(); } },
{"_links", n => { Links = n.GetObjectValue<PullRequestReview__links>(PullRequestReview__links.CreateFromDiscriminatorValue); } },
{"node_id", n => { NodeId = n.GetStringValue(); } },
{"pull_request_url", n => { PullRequestUrl = n.GetStringValue(); } },
Expand All @@ -151,7 +151,7 @@ public virtual void Serialize(ISerializationWriter writer)
writer.WriteStringValue("body_text", BodyText);
writer.WriteStringValue("commit_id", CommitId);
writer.WriteStringValue("html_url", HtmlUrl);
writer.WriteIntValue("id", Id);
writer.WriteLongValue("id", Id);
writer.WriteObjectValue<PullRequestReview__links>("_links", Links);
writer.WriteStringValue("node_id", NodeId);
writer.WriteStringValue("pull_request_url", PullRequestUrl);
Expand Down
54 changes: 14 additions & 40 deletions src/GitHub/Models/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,23 @@ public class Users : 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; }
/// <summary>The fragment property</summary>
/// <summary>Whether this email address is the primary address.</summary>
public bool? Primary { get; set; }
/// <summary>The type of email address.</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? Fragment { get; set; }
public string? Type { get; set; }
#nullable restore
#else
public string Fragment { get; set; }
public string Type { get; set; }
#endif
/// <summary>The matches property</summary>
/// <summary>The email address.</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public List<Users_matches>? Matches { get; set; }
public string? Value { get; set; }
#nullable restore
#else
public List<Users_matches> Matches { get; set; }
#endif
/// <summary>The object_type property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? ObjectType { get; set; }
#nullable restore
#else
public string ObjectType { get; set; }
#endif
/// <summary>The object_url property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? ObjectUrl { get; set; }
#nullable restore
#else
public string ObjectUrl { get; set; }
#endif
/// <summary>The property property</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public string? Property { get; set; }
#nullable restore
#else
public string Property { get; set; }
public string Value { get; set; }
#endif
/// <summary>
/// Instantiates a new <see cref="Users"/> and sets the default values.
Expand All @@ -76,11 +54,9 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{
return new Dictionary<string, Action<IParseNode>>
{
{"fragment", n => { Fragment = n.GetStringValue(); } },
{"matches", n => { Matches = n.GetCollectionOfObjectValues<Users_matches>(Users_matches.CreateFromDiscriminatorValue)?.ToList(); } },
{"object_type", n => { ObjectType = n.GetStringValue(); } },
{"object_url", n => { ObjectUrl = n.GetStringValue(); } },
{"property", n => { Property = n.GetStringValue(); } },
{"primary", n => { Primary = n.GetBoolValue(); } },
{"type", n => { Type = n.GetStringValue(); } },
{"value", n => { Value = n.GetStringValue(); } },
};
}
/// <summary>
Expand All @@ -90,11 +66,9 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
public virtual void Serialize(ISerializationWriter writer)
{
_ = writer ?? throw new ArgumentNullException(nameof(writer));
writer.WriteStringValue("fragment", Fragment);
writer.WriteCollectionOfObjectValues<Users_matches>("matches", Matches);
writer.WriteStringValue("object_type", ObjectType);
writer.WriteStringValue("object_url", ObjectUrl);
writer.WriteStringValue("property", Property);
writer.WriteBoolValue("primary", Primary);
writer.WriteStringValue("type", Type);
writer.WriteStringValue("value", Value);
writer.WriteAdditionalData(AdditionalData);
}
}
Expand Down
71 changes: 0 additions & 71 deletions src/GitHub/Models/Users_matches.cs

This file was deleted.

7 changes: 5 additions & 2 deletions src/GitHub/Networks/Item/Item/Events/EventsRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public EventsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : bas
{
}
/// <summary>
/// List public events for a network of repositories
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// API method documentation <see href="https://docs.github.com/[email protected]/rest/activity/events#list-public-events-for-a-network-of-repositories" />
/// </summary>
/// <returns>A List&lt;Event&gt;</returns>
Expand All @@ -57,6 +57,9 @@ public async Task<List<Event>> GetAsync(Action<RequestConfiguration<EventsReques
var collectionResult = await RequestAdapter.SendCollectionAsync<Event>(requestInfo, Event.CreateFromDiscriminatorValue, errorMapping, cancellationToken).ConfigureAwait(false);
return collectionResult?.ToList();
}
/// <summary>
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// </summary>
/// <returns>A <see cref="RequestInformation"/></returns>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
Expand All @@ -83,7 +86,7 @@ public EventsRequestBuilder WithUrl(string rawUrl)
return new EventsRequestBuilder(rawUrl, RequestAdapter);
}
/// <summary>
/// List public events for a network of repositories
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// </summary>
public class EventsRequestBuilderGetQueryParameters
{
Expand Down
7 changes: 5 additions & 2 deletions src/GitHub/Orgs/Item/Events/EventsRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public EventsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : bas
{
}
/// <summary>
/// List public organization events
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// API method documentation <see href="https://docs.github.com/[email protected]/rest/activity/events#list-public-organization-events" />
/// </summary>
/// <returns>A List&lt;Event&gt;</returns>
Expand All @@ -50,6 +50,9 @@ public async Task<List<Event>> GetAsync(Action<RequestConfiguration<EventsReques
var collectionResult = await RequestAdapter.SendCollectionAsync<Event>(requestInfo, Event.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false);
return collectionResult?.ToList();
}
/// <summary>
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// </summary>
/// <returns>A <see cref="RequestInformation"/></returns>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
Expand All @@ -76,7 +79,7 @@ public EventsRequestBuilder WithUrl(string rawUrl)
return new EventsRequestBuilder(rawUrl, RequestAdapter);
}
/// <summary>
/// List public organization events
/// &gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// </summary>
public class EventsRequestBuilderGetQueryParameters
{
Expand Down
6 changes: 3 additions & 3 deletions src/GitHub/Users/Item/Events/EventsRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public EventsRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : bas
{
}
/// <summary>
/// If you are authenticated as the given user, you will see your private events. Otherwise, you&apos;ll only see public events.
/// If you are authenticated as the given user, you will see your private events. Otherwise, you&apos;ll only see public events.&gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// API method documentation <see href="https://docs.github.com/[email protected]/rest/activity/events#list-events-for-the-authenticated-user" />
/// </summary>
/// <returns>A List&lt;Event&gt;</returns>
Expand All @@ -63,7 +63,7 @@ public async Task<List<Event>> GetAsync(Action<RequestConfiguration<EventsReques
return collectionResult?.ToList();
}
/// <summary>
/// If you are authenticated as the given user, you will see your private events. Otherwise, you&apos;ll only see public events.
/// If you are authenticated as the given user, you will see your private events. Otherwise, you&apos;ll only see public events.&gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// </summary>
/// <returns>A <see cref="RequestInformation"/></returns>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
Expand Down Expand Up @@ -91,7 +91,7 @@ public EventsRequestBuilder WithUrl(string rawUrl)
return new EventsRequestBuilder(rawUrl, RequestAdapter);
}
/// <summary>
/// If you are authenticated as the given user, you will see your private events. Otherwise, you&apos;ll only see public events.
/// If you are authenticated as the given user, you will see your private events. Otherwise, you&apos;ll only see public events.&gt; [!NOTE]&gt; This API is not built to serve real-time use cases. Depending on the time of day, event latency can be anywhere from 30s to 6h.
/// </summary>
public class EventsRequestBuilderGetQueryParameters
{
Expand Down
Loading
Loading