From ef742e0204228c05f1408580bdf6dda4908811b1 Mon Sep 17 00:00:00 2001 From: Samuel Aktar Laskar Date: Sat, 30 Mar 2024 00:51:17 +0530 Subject: [PATCH] Scaling points for PRs based on size of PR (#219) --- lib/api.ts | 63 ++++++++++++++++++++++++++++--------------- lib/types.ts | 1 + scraper/src/github.py | 11 ++++++++ 3 files changed, 54 insertions(+), 21 deletions(-) diff --git a/lib/api.ts b/lib/api.ts index 7f501f2e..2d4fc904 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -15,6 +15,7 @@ const points = { issue_opened: 4, eod_update: 2, pr_opened: 1, + no_of_linked_issues: 1, pr_merged: 7, pr_collaborated: 2, issue_closed: 0, @@ -24,6 +25,7 @@ const points = { // Reviewing a PR would get 4 points // Finding a bug would add up to 4 points // Opening a PR would give a single point and merging it would give you the other 7 points, making 8 per PR +// For each linked issue in pr body, points would increase by 1. // Updating the EOD would get 2 points per day and additional 20 for regular daily updates plus 10 for just missing one function formatSlug(slug: string) { @@ -115,9 +117,17 @@ export async function getContributorBySlug(file: string, detail = false) { return { activity: [ ...acc.activity, - { ...activity, points: points[activity.type] || 0 }, + { + ...activity, + points: + (points[activity.type] || 0) + + (activity.no_of_linked_issues || 0), + }, ], - points: acc.points + (points[activity.type] || 0), + points: + acc.points + + (points[activity.type] || 0) + + (activity.no_of_linked_issues || 0), comment_created: acc.comment_created + (activity.type === "comment_created" ? 1 : 0), eod_update: acc.eod_update + (activity.type === "eod_update" ? 1 : 0), @@ -218,6 +228,16 @@ function getCalendarData(activity: Activity[]) { } else { acc[date][activity.type] = 1; } + if (!acc[date]["points"]) { + acc[date]["points"] = points[activity.type]; + } else { + acc[date]["points"] += points[activity.type]; + if (activity.type === "pr_opened") { + acc[date]["points"] += + (activity.no_of_linked_issues ?? 0) * points["no_of_linked_issues"]; + } + } + if (!acc[date].types.includes(activity.type)) { acc[date].types.push(activity.type); // console.log(activity.type); @@ -248,29 +268,30 @@ function getCalendarData(activity: Activity[]) { }); } -const HIGHLIGHT_KEYS = [ - "eod_update", - "comment_created", - "pr_opened", - "pr_reviewed", - "pr_merged", - "pr_collaborated", - "issue_assigned", - "issue_opened", -] as const; +// const HIGHLIGHT_KEYS = [ +// "eod_update", +// "comment_created", +// "pr_opened", +// "pr_reviewed", +// "pr_merged", +// "pr_collaborated", +// "issue_assigned", +// "issue_opened", +// ] as const; -const computePoints = ( - calendarDataEntry: Highlights, - initialPoints: number, -) => { - return HIGHLIGHT_KEYS.map( - (key) => points[key] * (calendarDataEntry[key] ?? 0), - ).reduce((a, b) => a + b, initialPoints); -}; +// const computePoints = ( +// calendarDataEntry: Highlights, +// initialPoints: number, +// ) => { +// return HIGHLIGHT_KEYS.map( +// (key) => points[key] * (calendarDataEntry[key] ?? 0), +// ).reduce((a, b) => a + b, initialPoints); +// }; const HighlightsReducer = (acc: Highlights, day: Highlights) => { return { - points: computePoints(day, acc.points), + // points: computePoints(day, acc.points), + points: acc.points + (day.points ?? 0), eod_update: acc.eod_update + (day.eod_update ?? 0), comment_created: acc.comment_created + (day.comment_created ?? 0), pr_opened: acc.pr_opened + (day.pr_opened ?? 0), diff --git a/lib/types.ts b/lib/types.ts index d5cabe34..0566d36d 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -76,6 +76,7 @@ export interface Activity { text: string; collaborated_with?: string[]; turnaround_time?: number; + no_of_linked_issues?: number; } export interface OpenPr { diff --git a/scraper/src/github.py b/scraper/src/github.py index 797a5899..20857837 100755 --- a/scraper/src/github.py +++ b/scraper/src/github.py @@ -71,6 +71,14 @@ def append(self, user, event): "authored_issue_and_pr": [], } + def parse_linked_issues(self, pr_body): + if isinstance(pr_body, str): + pattern = r"#(\d+)" + matches = re.findall(pattern, pr_body) + return len(set(matches)) + else: + return 0 + def parse_event(self, event, event_time): user = event["actor"]["login"] try: @@ -116,6 +124,8 @@ def parse_event(self, event, event_time): ) elif event["type"] == "PullRequestEvent": + pr_body = event["payload"]["pull_request"]["body"] + no_of_linked_issues = self.parse_linked_issues(pr_body) if event["payload"]["action"] == "opened": self.append( user, @@ -125,6 +135,7 @@ def parse_event(self, event, event_time): "time": event_time, "link": event["payload"]["pull_request"]["html_url"], "text": event["payload"]["pull_request"]["title"], + "no_of_linked_issues" : no_of_linked_issues }, )