Skip to content

Commit

Permalink
Merge pull request #27 from ShiboSoftwareDev/main
Browse files Browse the repository at this point in the history
count approvals and rejections as tiny contribution points
  • Loading branch information
ShiboSoftwareDev authored Dec 31, 2024
2 parents c00d70e + 42dc435 commit 89c9283
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
27 changes: 27 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export async function generateOverview(startDate: string) {
reviewsReceived: 0,
rejectionsReceived: 0,
approvalsReceived: 0,
approvalsGiven: 0,
rejectionsGiven: 0,
prsOpened: 0,
prsMerged: 0,
issuesCreated: 0,
Expand All @@ -48,6 +50,31 @@ export async function generateOverview(startDate: string) {
contributorData[contributor].approvalsReceived += pr.approvalsReceived
contributorData[contributor].prsOpened += 1

if (pr.reviewsByUser) {
Object.entries(pr.reviewsByUser).forEach(
([reviewer, reviewerStats]) => {
if (!contributorData[reviewer]) {
contributorData[reviewer] = {
reviewsReceived: 0,
rejectionsReceived: 0,
approvalsReceived: 0,
approvalsGiven: 0,
rejectionsGiven: 0,
prsOpened: 0,
prsMerged: 0,
issuesCreated: 0,
bountiedIssuesCount: 0,
bountiedIssuesTotal: 0,
}
}
contributorData[reviewer].approvalsGiven +=
reviewerStats.approvalsGiven
contributorData[reviewer].rejectionsGiven +=
reviewerStats.rejectionsGiven
},
)
}

if (pr.isClosed && pr.merged_at)
contributorData[contributor].prsMerged += 1
}
Expand Down
9 changes: 8 additions & 1 deletion lib/generateMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export async function generateMarkdown(
{} as Record<string, Record<string, number>>,
)

// Then add bounty points separately for each contributor
Object.entries(contributorEffort).forEach(([contributor, effort]) => {
const bountiedAmount =
contributorIdToStatsMap[contributor]?.bountiedIssuesTotal || 0
Expand All @@ -86,6 +85,12 @@ export async function generateMarkdown(
)
// Add to score (minor contributions are worth 2 points each)
effort.score += minorContributionsFromBounties * 2

const approvalsGiven =
contributorIdToStatsMap[contributor]?.approvalsGiven || 0
const rejectionsGiven =
contributorIdToStatsMap[contributor]?.rejectionsGiven || 0
effort.score += Math.min(approvalsGiven + rejectionsGiven, 20)
})

const sortedContributors = Object.entries(contributorEffort).sort(
Expand Down Expand Up @@ -133,6 +138,8 @@ export async function generateMarkdown(
"Reviews Received": "reviewsReceived",
"Approvals Received": "approvalsReceived",
"Rejections Received": "rejectionsReceived",
Approvals: "approvalsGiven",
Rejections: "rejectionsGiven",
"PRs Opened": "prsOpened",
"PRs Merged": "prsMerged",
"Issues Created": "issuesCreated",
Expand Down
19 changes: 18 additions & 1 deletion lib/getAllPRs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { octokit } from "lib/sdks"
import type { PullRequest, PullRequestWithReviews } from "./types"
import type { PullRequestWithReviews, ReviewerStats } from "./types"

export async function getAllPRs(
repo: string,
Expand Down Expand Up @@ -66,11 +66,28 @@ export async function getAllPRs(
(review) => review.state === "CHANGES_REQUESTED",
).length

const reviewsByUser = reviews.reduce<Record<string, ReviewerStats>>(
(acc, review) => {
const reviewer = review.user.login
if (!acc[reviewer]) {
acc[reviewer] = { approvalsGiven: 0, rejectionsGiven: 0 }
}
if (review.state === "APPROVED") {
acc[reviewer].approvalsGiven++
} else if (review.state === "CHANGES_REQUESTED") {
acc[reviewer].rejectionsGiven++
}
return acc
},
{},
)

return {
...pr,
reviewsReceived,
rejectionsReceived,
approvalsReceived,
reviewsByUser,
isClosed: pr.state === "closed",
} as PullRequestWithReviews
}),
Expand Down
8 changes: 8 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export interface ReviewerStats {
approvalsGiven: number
rejectionsGiven: number
}

export interface ContributorStats {
reviewsReceived: number
rejectionsReceived: number
Expand All @@ -8,6 +13,8 @@ export interface ContributorStats {
bountiedIssuesCount?: number
bountiedIssuesTotal?: number
score?: number
approvalsGiven: number
rejectionsGiven: number
}

export interface PullRequest {
Expand All @@ -31,6 +38,7 @@ export interface PullRequestWithReviews extends PullRequest {
rejectionsReceived: number
approvalsReceived: number
isClosed: boolean
reviewsByUser?: Record<string, ReviewerStats>
}

export interface AnalyzedPR {
Expand Down

0 comments on commit 89c9283

Please sign in to comment.