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

feat: v8 #599

Merged
merged 15 commits into from
Jul 7, 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
30 changes: 10 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,35 +245,36 @@ const { data: app } = await requestWithAuth(
</tr>
<tr>
<th align=left>
<code>options.mediaType.format</code>
<code>options.method</code>
</th>
<td>
String
</td>
<td>
Media type param, such as `raw`, `html`, or `full`. See <a href="https://developer.github.com/v3/media/">Media Types</a>.
Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>, case insensitive. <em>Defaults to <code>Get</code></em>.
</td>
</tr>
<tr>
<th align=left>
<code>options.mediaType.previews</code>
<code>options.mediaType.format</code>
</th>
<td>
Array of strings
String
</td>
<td>
Name of previews, such as `mercy`, `symmetra`, or `scarlet-witch`. See <a href="https://developer.github.com/v3/previews/">API Previews</a>.
Media type param, such as `raw`, `html`, or `full`. See <a href="https://developer.github.com/v3/media/">Media Types</a>.
</td>
</tr>
<tr>
<th align=left>
<code>options.method</code>
<code>options.mediaType.previews</code>
</th>
<td>
String
Array of strings
</td>
<td>
Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>, case insensitive. <em>Defaults to <code>Get</code></em>.
Name of previews, such as `mercy`, `symmetra`, or `scarlet-witch`. See <a href="https://docs.github.com/graphql/overview/schema-previews">GraphQL Schema Previews</a>.
Note that these only apply to GraphQL requests and have no effect on REST routes.
</td>
</tr>
<tr>
Expand All @@ -299,18 +300,7 @@ const { data: app } = await requestWithAuth(
Set request body directly instead of setting it to JSON based on additional parameters. See <a href="#data-parameter">"The `data` parameter"</a> below.
</td>
</tr>
<tr>
<th align=left>
<a name="options-request-agent"></a>
<code>options.request.agent</code>
</th>
<td>
<a href="https://nodejs.org/api/http.html#http_class_http_agent">http(s).Agent</a> instance
</td>
<td>
Node only. Useful for custom proxy, certificate, or dns lookup.
</td>
</tr>

<tr>
<th align=left>
<code>options.request.fetch</code>
Expand Down
24 changes: 20 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@octokit/endpoint": "^8.0.1",
"@octokit/request-error": "^4.0.1",
"@octokit/types": "^10.0.0",
"@octokit/types": "^11.0.0",
"is-plain-object": "^5.0.0",
"universal-user-agent": "^6.0.0"
},
Expand Down
27 changes: 10 additions & 17 deletions src/fetch-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,16 @@ export default function fetchWrapper(
);
}

return fetch(
requestOptions.url,
Object.assign(
{
method: requestOptions.method,
body: requestOptions.body,
headers: requestOptions.headers as HeadersInit,
redirect: requestOptions.redirect,
// duplex must be set if request.body is ReadableStream or Async Iterables.
// See https://fetch.spec.whatwg.org/#dom-requestinit-duplex.
...(requestOptions.body && { duplex: "half" }),
},
// `requestOptions.request.agent` type is incompatible
// see https://github.com/octokit/types.ts/pull/264
requestOptions.request as any,
),
)
return fetch(requestOptions.url, {
method: requestOptions.method,
body: requestOptions.body,
headers: requestOptions.headers as HeadersInit,
signal: (requestOptions as any).signal,
data: (requestOptions as any).data,
// duplex must be set if request.body is ReadableStream or Async Iterables.
// See https://fetch.spec.whatwg.org/#dom-requestinit-duplex.
...(requestOptions.body && { duplex: "half" }),
})
.then(async (response) => {
url = response.url;
status = response.status;
Expand Down
19 changes: 0 additions & 19 deletions test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,6 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
);
});

it("options.request.signal is passed as option to fetch", function () {
return request("/", {
request: {
// We pass a value that is not an `AbortSignal`, and expect `fetch` to
// throw an exception complaining about the value
signal: "funk",
},
})
.then(() => {
throw new Error("Should not resolve");
})

.catch((error) => {
// We can't match on the entire string because the message differs between
// Node versions.
expect(error.message).toMatch(/AbortSignal/);
});
});

it("options.request.fetch", function () {
return request("/", {
request: {
Expand Down