11const fetch = require ( 'node-fetch' ) ;
2+
23const {
34 transformRecordedData : transformGitHub ,
45 setupGitHub,
@@ -33,39 +34,78 @@ function getEnvs() {
3334const apiRoot = 'https://api.netlify.com/api/v1/' ;
3435
3536async function get ( netlifyApiToken , path ) {
36- const response = await fetch ( `${ apiRoot } ${ path } ` , {
37- headers : {
38- 'Content-Type' : 'application/json' ,
39- Authorization : `Bearer ${ netlifyApiToken } ` ,
40- } ,
41- } ) . then ( res => res . json ( ) ) ;
42-
43- return response ;
37+ const controller = new AbortController ( ) ;
38+ const timeout = setTimeout ( ( ) => controller . abort ( ) , 10000 ) ; // 10 second timeout
39+
40+ try {
41+ const response = await fetch ( `${ apiRoot } ${ path } ` , {
42+ signal : controller . signal ,
43+ headers : {
44+ 'Content-Type' : 'application/json' ,
45+ Authorization : `Bearer ${ netlifyApiToken } ` ,
46+ } ,
47+ } ) . then ( res => res . json ( ) ) ;
48+ clearTimeout ( timeout ) ;
49+ return response ;
50+ } catch ( error ) {
51+ clearTimeout ( timeout ) ;
52+ if ( error . name === 'AbortError' ) {
53+ console . error ( `Netlify API GET timeout after 10s: ${ path } ` ) ;
54+ throw new Error ( `Netlify API GET request timeout: ${ path } ` ) ;
55+ }
56+ throw error ;
57+ }
4458}
4559
4660async function post ( netlifyApiToken , path , payload ) {
47- const response = await fetch ( `${ apiRoot } ${ path } ` , {
48- method : 'POST' ,
49- headers : {
50- 'Content-Type' : 'application/json' ,
51- Authorization : `Bearer ${ netlifyApiToken } ` ,
52- } ,
53- ...( payload ? { body : JSON . stringify ( payload ) } : { } ) ,
54- } ) . then ( res => res . json ( ) ) ;
55-
56- return response ;
61+ const controller = new AbortController ( ) ;
62+ const timeout = setTimeout ( ( ) => controller . abort ( ) , 10000 ) ; // 10 second timeout
63+
64+ try {
65+ const response = await fetch ( `${ apiRoot } ${ path } ` , {
66+ signal : controller . signal ,
67+ method : 'POST' ,
68+ headers : {
69+ 'Content-Type' : 'application/json' ,
70+ Authorization : `Bearer ${ netlifyApiToken } ` ,
71+ } ,
72+ ...( payload ? { body : JSON . stringify ( payload ) } : { } ) ,
73+ } ) . then ( res => res . json ( ) ) ;
74+ clearTimeout ( timeout ) ;
75+ return response ;
76+ } catch ( error ) {
77+ clearTimeout ( timeout ) ;
78+ if ( error . name === 'AbortError' ) {
79+ console . error ( `Netlify API POST timeout after 10s: ${ path } ` ) ;
80+ throw new Error ( `Netlify API POST request timeout: ${ path } ` ) ;
81+ }
82+ throw error ;
83+ }
5784}
5885
5986async function del ( netlifyApiToken , path ) {
60- const response = await fetch ( `${ apiRoot } ${ path } ` , {
61- method : 'DELETE' ,
62- headers : {
63- 'Content-Type' : 'application/json' ,
64- Authorization : `Bearer ${ netlifyApiToken } ` ,
65- } ,
66- } ) . then ( res => res . text ( ) ) ;
67-
68- return response ;
87+ const controller = new AbortController ( ) ;
88+ const timeout = setTimeout ( ( ) => controller . abort ( ) , 10000 ) ; // 10 second timeout
89+
90+ try {
91+ const response = await fetch ( `${ apiRoot } ${ path } ` , {
92+ signal : controller . signal ,
93+ method : 'DELETE' ,
94+ headers : {
95+ 'Content-Type' : 'application/json' ,
96+ Authorization : `Bearer ${ netlifyApiToken } ` ,
97+ } ,
98+ } ) . then ( res => res . text ( ) ) ;
99+ clearTimeout ( timeout ) ;
100+ return response ;
101+ } catch ( error ) {
102+ clearTimeout ( timeout ) ;
103+ if ( error . name === 'AbortError' ) {
104+ console . error ( `Netlify API DELETE timeout after 10s: ${ path } ` ) ;
105+ throw new Error ( `Netlify API DELETE request timeout: ${ path } ` ) ;
106+ }
107+ throw error ;
108+ }
69109}
70110
71111async function createSite ( netlifyApiToken , payload ) {
@@ -90,16 +130,29 @@ async function enableLargeMedia(netlifyApiToken, siteId) {
90130}
91131
92132async function waitForDeploys ( netlifyApiToken , siteId ) {
93- for ( let i = 0 ; i < 10 ; i ++ ) {
94- const deploys = await get ( netlifyApiToken , `sites/${ siteId } /deploys` ) ;
95- if ( deploys . some ( deploy => deploy . state === 'ready' ) ) {
96- console . log ( 'Deploy finished for site:' , siteId ) ;
97- return ;
133+ const maxRetries = 5 ; // Reduced from 10 to 5
134+ const retryDelayMs = 10 * 1000 ; // Reduced from 30s to 10s
135+
136+ for ( let i = 0 ; i < maxRetries ; i ++ ) {
137+ try {
138+ const deploys = await get ( netlifyApiToken , `sites/${ siteId } /deploys` ) ;
139+
140+ if ( deploys && deploys . some ( deploy => deploy . state === 'ready' ) ) {
141+ return ;
142+ }
143+
144+ if ( i < maxRetries - 1 ) {
145+ await new Promise ( resolve => setTimeout ( resolve , retryDelayMs ) ) ;
146+ }
147+ } catch ( error ) {
148+ console . error ( `Error checking deploy status: ${ error . message } ` ) ;
149+ if ( i < maxRetries - 1 ) {
150+ await new Promise ( resolve => setTimeout ( resolve , retryDelayMs ) ) ;
151+ }
98152 }
99- console . log ( 'Waiting on deploy of site:' , siteId ) ;
100- await new Promise ( resolve => setTimeout ( resolve , 30 * 1000 ) ) ;
101153 }
102- console . log ( 'Timed out waiting on deploy of site:' , siteId ) ;
154+
155+ console . error ( `Timed out waiting on deploy of site: ${ siteId } ` ) ;
103156}
104157
105158async function createUser ( netlifyApiToken , siteUrl , email , password ) {
0 commit comments