Write a JS program that loads all commit messages and their authors from a github repository using a given HTML.
HTML Template
You are given the following HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Github Commits</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
GitHub username:
<input type="text" id="username" value="nakov" /> <br>
Repo: <input type="text" id="repo" value="nakov.io.cin" />
<button onclick="loadCommits()">Load Commits</button>
<ul id="commits"></ul>
<script>
function loadCommits() {
// AJAX call …
}
</script>
</body>
</html>
The loadCommits function should get the username and repository from the HTML textboxes with ids "username" and "repo" and make a GET request to the Github API:
"https://api.github.com/repos/<username>/<repository>/commits"
Swap <username> and <repository> with the ones from the HTML:
-
In case of success, for each entry, add a list item (li) in the unordered list (ul) with id= "commits" with text in the format: "<commit.author.name>: <commit.message>"
-
In case of error and a single list item (li) with text in the format: "Error: <error.status> (<error.statusText>)"
Screenshots:
