Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,12 @@ async function* fetchCommits(repo) {
headers: {'User-Agent': 'Our script'}, // github needs any user-agent header
});

const body = await response.json(); // (2) response is JSON (array of commits)
const commits = await response.json(); // (2) response is JSON (array of commits)

// (3) the URL of the next page is in the headers, extract it
let nextPage = response.headers.get('Link').match(/<(.*?)>; rel="next"/);
nextPage = nextPage?.[1];
url = response.headers.get('link').match(/<([^>]+)>; rel="next"/)?.[1];

url = nextPage;

for(let commit of body) { // (4) yield commits one by one, until the page ends
for (const commit of commits) { // (4) yield commits one by one, until the page ends
yield commit;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
headers: {'User-Agent': 'Our script'}, // github requires user-agent header
});

const body = await response.json(); // parses response as JSON (array of commits)
const commits = await response.json(); // parses response as JSON (array of commits)

// the URL of the next page is in the headers, extract it
let nextPage = response.headers.get('Link').match(/<(.*?)>; rel="next"/);
nextPage = nextPage?.[1];

url = nextPage;
url = response.headers.get('link').match(/<([^>]+)>; rel="next"/)?.[1];

// yield commits one by one, when they finish - fetch a new page url
for(let commit of body) {
for (const commit of commits) {
yield commit;
}
}
Expand Down