Skip to content

Commit c74a851

Browse files
Merge pull request #299 from shri142/main
Added pagination logic
2 parents c863596 + 286ffb5 commit c74a851

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@percy/report",
33
"description": "Package to generate a build report and project summary report for Percy, BrowserStack's visual testing platform",
4-
"version": "1.0.5",
4+
"version": "1.0.6",
55
"main": "src/index.js",
66
"license": "MIT",
77
"author": "BrowserStack Pvt Ltd",

src/generate.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)