Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the file to fetch the discussions... #470

Closed
Closed
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
94 changes: 91 additions & 3 deletions scripts/pullHistoricalGitHubActivities.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/**
* Script to populate the data-repo with historical information from GitHub.
*
* Supports populating the ollowing activity types:
* Supports populating the following activity types:
*
* - [x] issue_opened
* - [x] pr_opened
* - [x] pr_merged
* - [x] discussion_created
* - [x] discussion_comment
*/

const { join } = require("path");
Expand Down Expand Up @@ -110,6 +112,60 @@ const getPullRequests = async (repo) => {
return repository.pullRequests.nodes;
};

const getDiscussions = async (repo) => {
const { repository } = await octokit.graphql.paginate(
`query paginate($cursor: String, $org: String!, $repo: String!) {
repository(owner: $org, name: $repo) {
discussions(first: 100, after: $cursor) {
nodes {
number
title
url
createdAt
author {
login
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
`,
{ org, repo },
);
return repository.discussions.nodes;
};

const getDiscussionComments = async (repo, discussionNumber) => {
const { repository } = await octokit.graphql.paginate(
`query paginate($cursor: String, $org: String!, $repo: String!, $number: Int!) {
repository(owner: $org, name: $repo) {
discussion(number: $number) {
comments(first: 100, after: $cursor) {
nodes {
id
createdAt
author {
login
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
`,
{ org, repo, number: discussionNumber },
);
return repository.discussion.comments.nodes;
};

const getUserActivities = async () => {
const userActivities = {};

Expand All @@ -128,7 +184,7 @@ const getUserActivities = async () => {
const issues = await getIssues(repo);
console.info(` Captured ${issues.length} issues`);
for (const issue of issues) {
if (!issues.author?.login) {
if (!issue.author?.login) {
continue;
}

Expand Down Expand Up @@ -166,6 +222,38 @@ const getUserActivities = async () => {
});
}
}

const discussions = await getDiscussions(repo);
console.info(` Captured ${discussions.length} discussions`);
for (const discussion of discussions) {
if (!discussion.author?.login) {
continue;
}

addActivity(discussion.author.login, {
type: "discussion_created",
title: `${org}/${repo}#${discussion.number}`,
time: discussion.createdAt,
link: discussion.url,
text: discussion.title,
});

const comments = await getDiscussionComments(repo, discussion.number);
console.info(` Captured ${comments.length} comments for discussion #${discussion.number}`);
for (const comment of comments) {
if (!comment.author?.login) {
continue;
}

addActivity(comment.author.login, {
type: "discussion_comment",
title: `${org}/${repo}#${discussion.number}`,
time: comment.createdAt,
link: `${discussion.url}#discussioncomment-${comment.id}`,
text: "Commented on discussion",
});
}
}
}

return userActivities;
Expand Down Expand Up @@ -232,4 +320,4 @@ async function main() {
console.log("Completed");
}

main();
main();