-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PR velocity to profile page (#111)
* add date-fns library for proper date calculations * add getRelativeDays as a new date util * fetch PR data and calculate user PR Velocity * add PR velocity in profile page * remove getContributorPullRequestVelocity from fetchOpenSaucedApiData.ts * add IUserPR type for PR API responses * add getUserPRVelocity utility function * use getUserPRVelocity function in the profile page * export IUserPR from types
- Loading branch information
Showing
7 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export interface IUserPR { | ||
readonly title: string; | ||
readonly author_login: string; | ||
readonly state: string; | ||
readonly created_at: string; | ||
readonly closed_at: string; | ||
readonly merged_at: string; | ||
readonly updated_at: string; | ||
readonly filesCount: number; | ||
linesCount: number; | ||
readonly merged: boolean; | ||
readonly draft: boolean; | ||
readonly full_name: string; | ||
readonly number: number; | ||
readonly additions: number; | ||
readonly deletions: number; | ||
readonly changed_files: number; | ||
readonly repo_id: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const getRelativeDays = (days: number) => { | ||
if (days === 0) { | ||
return "-"; | ||
} | ||
|
||
if (days >= 365) { | ||
return `${Math.floor(days / 365)}y`; | ||
} | ||
|
||
if (days > 30 && days < 365) { | ||
return `${Math.floor(days / 30)}mo`; | ||
} | ||
|
||
return `${days}d`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { differenceInDays } from "date-fns"; | ||
import { IUserPR } from "../ts/types"; | ||
|
||
export const getUserPRVelocity = ((prDetails: IUserPR[]) => { | ||
const mergedPRs = prDetails.filter((prState: IUserPR) => prState.state.toLowerCase() === "merged"); | ||
|
||
const totalDays = mergedPRs.reduce((total: number, pr: IUserPR) => { | ||
const daysBetween = differenceInDays(new Date(pr.closed_at), new Date(pr.created_at)); | ||
|
||
return (total += daysBetween); | ||
}, 0); | ||
|
||
const averageVelocity: number = mergedPRs.length > 0 ? Math.round(totalDays / mergedPRs.length) : 0; | ||
|
||
return averageVelocity; | ||
}); |