Advertisement
ErolKZ

Untitled

Feb 28th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1.  
  2. function loadCommits() {
  3.  
  4. // username repo
  5.  
  6. let resultUl = document.getElementById('commits');
  7.  
  8. let usernameElement = document.getElementById('username').value;
  9.  
  10. let repoElement = document.getElementById('repo').value;
  11.  
  12. console.log(usernameElement, repoElement);
  13.  
  14. let url = `https://api.github.com/repos/${usernameElement}/${repoElement}/commits`;
  15.  
  16. console.log(url);
  17.  
  18. fetch(url)
  19.  
  20. .then(response => response.json())
  21.  
  22. .then(result => {
  23.  
  24. result.forEach(commit => {
  25.  
  26. console.log(commit);
  27.  
  28. let newLiElement = document.createElement('li');
  29.  
  30. newLiElement.textContent = `${commit.author.name}: ${commit.message}`;
  31.  
  32. resultUl.appendChild(newLiElement);
  33.  
  34. });
  35.  
  36. })
  37.  
  38. .catch(error => {
  39.  
  40. let newLiElement = document.createElement('li');
  41.  
  42. newLiElement.textContent = `Error: ${error.status} (Not Found)`;
  43.  
  44. resultUl.appendChild(newLiElement);
  45.  
  46. // console.log(error.message);
  47.  
  48. });
  49.  
  50.  
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement