Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function loadCommits() {
- // username repo
- let resultUl = document.getElementById('commits');
- let usernameElement = document.getElementById('username').value;
- let repoElement = document.getElementById('repo').value;
- console.log(usernameElement, repoElement);
- let url = `https://api.github.com/repos/${usernameElement}/${repoElement}/commits`;
- console.log(url);
- fetch(url)
- .then(response => response.json())
- .then(result => {
- result.forEach(commit => {
- let newLiElement = document.createElement('li');
- newLiElement.textContent = `${commit.author.name}: ${commit.message}`;
- resultUl.appendChild(newLiElement);
- });
- })
- .catch(error => {
- let newLiElement = document.createElement('li');
- newLiElement.textContent = `Error: ${error.status} (Not Found)`;
- resultUl.appendChild(newLiElement);
- // console.log(error.message);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement