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

Add: Identify First-Time PR Contributors for Last Week #576

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

JavidSumra
Copy link

Fixes #153

Description

This PR implements logic to identify first-time PR contributors whose first pr_merged activity occurred within the specified time frame (last week). It ensures accuracy by filtering contributors based on their activities and checks if their first contribution happened during last week.

Screenshots / Outputs

image

Copy link

netlify bot commented Dec 25, 2024

👷 Deploy request for leaderboard-develop pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit abb4350

Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

instead of directly keeping the logic here, let's add it to the contributor object itself. so that this value isNewContributor could be reused everywhere else when needed.

@rithviknishad
Copy link
Member

Also not a fan of the design. Let's not have @, seems out of context. Also placing above the name doesn't seem nice.

@JavidSumra
Copy link
Author

instead of directly keeping the logic here, let's add it to the contributor object itself. so that this value isNewContributor could be reused everywhere else when needed.

Shall I add this logic in getContributorBySlug function?

@rithviknishad
Copy link
Member

yup! that's the right place to be

lib/api.ts Outdated Show resolved Hide resolved
@JavidSumra
Copy link
Author

@rithviknishad can you please review this PR?

lib/api.ts Outdated Show resolved Hide resolved
lib/api.ts Outdated Show resolved Hide resolved
Comment on lines +29 to +34
const topContributors = [
...contributors.filter((contributor) => contributor.isNewContributor),
...contributors
.filter((contributor) => !contributor.isNewContributor)
.slice(0, 8),
];
Copy link
Member

Choose a reason for hiding this comment

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

use Set instead to handle duplicates.

Copy link
Author

Choose a reason for hiding this comment

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

Could you please explain why a set is needed in this case? We're simply adding the top contributors to highlight them for the week, right? Since the isNewContributor attribute prevents duplication, isn't that sufficient?

Copy link
Member

@rithviknishad rithviknishad Jan 1, 2025

Choose a reason for hiding this comment

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

sufficient yes, but it's just cleaner than too many spread operations and filters. more readable the code is, the better.

Copy link
Author

Choose a reason for hiding this comment

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

I believe spread operators and filters are necessary since it’s an array of objects, and sets wouldn’t be usable in this case for the filtering process, right?

app/page.tsx Outdated Show resolved Hide resolved

const firstActivity = activity
.filter((act) => act.type === "pr_merged")
.sort((a, b) => compareAsc(new Date(a.time), new Date(b.time)))[0];
Copy link
Member

Choose a reason for hiding this comment

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

why wrap in date?

Suggested change
.sort((a, b) => compareAsc(new Date(a.time), new Date(b.time)))[0];
.sort((a, b) => compareAsc(a.time, b.time))[0];

Copy link
Author

@JavidSumra JavidSumra Jan 1, 2025

Choose a reason for hiding this comment

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

@rithviknishad compareAsc expects arguments of type Date or number, so I wrapped the value in a Date instead of converting it from a string to a number.

lib/api.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlight new contributors that have made their first contribution in the past 1 week in landing page
2 participants