Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions pages/track-first-steps-progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
Total_PRs();
Total_Issues();
Merged_PRs();
CountIssueComments(); // Call the new function here
})
.catch(function(error) {
console.log(error);
Expand Down Expand Up @@ -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 = "<strong>Number of Comments on Issues:<strong> " + commentsCount;
res.appendChild(p);
})
.catch(function(error) {
console.log(error);
});
}
</script>