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

feat :Duplicate PR collaboration activities closes #531 #534

Merged
merged 10 commits into from
Oct 30, 2024
50 changes: 34 additions & 16 deletions scraper/src/github-scraper/parseEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,23 @@ import { parseISO } from "date-fns";
import { isBlacklisted } from "./utils.js";
import { octokit } from "./config.js";
const processedData: ProcessData = {};

const DefaultBranch = new Map<string, string>();
async function getDefaultBranch(org: string, repo: string) {
try {
if (DefaultBranch.has(`${org}/${repo}`)) {
return DefaultBranch.get(`${org}/${repo}`);
}
const { data } = await octokit.request('GET /repos/{owner}/{repo}', {
owner: org,
repo: repo,
});
return data.default_branch;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the use of the cache when we are not setting anything to the cache ever?

} catch (e) {
console.error(
`Error fetching default branch for organisation ${org} /${repo} `,
);
}
}
function appendEvent(user: string, event: Activity) {
console.log(`Appending event for ${user}`);
if (!processedData[user]) {
Expand All @@ -33,7 +49,8 @@ const emailUserCache: { [key: string]: string } = {};

async function addCollaborations(event: PullRequestEvent, eventTime: Date) {
const collaborators: Set<string> = new Set();

const repo = event.repo.name.split('/');
const default_branch = await getDefaultBranch(repo[0], repo[1])
const url: string | undefined = event.payload.pull_request?.commits_url;

const response = await octokit.request("GET " + url);
Expand Down Expand Up @@ -103,21 +120,22 @@ async function addCollaborations(event: PullRequestEvent, eventTime: Date) {
}
}

if (collaborators.size > 1) {
if (collaborators.size > 1 && event.payload.pull_request.base.ref === default_branch) {
const collaboratorArray = Array.from(collaborators); // Convert Set to Array
for (const user of collaboratorArray) {
const others = new Set(collaborators);
const othersArray = Array.from(others);

others.delete(user);
appendEvent(user, {
type: "pr_collaborated",
title: `${event.repo.name}#${event.payload.pull_request.number}`,
time: eventTime.toISOString(),
link: event.payload.pull_request.html_url,
text: event.payload.pull_request.title,
collaborated_with: [...othersArray],
});
for (const user of collaboratorArray) {
const others = new Set(collaborators);
const othersArray = Array.from(others);

others.delete(user);

appendEvent(user, {
type: "pr_collaborated",
title: `${event.repo.name}#${event.payload.pull_request.number}`,
time: eventTime.toISOString(),
link: event.payload.pull_request.html_url,
text: event.payload.pull_request.title,
collaborated_with: [...othersArray],
});
}
}
}
Expand Down
1 change: 1 addition & 0 deletions scraper/src/github-scraper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Comment {
}

export interface PullRequest {
base:{ref:string};
html_url: string;
user: Actor;
title: string;
Expand Down
Loading