-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3832 from Lemito66/Emill_reto#17_Javascript
Reto #17 - Javascript
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
Retos/Reto #17 - GIT Y GITHUB [Difícil]/javascript/Lemito66.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* ¡Estoy de celebración! He publicado mi primer libro: | ||
* "Git y GitHub desde cero" | ||
* - Papel: mouredev.com/libro-git | ||
* - eBook: mouredev.com/ebook-git | ||
* | ||
* ¿Sabías que puedes leer información de Git y GitHub desde la gran | ||
* mayoría de lenguajes de programación? | ||
* | ||
* Crea un programa que lea los últimos 10 commits de este repositorio y muestre: | ||
* - Hash | ||
* - Autor | ||
* - Mensaje | ||
* - Fecha y hora | ||
* | ||
* Ejemplo de salida: | ||
* Commit 1 (el más reciente) | 12345A | MoureDev | Este es un commit | 24/04/2023 21:00 | ||
* | ||
* Se permite utilizar librerías que nos faciliten esta tarea. | ||
* | ||
*/ | ||
|
||
const getData = async (username, nameRepo, numberOfCommits) => { | ||
const url = `https://api.github.com/repos/${username}/${nameRepo}/commits`; | ||
const response = await fetch(url); | ||
const data = await response.json(); | ||
|
||
const commits = data.slice(0, numberOfCommits).map((commit, index) => { | ||
const { sha, commit: { author: { name, date }, message } } = commit; | ||
const newDate = new Date(date).toLocaleString(); | ||
return `Commit ${index + 1} | ${sha.slice(0, 7)} | ${name} | ${message} | ${newDate}`; | ||
} | ||
); | ||
return commits; | ||
|
||
}; | ||
|
||
(async () => { | ||
const data = await getData("lemito66", "django-crud-react", 10); | ||
|
||
data.forEach(element => { | ||
console.log(element); | ||
}); | ||
|
||
})(); |