-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathhead.html
More file actions
24 lines (19 loc) · 761 Bytes
/
head.html
File metadata and controls
24 lines (19 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script>
async function* fetchCommits(repo) {
let url = `https://api.github.com/repos/${repo}/commits`;
while (url) {
const response = await fetch(url, {
headers: {'User-Agent': 'Our script'}, // github requiere la cabecera user-agent
});
const body = await response.json(); // resuelve la respuesta como JSON (un array de commits)
// la URL de la página siguiente está en las cabeceras, la extraemos
let nextPage = response.headers.get('Link').match(/<(.*?)>; rel="next"/);
nextPage = nextPage?.[1];
url = nextPage;
// entrega los commits uno por uno, cuando finaliza buscamos la URL de una nueva página
for(let commit of body) {
yield commit;
}
}
}
</script>