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

Add support for copilot seats api #21

Merged
merged 5 commits into from
Dec 27, 2023
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
9 changes: 9 additions & 0 deletions Octokit.Reactive/Clients/IObservableCopilotClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
using Octokit.Copilot;

namespace Octokit.Reactive;

public interface IObservableCopilotClient
{
IObservable<CopilotSeatsResponse> GetAllSeats(string org);
}
2 changes: 2 additions & 0 deletions Octokit.Reactive/Clients/IObservableOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface IObservableOrganizationsClient
/// Returns a client to manage organization actions.
/// </summary>
IObservableOrganizationActionsClient Actions { get; }

IObservableCopilotClient Copilot { get; }

/// <summary>
/// Returns the specified organization.
Expand Down
19 changes: 19 additions & 0 deletions Octokit.Reactive/Clients/ObservableCopilotClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Reactive.Threading.Tasks;
using Octokit.Copilot;

namespace Octokit.Reactive;

public class ObservableCopilotClient : IObservableCopilotClient
{
private readonly ICopilotClient _client;
public ObservableCopilotClient(IGitHubClient client)
{
_client = client.Organization.Copilot;
}

public IObservable<CopilotSeatsResponse> GetAllSeats(string org)
{
return _client.GetAllSeats(org).ToObservable();
}
}
4 changes: 4 additions & 0 deletions Octokit.Reactive/Clients/ObservableOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ObservableOrganizationsClient(IGitHubClient client)
Hook = new ObservableOrganizationHooksClient(client);
OutsideCollaborator = new ObservableOrganizationOutsideCollaboratorsClient(client);
Actions = new ObservableOrganizationActionsClient(client);
Copilot = new ObservableCopilotClient(client);

_client = client.Organization;
_connection = client.Connection;
Expand Down Expand Up @@ -54,6 +55,9 @@ public ObservableOrganizationsClient(IGitHubClient client)
/// </summary>
public IObservableOrganizationActionsClient Actions { get; private set; }


public IObservableCopilotClient Copilot { get; }

/// <summary>
/// Returns the specified organization.
/// </summary>
Expand Down
35 changes: 35 additions & 0 deletions Octokit/Clients/CopilotClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit.Copilot;

namespace Octokit
{
public class CopilotClient : ApiClient, ICopilotClient
{
public CopilotClient(IApiConnection apiConnection) : base(apiConnection)
{
}

[ManualRoute("GET", "/orgs/{org}/copilot/billing/seats")]
public async Task<CopilotSeatsResponse> GetAllSeats(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

var results = await ApiConnection.GetAll<CopilotSeatsResponse>(ApiUrls.CopilotSeats(org), ApiOptions.None);
if (results.Count == 0)
{
return new CopilotSeatsResponse (0, new List<CopilotSeat>());
}

var totalSeats = results[0].TotalSeats;
var seats = new List<CopilotSeat>();

foreach (var copilotSeatsResponse in results)
{
seats.AddRange(copilotSeatsResponse.Seats);
}

return new CopilotSeatsResponse (totalSeats, seats);
}
}
}
11 changes: 11 additions & 0 deletions Octokit/Clients/ICopilotClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit.Copilot;

namespace Octokit
{
public interface ICopilotClient
{
Task<CopilotSeatsResponse> GetAllSeats(string org);
}
}
5 changes: 5 additions & 0 deletions Octokit/Clients/IOrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public interface IOrganizationsClient
/// Returns a client to manage organization actions.
/// </summary>
IOrganizationActionsClient Actions { get; }

/// <summary>
/// Returns a client to manage organization Copilot seats.
/// </summary>
ICopilotClient Copilot { get; }

/// <summary>
/// Returns the specified <see cref="Organization"/>.
Expand Down
3 changes: 3 additions & 0 deletions Octokit/Clients/OrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public OrganizationsClient(IApiConnection apiConnection) : base(apiConnection)
Hook = new OrganizationHooksClient(apiConnection);
OutsideCollaborator = new OrganizationOutsideCollaboratorsClient(apiConnection);
Actions = new OrganizationActionsClient(apiConnection);
Copilot = new CopilotClient(apiConnection);
}

/// <summary>
Expand All @@ -40,6 +41,8 @@ public OrganizationsClient(IApiConnection apiConnection) : base(apiConnection)
/// </summary>
public IOrganizationActionsClient Actions { get; private set; }

public ICopilotClient Copilot { get; }

/// <summary>
/// Returns a client to manage outside collaborators of an organization.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5219,5 +5219,15 @@ public static Uri AuditLog(string organization, string phrase)
{
return "organizations/{0}/audit-log?phrase={1}".FormatUri(organization, phrase);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the copilot seats of the organization
/// </summary>
/// <param name="org">The organization</param>
/// <returns></returns>
public static Uri CopilotSeats(string org)
{
return "orgs/{0}/copilot/billing/seats".FormatUri(org);
}
}
}
30 changes: 30 additions & 0 deletions Octokit/Models/Response/Copilot/CopilotSeat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Diagnostics;
using System.Globalization;

namespace Octokit.Copilot
{
[ExcludeFromCtorWithAllPropertiesConventionTest(nameof(Type))]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class CopilotSeat
{
public CopilotSeat() {}

public CopilotSeat(DateTime createdAt, DateTime updatedAt, User assignee)
{
CreatedAt = createdAt;
UpdatedAt = updatedAt;
Assignee = assignee;
}

public DateTime CreatedAt { get; private set; }

public DateTime UpdatedAt { get; private set; }

public User Assignee { get; private set; }

internal string DebuggerDisplay =>
string.Format(CultureInfo.InvariantCulture,
"User: Id: {0} Login: {1}", Assignee.Id, Assignee.Login);
}
}
33 changes: 33 additions & 0 deletions Octokit/Models/Response/Copilot/CopilotSeatsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

namespace Octokit.Copilot
{
/// <summary>
/// Represents a Copilot seats response on GitHub.
/// </summary>
[ExcludeFromCtorWithAllPropertiesConventionTest(nameof(Type))]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class CopilotSeatsResponse
{
public CopilotSeatsResponse()
{
}

public CopilotSeatsResponse(int totalSeats, IReadOnlyList<CopilotSeat> seats)
{
TotalSeats = totalSeats;
Seats = seats;
}

public int TotalSeats { get; private set;}

public IReadOnlyList<CopilotSeat> Seats { get; private set;}

internal string DebuggerDisplay =>
string.Format(CultureInfo.InvariantCulture,
"TotalSeats: {0}", TotalSeats);
}
}
2 changes: 1 addition & 1 deletion Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>An async-based GitHub API client library for .NET and .NET Core</Description>
<AssemblyTitle>Octokit</AssemblyTitle>
<Authors>GitHub</Authors>
<Version>1.0.17</Version>
<Version>1.0.18</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>Octokit</AssemblyName>
<PackageId>Apiiro.Octokit</PackageId>
Expand Down
Loading