Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
49 changes: 29 additions & 20 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { getMergedPRs } from "lib/data-retrieval/getMergedPRs"
import { getAllPRs } from "lib/data-retrieval/getAllPRs"
import { getBountiedIssues } from "lib/data-retrieval/getBountiedIssues"
import { getIssuesCreated } from "lib/data-retrieval/getIssuesCreated"
import { getRecentIssues } from "lib/data-retrieval/getRecentIssues"
import { getLastWednesday } from "lib/ai/date-utils"
import { analyzePRWithAI } from "lib/ai-stuff/analyze-pr"
import { processDiscussionsForContributors } from "lib/data-retrieval/processDiscussions"
Expand Down Expand Up @@ -179,31 +179,40 @@ export async function generateOverview(startDate: string) {
// Wait for all bounty fetching to complete
await Promise.all(bountiedIssuesPromises)

const getIssuesCreatedPromises = Object.keys(contributorData).map(
async (contributor) => {
const { totalIssues, majorIssues } = await getIssuesCreated(
repo,
contributor,
startDateString,
)
const recentIssues = await getRecentIssues(repo, startDateString)
const issuesByAuthor: Record<string, { total: number; major: number }> = {}

console.log(
`Processed issues created for ${contributor} - totalIssues: ${totalIssues} - majorIssues: ${majorIssues} in ${repo}`,
for (const issue of recentIssues) {
const author = issue.user?.login
if (!author || !contributorData[author]) continue
if (!issuesByAuthor[author]) {
issuesByAuthor[author] = { total: 0, major: 0 }
}
issuesByAuthor[author].total++
if (
issue.labels.some(
(label) =>
typeof label === "object" && label.name?.toLowerCase() === "major",
)
) {
issuesByAuthor[author].major++
}
}

contributorData[contributor].issuesCreated =
(contributorData[contributor].issuesCreated || 0) + totalIssues
for (const [contributor, counts] of Object.entries(issuesByAuthor)) {
console.log(
`Processed issues created for ${contributor} - totalIssues: ${counts.total} - majorIssues: ${counts.major} in ${repo}`,
)

// Calculate score based on issues created
const scoreFromIssues =
Math.min(totalIssues, 5) * 0.5 + majorIssues * 1.5
contributorData[contributor].issuesCreated =
(contributorData[contributor].issuesCreated || 0) + counts.total

contributorData[contributor].score =
(contributorData[contributor].score || 0) + scoreFromIssues
},
)
const scoreFromIssues =
Math.min(counts.total, 5) * 0.5 + counts.major * 1.5

await Promise.all(getIssuesCreatedPromises)
contributorData[contributor].score =
(contributorData[contributor].score || 0) + scoreFromIssues
}
}
// Process GitHub Discussions for all contributors
const allGithubDiscussions = await processDiscussionsForContributors(
Expand Down
16 changes: 16 additions & 0 deletions lib/data-retrieval/getRecentIssues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { octokit } from "lib/sdks"

export async function getRecentIssues(repo: string, since: string) {
const [owner, repoName] = repo.split("/")
const { data } = await octokit.issues.listForRepo({
owner,
repo: repoName,
state: "all",
sort: "created",
direction: "desc",
per_page: 100,
since,
})

return data.filter((issue) => !issue.pull_request)
}
8 changes: 4 additions & 4 deletions tests/test-pr-scoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ it("should count distinct PRs reviewed", () => {
expect(result.score).toBe(2) // Should get 2 points for reviewing 2 distinct PRs
})

it("should cap review points at 10", () => {
it("should cap review points at 5", () => {
const mockPRs: AnalyzedPR[] = []
Comment on lines +25 to 26
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test file appears to have multiple test definitions using it() blocks. According to the project's testing standards, each test file should contain at most one test() call, with additional tests split into separate numbered files. Consider refactoring these tests into multiple files (e.g., test-pr-scoring-1.test.ts, test-pr-scoring-2.test.ts, etc.) to align with the established testing pattern.

Spotted by Diamond (based on custom rules)

Is this helpful? React 👍 or 👎 to let us know.

const stats: ContributorStats = {
reviewsReceived: 0,
Expand All @@ -39,7 +39,7 @@ it("should cap review points at 10", () => {
}

const result = getContributorScore(mockPRs, stats)
expect(result.score).toBe(10) // Should be capped at 10 points
expect(result.score).toBe(5) // Should be capped at 5 points
})

it("should handle edge cases", () => {
Expand Down Expand Up @@ -104,7 +104,7 @@ describe("distinct PRs reviewed functionality", () => {
expect(result.score).toBe(1) // Should get 1 point for one distinct PR reviewed
})

it("should cap review points at 10 even with many distinct PRs", () => {
it("should cap review points at 5 even with many distinct PRs", () => {
const mockPRs: AnalyzedPR[] = []
const contributorStats: ContributorStats = {
reviewsReceived: 0,
Expand All @@ -121,7 +121,7 @@ describe("distinct PRs reviewed functionality", () => {
}

const result = getContributorScore(mockPRs, contributorStats)
expect(result.score).toBe(10) // Should be capped at 10 points
expect(result.score).toBe(5) // Should be capped at 5 points
})

it("should handle edge case of no reviews", () => {
Expand Down