File tree Expand file tree Collapse file tree 3 files changed +38
-14
lines changed Expand file tree Collapse file tree 3 files changed +38
-14
lines changed Original file line number Diff line number Diff line change 48
48
"htmlparser2" : " ^7.2.0" ,
49
49
"kleur" : " ^4.1.5" ,
50
50
"node-fetch" : " ^3.2.10" ,
51
+ "p-retry" : " ^5.1.1" ,
51
52
"parse-numeric-range" : " ^1.3.0" ,
52
53
"preact" : " ^10.10.1" ,
53
54
"prettier" : " ^2.7.1" ,
Original file line number Diff line number Diff line change 1
1
import fetch from 'node-fetch' ;
2
+ import pRetry , { AbortError } from 'p-retry' ;
2
3
3
4
/**
4
5
* Fetch a URL from the GitHub API and resolve its JSON response.
5
6
* @param {{ url: string; githubToken?: string } } options
6
7
* @returns {Promise<any> }
7
8
*/
8
9
export async function githubGet ( { url, githubToken = undefined } ) {
9
- const headers = {
10
- Accept : 'application/vnd.github.v3+json' ,
11
- } ;
12
- if ( githubToken ) {
13
- headers . Authorization = `token ${ githubToken } ` ;
14
- }
15
- const response = await fetch ( url , {
16
- headers ,
17
- } ) ;
18
- const json = await response . json ( ) ;
10
+ return await pRetry (
11
+ async ( ) => {
12
+ const headers = {
13
+ Accept : 'application/vnd.github.v3+json' ,
14
+ } ;
15
+ if ( githubToken ) {
16
+ headers . Authorization = `token ${ githubToken } ` ;
17
+ }
18
+ const response = await fetch ( url , { headers } ) ;
19
+ const json = await response . json ( ) ;
19
20
20
- if ( ! response . ok ) {
21
- throw new Error ( `GitHub API call failed: GET "${ url } " returned status ${ response . status } : ${ JSON . stringify ( json ) } ` ) ;
22
- }
21
+ if ( ! response . ok ) {
22
+ throw new AbortError ( `GitHub API call failed: GET "${ url } " returned status ${ response . status } : ${ JSON . stringify ( json ) } ` ) ;
23
+ }
23
24
24
- return json ;
25
+ return json ;
26
+ } ,
27
+ { retries : 5 }
28
+ ) ;
25
29
}
You can’t perform that action at this time.
0 commit comments