Skip to content

Commit 743cf78

Browse files
committed
fix: adapt for latest @octokit/types
1 parent 5369ed7 commit 743cf78

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

Diff for: README.md

+16-13
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ the passed options and sends the request using [fetch](https://developer.mozilla
3838
🤩 1:1 mapping of REST API endpoint documentation, e.g. [Add labels to an issue](https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue) becomes
3939

4040
```js
41-
request("POST /repos/:owner/:repo/issues/:number/labels", {
41+
request("POST /repos/{owner}/{repo}/issues/{number}/labels", {
4242
mediaType: {
4343
previews: ["symmetra"],
4444
},
@@ -99,7 +99,7 @@ const { request } = require("@octokit/request");
9999
```js
100100
// Following GitHub docs formatting:
101101
// https://developer.github.com/v3/repos/#list-organization-repositories
102-
const result = await request("GET /orgs/:org/repos", {
102+
const result = await request("GET /orgs/{org}/repos", {
103103
headers: {
104104
authorization: "token 0000000000000000000000000000000000000001",
105105
},
@@ -139,7 +139,7 @@ Alternatively, pass in a method and a url
139139
```js
140140
const result = await request({
141141
method: "GET",
142-
url: "/orgs/:org/repos",
142+
url: "/orgs/{org}/repos",
143143
headers: {
144144
authorization: "token 0000000000000000000000000000000000000001",
145145
},
@@ -180,11 +180,14 @@ const requestWithAuth = request.defaults({
180180
});
181181

182182
const { data: app } = await requestWithAuth("GET /app");
183-
const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
184-
owner: "octocat",
185-
repo: "hello-world",
186-
title: "Hello from the engine room",
187-
});
183+
const { data: app } = await requestWithAuth(
184+
"POST /repos/{owner}/{repo}/issues",
185+
{
186+
owner: "octocat",
187+
repo: "hello-world",
188+
title: "Hello from the engine room",
189+
}
190+
);
188191
```
189192

190193
## request()
@@ -215,7 +218,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
215218
String
216219
</td>
217220
<td>
218-
If <code>route</code> is set it has to be a string consisting of the request method and URL, e.g. <code>GET /orgs/:org</code>
221+
If <code>route</code> is set it has to be a string consisting of the request method and URL, e.g. <code>GET /orgs/{org}</code>
219222
</td>
220223
</tr>
221224
<tr>
@@ -283,7 +286,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
283286
</td>
284287
<td>
285288
<strong>Required.</strong> A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,
286-
e.g. <code>/orgs/:org/repos</code>. The <code>url</code> is parsed using <a href="https://github.com/bramstein/url-template">url-template</a>.
289+
e.g. <code>/orgs/{org}/repos</code>. The <code>url</code> is parsed using <a href="https://github.com/bramstein/url-template">url-template</a>.
287290
</td>
288291
</tr>
289292
<tr>
@@ -356,7 +359,7 @@ const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", {
356359

357360
All other options except `options.request.*` will be passed depending on the `method` and `url` options.
358361

359-
1. If the option key is a placeholder in the `url`, it will be used as replacement. For example, if the passed options are `{url: '/orgs/:org/repos', org: 'foo'}` the returned `options.url` is `https://api.github.com/orgs/foo/repos`
362+
1. If the option key is a placeholder in the `url`, it will be used as replacement. For example, if the passed options are `{url: '/orgs/{org}/repos', org: 'foo'}` the returned `options.url` is `https://api.github.com/orgs/foo/repos`
360363
2. If the `method` is `GET` or `HEAD`, the option is passed as query parameter
361364
3. Otherwise the parameter is passed in the request body as JSON key.
362365

@@ -421,7 +424,7 @@ const myrequest = require("@octokit/request").defaults({
421424
per_page: 100,
422425
});
423426

424-
myrequest(`GET /orgs/:org/repos`);
427+
myrequest(`GET /orgs/{org}/repos`);
425428
```
426429

427430
You can call `.defaults()` again on the returned method, the defaults will cascade.
@@ -450,7 +453,7 @@ by the global default.
450453
See https://github.com/octokit/endpoint.js. Example
451454

452455
```js
453-
const options = request.endpoint("GET /orgs/:org/repos", {
456+
const options = request.endpoint("GET /orgs/{org}/repos", {
454457
org: "my-project",
455458
type: "private",
456459
});

Diff for: test/defaults.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("endpoint.defaults()", () => {
3535
},
3636
});
3737

38-
return myRequest(`GET /orgs/:org/repos`).then((response) => {
38+
return myRequest(`GET /orgs/{org}/repos`).then((response) => {
3939
expect(response.status).toEqual(200);
4040
});
4141
});
@@ -76,8 +76,10 @@ describe("endpoint.defaults()", () => {
7676
},
7777
});
7878

79-
return myProjectRequestWithAuth(`GET /orgs/:org/repos`).then((response) => {
80-
expect(response.status).toEqual(200);
81-
});
79+
return myProjectRequestWithAuth(`GET /orgs/{org}/repos`).then(
80+
(response) => {
81+
expect(response.status).toEqual(200);
82+
}
83+
);
8284
});
8385
});

Diff for: test/request.test.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("request()", () => {
2929
},
3030
});
3131

32-
return request("GET /orgs/:org/repos", {
32+
return request("GET /orgs/{org}/repos", {
3333
headers: {
3434
authorization: "token 0000000000000000000000000000000000000001",
3535
},
@@ -50,7 +50,7 @@ describe("request()", () => {
5050

5151
return request({
5252
method: "GET",
53-
url: "/orgs/:org/repos",
53+
url: "/orgs/{org}/repos",
5454
headers: {
5555
authorization: "token 0000000000000000000000000000000000000001",
5656
},
@@ -147,7 +147,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
147147
},
148148
});
149149
await requestWithAuth("GET /app");
150-
await requestWithAuth("POST /repos/:owner/:repo/issues", {
150+
await requestWithAuth("POST /repos/{owner}/{repo}/issues", {
151151
owner: "octocat",
152152
repo: "hello-world",
153153
title: "Hello from the engine room",
@@ -165,7 +165,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
165165
},
166166
});
167167

168-
request("POST /repos/:owner/:repo/issues", {
168+
request("POST /repos/{owner}/{repo}/issues", {
169169
owner: "octocat",
170170
repo: "hello-world",
171171
headers: {
@@ -193,7 +193,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
193193
},
194194
});
195195

196-
request("PUT /user/starred/:owner/:repo", {
196+
request("PUT /user/starred/{owner}/{repo}", {
197197
headers: {
198198
authorization: `token 0000000000000000000000000000000000000001`,
199199
},
@@ -234,12 +234,12 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
234234
},
235235
};
236236

237-
request(`HEAD /repos/:owner/:repo/pulls/:number`, options)
237+
request(`HEAD /repos/{owner}/{repo}/pulls/{number}`, options)
238238
.then((response) => {
239239
expect(response.status).toEqual(200);
240240

241241
return request(
242-
`HEAD /repos/:owner/:repo/pulls/:number`,
242+
`HEAD /repos/{owner}/{repo}/pulls/{number}`,
243243
Object.assign(options, { number: 2 })
244244
);
245245
})
@@ -271,7 +271,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
271271
}
272272
);
273273

274-
return request("GET /repos/:owner/:repo/:archive_format/:ref", {
274+
return request("GET /repos/{owner}/{repo}/{archive_format}/{ref}", {
275275
owner: "octokit-fixture-org",
276276
repo: "get-archive",
277277
archive_format: "tarball",
@@ -324,7 +324,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
324324
);
325325
}, 304);
326326

327-
return request("GET /orgs/:org", {
327+
return request("GET /orgs/{org}", {
328328
org: "myorg",
329329
headers: { "If-None-Match": "etag" },
330330
request: {
@@ -349,7 +349,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
349349
);
350350
}, 304);
351351

352-
return request("GET /orgs/:org", {
352+
return request("GET /orgs/{org}", {
353353
org: "myorg",
354354
headers: {
355355
"If-Modified-Since": "Sun Dec 24 2017 22:00:00 GMT-0600 (CST)",
@@ -369,7 +369,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
369369
it("Not found", () => {
370370
const mock = fetchMock.sandbox().get("path:/orgs/nope", 404);
371371

372-
return request("GET /orgs/:org", {
372+
return request("GET /orgs/{org}", {
373373
org: "nope",
374374
request: {
375375
fetch: mock,
@@ -398,7 +398,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
398398
},
399399
});
400400

401-
return request("GET /repos/:owner/:repo/contents/:path", {
401+
return request("GET /repos/{owner}/{repo}/contents/{path}", {
402402
headers: {
403403
accept: "application/vnd.github.v3.raw",
404404
},
@@ -670,7 +670,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
670670
},
671671
});
672672

673-
return request("GET /repos/:owner/:repo/issues/:number", {
673+
return request("GET /repos/{owner}/{repo}/issues/{number}", {
674674
headers: {
675675
authorization: "token 0000000000000000000000000000000000000001",
676676
},
@@ -700,7 +700,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
700700
},
701701
});
702702

703-
return request("GET /repos/:owner/:repo/issues/:number", {
703+
return request("GET /repos/{owner}/{repo}/issues/{number}", {
704704
headers: {
705705
authorization: "token 0000000000000000000000000000000000000001",
706706
},
@@ -742,7 +742,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
742742
}
743743
);
744744

745-
return request("PUT /repos/:owner/:repo/branches/:branch/protection", {
745+
return request("PUT /repos/{owner}/{repo}/branches/{branch}/protection", {
746746
baseUrl: "https://request-errors-test.com",
747747
mediaType: { previews: ["luke-cage"] },
748748
headers: {

0 commit comments

Comments
 (0)