Skip to content

Commit

Permalink
Removing previous logic of fetch participants
Browse files Browse the repository at this point in the history
  • Loading branch information
dgparmar14 committed Jul 22, 2024
1 parent 355b5ad commit 66a86ab
Showing 1 changed file with 3 additions and 70 deletions.
73 changes: 3 additions & 70 deletions lib/discussion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@ import octokit from "./octokit";
import { featureIsEnabled } from "./utils";
import { Activity } from "./types";

interface Participant {
repository: {
discussion: {
comments: {
edges: {
node: {
author: {
login: string;
};
};
}[];
};
};
};
}
interface Dicussion {
repository: {
discussion: {
Expand All @@ -38,56 +23,6 @@ const root = join(process.cwd(), "data-repo/data/github/discussions");

export const categories: { name: string; emoji: string }[] = [];

export async function fetchParticipants(discussion: ParsedDiscussion) {
const org = env.NEXT_PUBLIC_GITHUB_ORG;
const number = discussion.link?.split("/").pop() ?? "";

const query = `query($org: String!, $repoName: String!, $discussionNumber: Int!, $cursor: String) {
repository(owner: $org, name: $repoName) {
discussion(number: $discussionNumber) {
comments(first: 100, after: $cursor) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
author {
login
}
}
}
}
}
}
}
`;
const participants: Participant = await octokit.graphql.paginate(query, {
org,
repoName: discussion.repoName,
discussionNumber: Number(number),
cursor: null,
});
return Array.from(
new Set(
participants.repository.discussion.comments.edges.map(
(c) => c.node.author.login,
),
),
);
}

async function appendParticipantsToDiscussions(
discussions: ParsedDiscussion[],
) {
await Promise.all(
discussions.map(async (discussion) => {
if (!discussion.isAnswered) discussion.participants = []; // await fetchParticipants(discussion);
}),
);
return discussions;
}

export async function fetchGithubDiscussion(
noOfDiscussion?: number | null,
user?: string,
Expand Down Expand Up @@ -119,19 +54,17 @@ export async function fetchGithubDiscussion(
}
});

let discussionsToReturn: ParsedDiscussion[] = discussions;

if (user) {
discussionsToReturn = discussions.filter(
return await discussions.filter(
(discussion) =>
(discussion.participants ?? []).includes(user) ||
discussion.author === user,
);
} else if (noOfDiscussion) {
discussionsToReturn = discussions.slice(0, noOfDiscussion);
return discussions.slice(0, noOfDiscussion);
}

return await appendParticipantsToDiscussions(discussionsToReturn);
return discussions;
}

export async function checkAnsweredByUser(
Expand Down

0 comments on commit 66a86ab

Please sign in to comment.