diff --git a/pages/track-first-steps-progress.md b/pages/track-first-steps-progress.md index e0212565f..b3b68683f 100644 --- a/pages/track-first-steps-progress.md +++ b/pages/track-first-steps-progress.md @@ -50,6 +50,7 @@ Total_PRs(); Total_Issues(); Merged_PRs(); + CountIssueComments(); // Call the new function here }) .catch(function(error) { console.log(error); @@ -111,4 +112,57 @@ console.log(error); }); } + + // Function to count comments made by a user in issues + function CountIssueComments() { + const githubToken = "YOUR-ACCESS-TOKEN-HERE"; //insert your access token here + const query = ` + query { + repository(owner: "open-learning-exchange", name: "open-learning-exchange.github.io") { + issues(states: [OPEN], first: 100) { + edges { + node { + comments(first: 100) { + edges { + node { + author { + login + } + } + } + } + } + } + } + } + } + `; + + fetch('https://api.github.com/graphql', { + method: 'POST', + headers: { + 'Authorization': 'Bearer ' + githubToken, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ query }) + }) + .then(checkStatus) + .then((resp) => resp.json()) + .then(function(data) { + let commentsCount = 0; + data.data.repository.issues.edges.forEach(issue => { + issue.node.comments.edges.forEach(comment => { + if (comment.node.author && comment.node.author.login === user) { + commentsCount++; + } + }); + }); + let p = document.createElement('p'); + p.innerHTML = "Number of Comments on Issues: " + commentsCount; + res.appendChild(p); + }) + .catch(function(error) { + console.log(error); + }); +}