diff --git a/index.ts b/index.ts index c7e03661..dae2fa06 100644 --- a/index.ts +++ b/index.ts @@ -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" @@ -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 = {} - 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( diff --git a/lib/data-retrieval/getRecentIssues.ts b/lib/data-retrieval/getRecentIssues.ts new file mode 100644 index 00000000..02de2707 --- /dev/null +++ b/lib/data-retrieval/getRecentIssues.ts @@ -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) +} diff --git a/tests/test-pr-scoring.test.ts b/tests/test-pr-scoring.test.ts index d3faf8ed..13de6a53 100644 --- a/tests/test-pr-scoring.test.ts +++ b/tests/test-pr-scoring.test.ts @@ -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[] = [] const stats: ContributorStats = { reviewsReceived: 0, @@ -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", () => { @@ -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, @@ -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", () => {