Skip to content

Commit a8af028

Browse files
Commit via running ake Sources/copilot
1 parent 45d558b commit a8af028

File tree

2 files changed

+543
-0
lines changed

2 files changed

+543
-0
lines changed

Sources/copilot/Client.swift

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,4 +2015,201 @@ public struct Client: APIProtocol {
20152015
}
20162016
)
20172017
}
2018+
/// Get a summary of Copilot usage for a team
2019+
///
2020+
/// > [!NOTE]
2021+
/// > This endpoint is in beta and is subject to change.
2022+
///
2023+
/// You can use this endpoint to see a daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE
2024+
/// for users within a team, with a further breakdown of suggestions, acceptances, and number of active users by editor and language for each day.
2025+
/// See the response schema tab for detailed metrics definitions.
2026+
///
2027+
/// The response contains metrics for up to 28 days prior. Usage metrics are processed once per day for the previous day,
2028+
/// and the response will only include data up until yesterday. In order for an end user to be counted towards these metrics,
2029+
/// they must have telemetry enabled in their IDE.
2030+
///
2031+
/// > [!NOTE]
2032+
/// > This endpoint will only return results for a given day if the team had five or more members with active Copilot licenses, as evaluated at the end of that day.
2033+
///
2034+
/// Organization owners for the organization that contains this team, and owners and billing managers of the parent enterprise can view Copilot usage metrics for a team.
2035+
///
2036+
/// OAuth app tokens and personal access tokens (classic) need either the `manage_billing:copilot`, `read:org`, or `read:enterprise` scopes to use this endpoint.
2037+
///
2038+
/// - Remark: HTTP `GET /orgs/{org}/team/{team_slug}/copilot/usage`.
2039+
/// - Remark: Generated from `#/paths//orgs/{org}/team/{team_slug}/copilot/usage/get(copilot/usage-metrics-for-team)`.
2040+
public func copilot_sol_usage_hyphen_metrics_hyphen_for_hyphen_team(_ input: Operations.copilot_sol_usage_hyphen_metrics_hyphen_for_hyphen_team.Input) async throws -> Operations.copilot_sol_usage_hyphen_metrics_hyphen_for_hyphen_team.Output {
2041+
try await client.send(
2042+
input: input,
2043+
forOperation: Operations.copilot_sol_usage_hyphen_metrics_hyphen_for_hyphen_team.id,
2044+
serializer: { input in
2045+
let path = try converter.renderedPath(
2046+
template: "/orgs/{}/team/{}/copilot/usage",
2047+
parameters: [
2048+
input.path.org,
2049+
input.path.team_slug
2050+
]
2051+
)
2052+
var request: HTTPTypes.HTTPRequest = .init(
2053+
soar_path: path,
2054+
method: .get
2055+
)
2056+
suppressMutabilityWarning(&request)
2057+
try converter.setQueryItemAsURI(
2058+
in: &request,
2059+
style: .form,
2060+
explode: true,
2061+
name: "since",
2062+
value: input.query.since
2063+
)
2064+
try converter.setQueryItemAsURI(
2065+
in: &request,
2066+
style: .form,
2067+
explode: true,
2068+
name: "until",
2069+
value: input.query.until
2070+
)
2071+
try converter.setQueryItemAsURI(
2072+
in: &request,
2073+
style: .form,
2074+
explode: true,
2075+
name: "page",
2076+
value: input.query.page
2077+
)
2078+
try converter.setQueryItemAsURI(
2079+
in: &request,
2080+
style: .form,
2081+
explode: true,
2082+
name: "per_page",
2083+
value: input.query.per_page
2084+
)
2085+
converter.setAcceptHeader(
2086+
in: &request.headerFields,
2087+
contentTypes: input.headers.accept
2088+
)
2089+
return (request, nil)
2090+
},
2091+
deserializer: { response, responseBody in
2092+
switch response.status.code {
2093+
case 200:
2094+
let contentType = converter.extractContentTypeIfPresent(in: response.headerFields)
2095+
let body: Operations.copilot_sol_usage_hyphen_metrics_hyphen_for_hyphen_team.Output.Ok.Body
2096+
let chosenContentType = try converter.bestContentType(
2097+
received: contentType,
2098+
options: [
2099+
"application/json"
2100+
]
2101+
)
2102+
switch chosenContentType {
2103+
case "application/json":
2104+
body = try await converter.getResponseBodyAsJSON(
2105+
[Components.Schemas.copilot_hyphen_usage_hyphen_metrics].self,
2106+
from: responseBody,
2107+
transforming: { value in
2108+
.json(value)
2109+
}
2110+
)
2111+
default:
2112+
preconditionFailure("bestContentType chose an invalid content type.")
2113+
}
2114+
return .ok(.init(body: body))
2115+
case 500:
2116+
let contentType = converter.extractContentTypeIfPresent(in: response.headerFields)
2117+
let body: Components.Responses.internal_error.Body
2118+
let chosenContentType = try converter.bestContentType(
2119+
received: contentType,
2120+
options: [
2121+
"application/json"
2122+
]
2123+
)
2124+
switch chosenContentType {
2125+
case "application/json":
2126+
body = try await converter.getResponseBodyAsJSON(
2127+
Components.Schemas.basic_hyphen_error.self,
2128+
from: responseBody,
2129+
transforming: { value in
2130+
.json(value)
2131+
}
2132+
)
2133+
default:
2134+
preconditionFailure("bestContentType chose an invalid content type.")
2135+
}
2136+
return .internalServerError(.init(body: body))
2137+
case 401:
2138+
let contentType = converter.extractContentTypeIfPresent(in: response.headerFields)
2139+
let body: Components.Responses.requires_authentication.Body
2140+
let chosenContentType = try converter.bestContentType(
2141+
received: contentType,
2142+
options: [
2143+
"application/json"
2144+
]
2145+
)
2146+
switch chosenContentType {
2147+
case "application/json":
2148+
body = try await converter.getResponseBodyAsJSON(
2149+
Components.Schemas.basic_hyphen_error.self,
2150+
from: responseBody,
2151+
transforming: { value in
2152+
.json(value)
2153+
}
2154+
)
2155+
default:
2156+
preconditionFailure("bestContentType chose an invalid content type.")
2157+
}
2158+
return .unauthorized(.init(body: body))
2159+
case 403:
2160+
let contentType = converter.extractContentTypeIfPresent(in: response.headerFields)
2161+
let body: Components.Responses.forbidden.Body
2162+
let chosenContentType = try converter.bestContentType(
2163+
received: contentType,
2164+
options: [
2165+
"application/json"
2166+
]
2167+
)
2168+
switch chosenContentType {
2169+
case "application/json":
2170+
body = try await converter.getResponseBodyAsJSON(
2171+
Components.Schemas.basic_hyphen_error.self,
2172+
from: responseBody,
2173+
transforming: { value in
2174+
.json(value)
2175+
}
2176+
)
2177+
default:
2178+
preconditionFailure("bestContentType chose an invalid content type.")
2179+
}
2180+
return .forbidden(.init(body: body))
2181+
case 404:
2182+
let contentType = converter.extractContentTypeIfPresent(in: response.headerFields)
2183+
let body: Components.Responses.not_found.Body
2184+
let chosenContentType = try converter.bestContentType(
2185+
received: contentType,
2186+
options: [
2187+
"application/json"
2188+
]
2189+
)
2190+
switch chosenContentType {
2191+
case "application/json":
2192+
body = try await converter.getResponseBodyAsJSON(
2193+
Components.Schemas.basic_hyphen_error.self,
2194+
from: responseBody,
2195+
transforming: { value in
2196+
.json(value)
2197+
}
2198+
)
2199+
default:
2200+
preconditionFailure("bestContentType chose an invalid content type.")
2201+
}
2202+
return .notFound(.init(body: body))
2203+
default:
2204+
return .undocumented(
2205+
statusCode: response.status.code,
2206+
.init(
2207+
headerFields: response.headerFields,
2208+
body: responseBody
2209+
)
2210+
)
2211+
}
2212+
}
2213+
)
2214+
}
20182215
}

0 commit comments

Comments
 (0)