File tree 5 files changed +53
-7
lines changed
5 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,17 @@ const { data: app } = await requestWithAuth(
346
346
Used for internal logging. Defaults to <a href="https://developer.mozilla.org/en-US/docs/Web/API/console"><code>console</code></a>.
347
347
</td>
348
348
</tr >
349
+ </tr >
350
+ <th align=left>
351
+ <code>options.request.parseSuccessResponseBody</code>
352
+ </th>
353
+ <td>
354
+ <code>boolean</code>
355
+ </td>
356
+ <td>
357
+ If set to <code>false</code> the returned `response` will be passed through from `fetch`. This is useful to stream response.body when downloading files from the GitHub API.
358
+ </td>
359
+ </tr >
349
360
</table >
350
361
351
362
All other options except ` options.request.* ` will be passed depending on the ` method ` and ` url ` options.
Original file line number Diff line number Diff line change 24
24
"dependencies" : {
25
25
"@octokit/endpoint" : " ^9.0.0" ,
26
26
"@octokit/request-error" : " ^5.0.0" ,
27
- "@octokit/types" : " ^11.0 .0" ,
27
+ "@octokit/types" : " ^11.1 .0" ,
28
28
"is-plain-object" : " ^5.0.0" ,
29
29
"universal-user-agent" : " ^6.0.0"
30
30
},
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ export default function fetchWrapper(
11
11
requestOptions . request && requestOptions . request . log
12
12
? requestOptions . request . log
13
13
: console ;
14
+ const parseSuccessResponseBody =
15
+ requestOptions . request ?. parseSuccessResponseBody !== false ;
14
16
15
17
if (
16
18
isPlainObject ( requestOptions . body ) ||
@@ -113,7 +115,9 @@ export default function fetchWrapper(
113
115
throw error ;
114
116
}
115
117
116
- return getResponseData ( response ) ;
118
+ return parseSuccessResponseBody
119
+ ? await getResponseData ( response )
120
+ : response . body ;
117
121
} )
118
122
. then ( ( data ) => {
119
123
return {
Original file line number Diff line number Diff line change 1
1
import fs from "fs" ;
2
- import stream from "stream" ;
2
+ import stream , { Stream } from "stream" ;
3
3
4
4
import { getUserAgent } from "universal-user-agent" ;
5
5
import fetchMock from "fetch-mock" ;
@@ -1021,4 +1021,35 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
1021
1021
expect ( error . name ) . toEqual ( "AbortError" ) ;
1022
1022
} ) ;
1023
1023
} ) ;
1024
+
1025
+ it ( "request should pass the stream in the response" , ( ) => {
1026
+ const mock = fetchMock . sandbox ( ) . get (
1027
+ "https://api.github.com/repos/octokit-fixture-org/release-assets/tarball/main" ,
1028
+ {
1029
+ status : 200 ,
1030
+ headers : {
1031
+ "content-type" : "application/x-gzip" ,
1032
+ } ,
1033
+ body : fs . createReadStream ( __filename ) ,
1034
+ } ,
1035
+ {
1036
+ sendAsJson : false ,
1037
+ } ,
1038
+ ) ;
1039
+
1040
+ return request ( "GET /repos/{owner}/{repo}/tarball/{branch}" , {
1041
+ owner : "octokit-fixture-org" ,
1042
+ repo : "release-assets" ,
1043
+ branch : "main" ,
1044
+ request : {
1045
+ parseSuccessResponseBody : false ,
1046
+ fetch : mock ,
1047
+ } ,
1048
+ } ) . then ( ( response ) => {
1049
+ expect ( response . status ) . toEqual ( 200 ) ;
1050
+ expect ( response . headers [ "content-type" ] ) . toEqual ( "application/x-gzip" ) ;
1051
+ expect ( response . data ) . toBeInstanceOf ( Stream ) ;
1052
+ expect ( mock . done ( ) ) . toBe ( true ) ;
1053
+ } ) ;
1054
+ } ) ;
1024
1055
} ) ;
You can’t perform that action at this time.
0 commit comments