-
Notifications
You must be signed in to change notification settings - Fork 86
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
Conversation
✅ Deploy Preview for leaderboard-develop ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
async function fetchdefaultbranch(org: string, repo: string) { | ||
try { | ||
const { data } = await octokit.request('GET /repos/{owner}/{repo}', { | ||
owner: org, | ||
repo: repo, | ||
}); | ||
return data.default_branch; | ||
} catch (e) { | ||
console.error( | ||
`Error fetching default branch for organisation ${org} /${repo} `, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we maintain a cache of the results? So that we don't need to keep hitting GitHub's APIs for every PRs that collaboration event is to be added?
if (collaborators.size > 1) { | ||
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], | ||
}); | ||
if (event.payload.pull_request.base.ref === default_branch) { | ||
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], | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the check can be merged along with line before like if (collaborators.size > 1 && event.payload... === default branch
right?
scraper/src/github-scraper/types.ts
Outdated
@@ -15,6 +15,7 @@ interface Comment { | |||
} | |||
|
|||
export interface PullRequest { | |||
base: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add proper types; any is not allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes naming convention and managing cache for DefaultBranch to avoid extra api call and changes type from any
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; |
There was a problem hiding this comment.
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?
here before changes this issue persist at url: http://localhost:3000/contributors/gigincg
after changes