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

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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
17 changes: 12 additions & 5 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export default async function Home() {
const discussions = await fetchGithubDiscussion(5);
const startDate = parseISO(env.NEXT_PUBLIC_ORG_START_DATE);

const topContributors = [
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
...contributors.filter((contributor) => contributor.isNewContributor),
...contributors
.filter((contributor) => !contributor.isNewContributor)
.slice(0, 8),
];
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

return (
<div className="min-h-screen bg-background text-foreground">
<section className="bg-background">
Expand Down Expand Up @@ -166,24 +173,24 @@ export default async function Home() {
role="list"
className="mt-4 space-y-4 sm:grid sm:grid-cols-2 sm:gap-6 sm:space-y-0 lg:grid-cols-2 lg:gap-8"
>
{contributors
.slice(0, 8)
.map((contributor: any, index: number) => {
{topContributors.map(
(contributor: any, index: number) => {
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
return (
<InfoCard
key={index}
contributor={contributor}
isClickable
/>
);
})}
},
)}
</ul>
<Link
className="flex w-fit items-center gap-1 rounded px-3 py-2 text-secondary-400 underline underline-offset-2 transition-all duration-200 ease-in-out hover:gap-2 hover:text-primary-200 sm:justify-center lg:ml-auto"
href={"/people"}
>
{contributors.length > 8
? `${contributors.length - 8} contributors more`
? `${contributors.length - topContributors.length} contributors more`
: "Show all contributors"}
<MdOutlineArrowForwardIos />
</Link>
Expand Down
13 changes: 10 additions & 3 deletions components/contributors/InfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default function InfoCard({
contributor: Contributor;
rank?: number | null;
isClickable?: boolean;
isFirstTimeContributor?: boolean;
}) {
return (
<div
Expand Down Expand Up @@ -59,9 +60,15 @@ export default function InfoCard({
#{rank}
</span>
</Link>
<p className="text-sm text-secondary-400 md:text-base">
{contributor.title}
</p>
{contributor.isNewContributor ? (
<p className="inline-block rounded-full text-sm text-primary-400 md:text-base">
New Contributor 🎉
</p>
) : (
<p className="text-sm text-secondary-400 md:text-base">
{contributor.title}
</p>
)}
</div>

<ul role="list" className="mt-4 flex items-center space-x-4">
Expand Down
16 changes: 16 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { padZero } from "./utils";
import { readFile, readdir } from "fs/promises";
import { existsSync } from "fs";
import { getGithubDiscussions } from "@/lib/discussion";
import { isAfter, sub } from "date-fns";

const root = join(process.cwd(), "data-repo/contributors");
const slackRoot = join(process.cwd(), "data-repo/data/slack");
Expand Down Expand Up @@ -180,6 +181,20 @@ export async function getContributorBySlug(file: string, detail = false) {

const calendarData = getCalendarData(weightedActivity.activity);

const isNewContributor = (() => {
const { activity } = activityData;

const aWeekAgo = sub(new Date(), { days: 7 });

const firstActivity = activity
.filter((act) => act.type === "pr_merged")
.sort(
(a, b) => new Date(a.time).getTime() - new Date(b.time).getTime(),
)[0];
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved

return isAfter(new Date(firstActivity?.time), aWeekAgo);
JavidSumra marked this conversation as resolved.
Show resolved Hide resolved
})();

const summarize = (start: Date, end: Date) => {
return calendarData
.filter((day) => {
Expand All @@ -194,6 +209,7 @@ export async function getContributorBySlug(file: string, detail = false) {
slug: formatSlug(file),
path: fullPath,
content: content,
isNewContributor,
activityData: {
...activityData,
activity: weightedActivity.activity,
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Contributor {
joining_date: string;
role: "core" | "intern" | "operations" | "contributor";
courses_completed: string[];
isNewContributor: boolean;
}

export interface ActivityData {
Expand Down