Skip to content

Commit a7ec830

Browse files
octokit[bot]octokitbotwolfy1339
authored
feat: new GET /users/{username}/settings/billing/usage, POST /credentials/revoke endpoints, endpoint type updates, type performance fixes (#675)
* WIP octokit/openapi updated * fix: implement some performance improvements (#667) * Pre-compute the keys of the `Endpoint` type in order to not have to compute them multiple times * Use interface extends instead of intersections See https://github.com/microsoft/TypeScript/wiki/Performance Part of #666 --------- Co-authored-by: Octokit Bot <[email protected]> Co-authored-by: wolfy1339 <[email protected]>
1 parent 10745ee commit a7ec830

File tree

9 files changed

+62
-22
lines changed

9 files changed

+62
-22
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"description": "Shared TypeScript definitions for Octokit projects",
99
"dependencies": {
10-
"@octokit/openapi-types": "^25.0.0"
10+
"@octokit/openapi-types": "^25.1.0"
1111
},
1212
"scripts": {
1313
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
@@ -76,6 +76,6 @@
7676
]
7777
},
7878
"octokit": {
79-
"openapi-version": "19.0.0"
79+
"openapi-version": "19.1.0"
8080
}
8181
}

scripts/update-endpoints/generated/endpoints.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,6 +3961,19 @@
39613961
],
39623962
"renamed": null
39633963
},
3964+
{
3965+
"method": "GET",
3966+
"url": "/users/{username}/settings/billing/usage",
3967+
"documentationUrl": "https://docs.github.com/rest/billing/enhanced-billing#get-billing-usage-report-for-a-user",
3968+
"parameters": [
3969+
{ "alias": null, "deprecated": null, "in": "PATH", "name": "username" },
3970+
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "year" },
3971+
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "month" },
3972+
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "day" },
3973+
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "hour" }
3974+
],
3975+
"renamed": null
3976+
},
39643977
{
39653978
"method": "GET",
39663979
"url": "/orgs/{org}/settings/billing/packages",
@@ -6938,6 +6951,15 @@
69386951
],
69396952
"renamed": null
69406953
},
6954+
{
6955+
"method": "POST",
6956+
"url": "/credentials/revoke",
6957+
"documentationUrl": "https://docs.github.com/rest/credentials/revoke#revoke-a-list-of-credentials",
6958+
"parameters": [
6959+
{ "alias": null, "deprecated": null, "in": "BODY", "name": "credentials" }
6960+
],
6961+
"renamed": null
6962+
},
69416963
{
69426964
"method": "PUT",
69436965
"url": "/orgs/{org}/dependabot/secrets/{secret_name}/repositories/{repository_id}",
@@ -7104,6 +7126,7 @@
71047126
"in": "QUERY",
71057127
"name": "epss_percentage"
71067128
},
7129+
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "has" },
71077130
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "scope" },
71087131
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "sort" },
71097132
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "direction" },
@@ -7131,6 +7154,7 @@
71317154
"in": "QUERY",
71327155
"name": "epss_percentage"
71337156
},
7157+
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "has" },
71347158
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "scope" },
71357159
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "sort" },
71367160
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "direction" },
@@ -7160,6 +7184,7 @@
71607184
"in": "QUERY",
71617185
"name": "epss_percentage"
71627186
},
7187+
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "has" },
71637188
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "scope" },
71647189
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "sort" },
71657190
{ "alias": null, "deprecated": null, "in": "QUERY", "name": "direction" },

scripts/update-endpoints/templates/endpoints.ts.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,6 @@ export interface Endpoints {
116116
"{{method}}"
117117
>,
118118
{{/each}}
119-
}
119+
}
120+
121+
export type EndpointKeys = keyof Endpoints;

src/EndpointDefaults.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Url } from "./Url.js";
77
* The `.endpoint()` method is guaranteed to set all keys defined by RequestParameters
88
* as well as the method property.
99
*/
10-
export type EndpointDefaults = RequestParameters & {
10+
export interface EndpointDefaults extends RequestParameters {
1111
baseUrl: Url;
1212
method: RequestMethod;
1313
url?: Url;
@@ -19,4 +19,4 @@ export type EndpointDefaults = RequestParameters & {
1919
format: string;
2020
previews?: string[];
2121
};
22-
};
22+
}

src/EndpointInterface.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { RequestOptions } from "./RequestOptions.js";
33
import type { RequestParameters } from "./RequestParameters.js";
44
import type { Route } from "./Route.js";
55

6-
import type { Endpoints } from "./generated/Endpoints.js";
6+
import type { EndpointKeys, Endpoints } from "./generated/Endpoints.js";
77

88
export interface EndpointInterface<D extends object = object> {
99
/**
@@ -25,13 +25,13 @@ export interface EndpointInterface<D extends object = object> {
2525
*/
2626
<
2727
R extends Route,
28-
P extends RequestParameters = R extends keyof Endpoints
28+
P extends RequestParameters = R extends EndpointKeys
2929
? Endpoints[R]["parameters"] & RequestParameters
3030
: RequestParameters,
3131
>(
32-
route: keyof Endpoints | R,
32+
route: EndpointKeys | R,
3333
parameters?: P,
34-
): (R extends keyof Endpoints ? Endpoints[R]["request"] : RequestOptions) &
34+
): (R extends EndpointKeys ? Endpoints[R]["request"] : RequestOptions) &
3535
Pick<P, keyof RequestOptions>;
3636

3737
/**
@@ -57,14 +57,14 @@ export interface EndpointInterface<D extends object = object> {
5757
*/
5858
<
5959
R extends Route,
60-
P extends RequestParameters = R extends keyof Endpoints
60+
P extends RequestParameters = R extends EndpointKeys
6161
? Endpoints[R]["parameters"] & RequestParameters
6262
: RequestParameters,
6363
>(
64-
route: keyof Endpoints | R,
64+
route: EndpointKeys | R,
6565
parameters?: P,
6666
): D &
67-
(R extends keyof Endpoints
67+
(R extends EndpointKeys
6868
? Endpoints[R]["request"] & Endpoints[R]["parameters"]
6969
: EndpointDefaults) &
7070
P;

src/EndpointOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { RequestMethod } from "./RequestMethod.js";
22
import type { Url } from "./Url.js";
33
import type { RequestParameters } from "./RequestParameters.js";
44

5-
export type EndpointOptions = RequestParameters & {
5+
export interface EndpointOptions extends RequestParameters {
66
method: RequestMethod;
77
url: Url;
8-
};
8+
}

src/RequestInterface.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { OctokitResponse } from "./OctokitResponse.js";
33
import type { RequestParameters } from "./RequestParameters.js";
44
import type { Route } from "./Route.js";
55

6-
import type { Endpoints } from "./generated/Endpoints.js";
6+
import type { EndpointKeys, Endpoints } from "./generated/Endpoints.js";
77

88
export interface RequestInterface<D extends object = object> {
99
/**
@@ -24,11 +24,11 @@ export interface RequestInterface<D extends object = object> {
2424
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.{format|previews}`, `request`, or `baseUrl`.
2525
*/
2626
<R extends Route>(
27-
route: keyof Endpoints | R,
28-
options?: R extends keyof Endpoints
27+
route: EndpointKeys | R,
28+
options?: R extends EndpointKeys
2929
? Endpoints[R]["parameters"] & RequestParameters
3030
: RequestParameters,
31-
): R extends keyof Endpoints
31+
): R extends EndpointKeys
3232
? Promise<Endpoints[R]["response"]>
3333
: Promise<OctokitResponse<any>>;
3434

src/generated/Endpoints.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4724,6 +4724,13 @@ export interface Endpoints {
47244724
"/users/{username}/settings/billing/shared-storage",
47254725
"get"
47264726
>;
4727+
/**
4728+
* @see https://docs.github.com/rest/billing/enhanced-billing#get-billing-usage-report-for-a-user
4729+
*/
4730+
"GET /users/{username}/settings/billing/usage": Operation<
4731+
"/users/{username}/settings/billing/usage",
4732+
"get"
4733+
>;
47274734
/**
47284735
* @see https://docs.github.com/rest/users/social-accounts#list-social-accounts-for-a-user
47294736
*/
@@ -5205,6 +5212,10 @@ export interface Endpoints {
52055212
"/applications/{client_id}/token/scoped",
52065213
"post"
52075214
>;
5215+
/**
5216+
* @see https://docs.github.com/rest/credentials/revoke#revoke-a-list-of-credentials
5217+
*/
5218+
"POST /credentials/revoke": Operation<"/credentials/revoke", "post">;
52085219
/**
52095220
* @see https://docs.github.com/rest/code-security/configurations#create-a-code-security-configuration-for-an-enterprise
52105221
*/
@@ -6892,3 +6903,5 @@ export interface Endpoints {
68926903
"put"
68936904
>;
68946905
}
6906+
6907+
export type EndpointKeys = keyof Endpoints;

0 commit comments

Comments
 (0)