@@ -49,17 +49,41 @@ module.exports.Generate = async function (config) {
4949 throw new Error ( "Build Failed with an Error on Percy Server. Please check your percy dashboard for more information." )
5050 }
5151 }
52-
52+
5353 console . log ( `Generating report for Build ID ${ buildId } ` )
54- let snapshotsData = await axios . get ( `/snapshots?build_id=${ buildId } ` , { responseType : 'json' } ) . then ( ( res ) => {
55- if ( res . status == 200 ) {
56- let parser = new Parser ( res . data )
57- let data = parser . getSimplified ( )
58- return data
54+ // let snapshotsData = await axios.get(`/snapshots?build_id=${buildId}`, { responseType: 'json' }).then((res) => {
55+ // if (res.status == 200) {
56+ // let parser = new Parser(res.data)
57+ // let data = parser.getSimplified()
58+ // return data
59+ // } else {
60+ // throw res.data
61+ // }
62+ // })
63+ //
64+ let snapshotsData = [ ] ;
65+ let cursor = null ;
66+ let hasMore = true ;
67+
68+ while ( hasMore ) {
69+ const cursorParam = cursor ? `&page[cursor]=${ cursor } ` : '' ;
70+ const response = await axios . get ( `/snapshots?build_id=${ buildId } ${ cursorParam } ` , { responseType : 'json' } ) ;
71+ if ( response . status === 200 ) {
72+ let parser = new Parser ( response . data ) ;
73+ let data = parser . getSimplified ( ) ;
74+ if ( data . length > 0 ) {
75+ snapshotsData . push ( ...data ) ;
76+ cursor = data [ data . length - 1 ] . id ; // update cursor to last snapshot ID
77+ // If less than a typical page size (usually 20), stop
78+ // hasMore = data.length >= 20;
79+ } else {
80+ hasMore = false ;
81+ }
5982 } else {
60- throw res . data
83+ throw response . data ;
6184 }
62- } )
85+ }
86+
6387 buildURL = buildDetails [ 'data' ] [ 'attributes' ] [ 'web-url' ]
6488 projectURL = buildURL . split ( "/builds/" ) [ 0 ]
6589 projectName = projectURL . split ( '/' ) . slice ( - 1 ) [ 0 ]
0 commit comments