I need to find top 5 popular discussions in the last month for a Github repo. By popular, I mean most interacted with. I am using the below java-script code which gives me the total count of comments and reactions for each discussion. But how do I modify it get the total count of comments and reactions in the last month? I am new to GraphQL, so if someone has a better idea to achieve this, please help.
function get_repo_discussions(repo) {
var after = "";
var res = [];
do {
var query = ` \
query { \
repository(owner: ` + '"' + owner + '", name: "' + repo + `") { \
discussions(first:100 \
` + after + `\
) { \
totalCount \
pageInfo { \
startCursor \
endCursor \
hasNextPage \
hasPreviousPage \
} \
edges { \
node { \
number, title, url, createdAt \
comments {
totalCount \
}, \
reactions {
totalCount \
} \
} \
} \
} \
} \
} \
`;
var ql = 'https://api.github.com/graphql';
var response = UrlFetchApp.fetch(ql, {
method: "POST",
contentType: 'application/json',
headers: { Authorization: 'Bearer ' + token},
payload: JSON.stringify({query: query})
});
var json = response.getContentText();
data = JSON.parse(json);
// Logger.log(data.data.repository.discussions.pageInfo.hasNextPage);
var discussion_count = data.data.repository.discussions.edges.length;
var edges = data.data.repository.discussions.edges;
for (var i = 0; i < discussion_count;i++){
var node = edges[i].node;
var number = node.number;
var title = node.title;
var url = node.url;
var created_at = new Date(node.createdAt);
var comments = node.comments.totalCount;
var reactions = node.reactions.totalCount;
res.push([number,title, url, created_at,comments + reactions]);
}
if(data.data.repository.discussions.pageInfo.hasNextPage){
after = " after:" + '"' + data.data.repository.discussions.pageInfo.hasNextPage.endCursor + '"';
}
}
while(data.data.repository.discussions.pageInfo.hasNextPage ==true);
return res;
}