We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cdf4232 commit 62f2b71Copy full SHA for 62f2b71
1 file changed
1-js/12-generators-iterators/2-async-iterators-generators/head.html
@@ -0,0 +1,24 @@
1
+<script>
2
+ async function* fetchCommits(repo) {
3
+ let url = `https://api.github.com/repos/${repo}/commits`;
4
+
5
+ while (url) {
6
+ const response = await fetch(url, {
7
+ headers: {'User-Agent': 'Our script'}, // github requires user-agent header
8
+ });
9
10
+ const body = await response.json(); // parses response as JSON (array of commits)
11
12
+ // the URL of the next page is in the headers, extract it
13
+ let nextPage = response.headers.get('Link').match(/<(.*?)>; rel="next"/);
14
+ nextPage = nextPage && nextPage[1];
15
16
+ url = nextPage;
17
18
+ // yield commits one by one, when they finish - fetch a new page url
19
+ for(let commit of body) {
20
+ yield commit;
21
+ }
22
23
24
+</script>
0 commit comments