- Click on the blue "Get PRs/Issues Count" button below.
- Type in a valid Github username
- Remember, in order to complete the "First Steps" you need:
- at least 5 valid PRs
- 4 comments made on issues you didn't create
- 4 issues created
- Click here to return to Step 8.
Get PRs/Issues Count
<script> const res = document.getElementById('results'); var user = "replace me with your GitHub username"; //Functions //Check response from the API function checkStatus(response) { if (response.status >= 200 && response.status < 300) { return Promise.resolve(response) } else { return Promise.reject(new Error(response.statusText)) } } //Validate User function Set_User() { res.innerHTML = ""; user = prompt("Please enter username", user); if (!(user == "" || user == null)) { var url = "https://api.github.com/users/" + user; fetch(url) .then(checkStatus) .then(function(data) { res.innerHTML = ""; Total_PRs(); Total_Issues(); Merged_PRs(); }) .catch(function(error) { console.log(error); let p = document.createElement('p'); p.innerHTML = "ERROR: User " + user + " does not exists."; res.appendChild(p); }); } else { let p = document.createElement('p'); p.innerHTML = "ERROR: Blank or NULL user entered."; res.appendChild(p); } } //Check total number of pull requests function Total_PRs() { var url = "https://api.github.com/search/issues?q=repo:treehouses/treehouses.github.io+author:" + user + "+type:pr&sort=created&order=asc"; fetch(url) .then(checkStatus) .then((resp) => resp.json()) .then(function(data) { let p = document.createElement('p'); p.innerHTML = "Number of PRs: " + data.total_count; res.appendChild(p); }) .catch(function(error) { console.log(error); }); } //Check total number of Comments function Total_PRs() { var url = "https://api.github.com/search/issues?q=repo:treehouses/treehouses.github.io+commenter:" + user + "+type:comment&sort=created&order=asc"; fetch(url) .then(checkStatus) .then((resp) => resp.json()) .then(function(data) { let p = document.createElement('p'); p.innerHTML = "Number of Comments: " + data.total_count; res.appendChild(p); }) .catch(function(error) { console.log(error); }); } //Check total number of Issues Created. function Total_Issues() { var url = "https://api.github.com/search/issues?q=repo:treehouses/treehouses.github.io+author:" + user + "+type:issue&sort=created&order=asc"; fetch(url) .then(checkStatus) .then((resp) => resp.json()) .then(function(data) { let p = document.createElement('p'); p.innerHTML = "Number of Issues: " + data.total_count; res.appendChild(p); }) .catch(function(error) { console.log(error); }); } // Check Number of merged Pull Requests function Merged_PRs() { var url = "https://api.github.com/search/issues?q=repo:treehouses/treehouses.github.io+author:" + user + "+is:merged&sort=created&order=asc"; fetch(url) .then(checkStatus) .then((resp) => resp.json()) .then(function(data) { let p = document.createElement('p'); p.innerHTML = "Number of Merged PRs: " + data.total_count; res.appendChild(p); }) .catch(function(error) { console.log(error); }); } </script>