From 94ee6ceadfc0eab048f275b46e75188b78bc13f6 Mon Sep 17 00:00:00 2001 From: Munish Patel <53735021+munishpatel@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:21:08 -0500 Subject: [PATCH 1/2] updated code for tracking progress --- pages/track-first-steps-progress.md | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/pages/track-first-steps-progress.md b/pages/track-first-steps-progress.md index e0212565f4..9bc4883947 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(); }) .catch(function(error) { console.log(error); @@ -111,4 +112,52 @@ console.log(error); }); } + + // Function to count comments on issues by a user + function CountIssueComments() { + var url = "https://api.github.com/repos/open-learning-exchange/open-learning-exchange.github.io/issues?state=all&per_page=100"; + var commentsCount = 0; + var page = 1; + + // Recursive function to handle pagination + function fetchIssues(url) { + fetch(url) + .then(checkStatus) + .then((resp) => resp.json()) + .then(function(data) { + data.forEach(issue => { + fetch(issue.comments_url) + .then(checkStatus) + .then((resp) => resp.json()) + .then(function(comments) { + comments.forEach(comment => { + if (comment.user.login === user) { + commentsCount++; + } + }); + }) + .catch(function(error) { + console.log(error); + }); + }); + + // Check if there are more pages + if (data.length === 100) { + page++; + var nextPageUrl = "https://api.github.com/repos/open-learning-exchange/open-learning-exchange.github.io/issues?state=all&per_page=100&page=" + page; + fetchIssues(nextPageUrl); + } else { + // Display the total comments count + let p = document.createElement('p'); + p.innerHTML = "Number of Comments on Issues: " + commentsCount; + res.appendChild(p); + } + }) + .catch(function(error) { + console.log(error); + }); + } + + fetchIssues(url); +} From 55e42acb34d7ff0990b701a5bbbf2e3537a283ae Mon Sep 17 00:00:00 2001 From: Munish Patel <53735021+munishpatel@users.noreply.github.com> Date: Mon, 10 Mar 2025 17:22:12 -0500 Subject: [PATCH 2/2] updated code(access token required) --- pages/track-first-steps-progress.md | 89 +++++++++++++++-------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/pages/track-first-steps-progress.md b/pages/track-first-steps-progress.md index 9bc4883947..b3b68683f6 100644 --- a/pages/track-first-steps-progress.md +++ b/pages/track-first-steps-progress.md @@ -50,7 +50,7 @@ Total_PRs(); Total_Issues(); Merged_PRs(); - CountIssueComments(); + CountIssueComments(); // Call the new function here }) .catch(function(error) { console.log(error); @@ -113,51 +113,56 @@ }); } - // Function to count comments on issues by a user + // Function to count comments made by a user in issues function CountIssueComments() { - var url = "https://api.github.com/repos/open-learning-exchange/open-learning-exchange.github.io/issues?state=all&per_page=100"; - var commentsCount = 0; - var page = 1; - - // Recursive function to handle pagination - function fetchIssues(url) { - fetch(url) - .then(checkStatus) - .then((resp) => resp.json()) - .then(function(data) { - data.forEach(issue => { - fetch(issue.comments_url) - .then(checkStatus) - .then((resp) => resp.json()) - .then(function(comments) { - comments.forEach(comment => { - if (comment.user.login === user) { - commentsCount++; + 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 + } + } } - }); - }) - .catch(function(error) { - console.log(error); - }); - }); + } + } + } + } + } + } + `; - // Check if there are more pages - if (data.length === 100) { - page++; - var nextPageUrl = "https://api.github.com/repos/open-learning-exchange/open-learning-exchange.github.io/issues?state=all&per_page=100&page=" + page; - fetchIssues(nextPageUrl); - } else { - // Display the total comments count - let p = document.createElement('p'); - p.innerHTML = "Number of Comments on Issues: " + commentsCount; - res.appendChild(p); + 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++; } - }) - .catch(function(error) { - console.log(error); }); - } - - fetchIssues(url); + }); + let p = document.createElement('p'); + p.innerHTML = "Number of Comments on Issues: " + commentsCount; + res.appendChild(p); + }) + .catch(function(error) { + console.log(error); + }); }