Skip to content

Commit 734d7a3

Browse files
authored
feat: legacyRestEndpointMethods export (#367)
BREAKING CHANGE: No methods are set on `octokit.*` any more, only on `octokit.rest.*`. You can use `Octokit.plugin(legacyRestEndpointMethods)` to recover the previous behavior for the forseeable time, but eventually it will be deprecated and removed
1 parent 6cb8fa8 commit 734d7a3

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ import { endpointsToMethods } from "./endpoints-to-methods";
99
export function restEndpointMethods(octokit: Octokit): Api {
1010
const api = endpointsToMethods(octokit, ENDPOINTS);
1111
return {
12-
...api,
1312
rest: api,
1413
};
1514
}
1615
restEndpointMethods.VERSION = VERSION;
16+
17+
export function legacyRestEndpointMethods(octokit: Octokit): Api["rest"] & Api {
18+
const api = endpointsToMethods(octokit, ENDPOINTS);
19+
return {
20+
...api,
21+
rest: api,
22+
};
23+
}
24+
legacyRestEndpointMethods.VERSION = VERSION;

src/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { Route, RequestParameters } from "@octokit/types";
22

33
import { RestEndpointMethods } from "./generated/method-types";
44

5-
export type Api = RestEndpointMethods & {
6-
rest: RestEndpointMethods;
7-
};
5+
export type Api = { rest: RestEndpointMethods };
86

97
export type EndpointDecorations = {
108
mapToData?: string;

test/rest-endpoint-methods.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fetchMock from "fetch-mock";
22
import { Octokit } from "@octokit/core";
33

4-
import { restEndpointMethods } from "../src";
4+
import { restEndpointMethods, legacyRestEndpointMethods } from "../src";
55

66
describe("REST API endpoint methods", () => {
77
it("README example", async () => {
@@ -179,11 +179,11 @@ describe("REST API endpoint methods", () => {
179179
return octokit.rest.apps.listInstallations();
180180
});
181181

182-
// besides setting `octokit.rest.*`, the plugin is also setting the same methods
183-
// directly on `octokit.*` for legacy reasons. We will deprecate the `octokit.*`
184-
// methods in future, but for now we just make sure they are set
182+
// besides setting `octokit.rest.*`, the plugin exports legacyRestEndpointMethods
183+
// which is also setting the same methods directly on `octokit.*` for legacy reasons.
184+
// We will deprecate the `octokit.*` methods in future, but for now we just make sure they are set
185185

186-
it("octokit.repos.createForAuthenticatedUser()", async () => {
186+
it("legacyRestEndpointMethods", async () => {
187187
const mock = fetchMock.sandbox().post(
188188
"path:/user/repos",
189189
{ id: 1 },
@@ -194,7 +194,7 @@ describe("REST API endpoint methods", () => {
194194
}
195195
);
196196

197-
const MyOctokit = Octokit.plugin(restEndpointMethods);
197+
const MyOctokit = Octokit.plugin(legacyRestEndpointMethods);
198198
const octokit = new MyOctokit({
199199
auth: "secret123",
200200
request: {
@@ -203,10 +203,14 @@ describe("REST API endpoint methods", () => {
203203
});
204204

205205
// See https://developer.github.com/v3/repos/#create
206-
const { data } = await octokit.repos.createForAuthenticatedUser({
206+
const response1 = await octokit.repos.createForAuthenticatedUser({
207+
name: "my-new-repo",
208+
});
209+
const response2 = await octokit.rest.repos.createForAuthenticatedUser({
207210
name: "my-new-repo",
208211
});
209212

210-
expect(data.id).toStrictEqual(1);
213+
expect(response1.data.id).toStrictEqual(1);
214+
expect(response2.data.id).toStrictEqual(1);
211215
});
212216
});

0 commit comments

Comments
 (0)