- Click on the blue "Get PRs/Issues Count" button below.
- Type in a valid GitHub username
- Remember, to complete the First Steps, you need a minimum of:
- 4 issues created (one from Step 6 and three from Step 8)
- 4 comments on issues you didn’t create (one from Step 6 and three from Step 8)
- 5 merged pull requests (one from Step 1, one from Step 6, and three from Step 8)
Get PRs/Issues Count
<script> const res = document.getElementById('results'); var user = "dogi"; //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 + " is not a valid GitHub Username. Make sure you are entering a valid GitHub Username."; 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:open-learning-exchange/open-learning-exchange.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 Issues Created. function Total_Issues() { var url = "https://api.github.com/search/issues?q=repo:open-learning-exchange/open-learning-exchange.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:open-learning-exchange/open-learning-exchange.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>