Skip to content

Commit 4806c1a

Browse files
committed
refactor issue fetching
1 parent 4b43e5d commit 4806c1a

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

index.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { getMergedPRs } from "lib/data-retrieval/getMergedPRs"
99
import { getAllPRs } from "lib/data-retrieval/getAllPRs"
1010
import { getBountiedIssues } from "lib/data-retrieval/getBountiedIssues"
11-
import { getIssuesCreated } from "lib/data-retrieval/getIssuesCreated"
11+
import { getRecentIssues } from "lib/data-retrieval/getRecentIssues"
1212
import { getLastWednesday } from "lib/ai/date-utils"
1313
import { analyzePRWithAI } from "lib/ai-stuff/analyze-pr"
1414
import { processDiscussionsForContributors } from "lib/data-retrieval/processDiscussions"
@@ -179,31 +179,40 @@ export async function generateOverview(startDate: string) {
179179
// Wait for all bounty fetching to complete
180180
await Promise.all(bountiedIssuesPromises)
181181

182-
const getIssuesCreatedPromises = Object.keys(contributorData).map(
183-
async (contributor) => {
184-
const { totalIssues, majorIssues } = await getIssuesCreated(
185-
repo,
186-
contributor,
187-
startDateString,
188-
)
182+
const recentIssues = await getRecentIssues(repo, startDateString)
183+
const issuesByAuthor: Record<string, { total: number; major: number }> = {}
189184

190-
console.log(
191-
`Processed issues created for ${contributor} - totalIssues: ${totalIssues} - majorIssues: ${majorIssues} in ${repo}`,
185+
for (const issue of recentIssues) {
186+
const author = issue.user?.login
187+
if (!author || !contributorData[author]) continue
188+
if (!issuesByAuthor[author]) {
189+
issuesByAuthor[author] = { total: 0, major: 0 }
190+
}
191+
issuesByAuthor[author].total++
192+
if (
193+
issue.labels.some(
194+
(label) =>
195+
typeof label === "object" && label.name?.toLowerCase() === "major",
192196
)
197+
) {
198+
issuesByAuthor[author].major++
199+
}
200+
}
193201

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

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

201-
contributorData[contributor].score =
202-
(contributorData[contributor].score || 0) + scoreFromIssues
203-
},
204-
)
210+
const scoreFromIssues =
211+
Math.min(counts.total, 5) * 0.5 + counts.major * 1.5
205212

206-
await Promise.all(getIssuesCreatedPromises)
213+
contributorData[contributor].score =
214+
(contributorData[contributor].score || 0) + scoreFromIssues
215+
}
207216
}
208217
// Process GitHub Discussions for all contributors
209218
const allGithubDiscussions = await processDiscussionsForContributors(
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { octokit } from "lib/sdks"
2+
3+
export async function getRecentIssues(repo: string, since: string) {
4+
const [owner, repoName] = repo.split("/")
5+
const { data } = await octokit.issues.listForRepo({
6+
owner,
7+
repo: repoName,
8+
state: "all",
9+
sort: "created",
10+
direction: "desc",
11+
per_page: 100,
12+
since,
13+
})
14+
15+
return data.filter((issue) => !issue.pull_request)
16+
}

tests/test-pr-scoring.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ it("should count distinct PRs reviewed", () => {
2222
expect(result.score).toBe(2) // Should get 2 points for reviewing 2 distinct PRs
2323
})
2424

25-
it("should cap review points at 10", () => {
25+
it("should cap review points at 5", () => {
2626
const mockPRs: AnalyzedPR[] = []
2727
const stats: ContributorStats = {
2828
reviewsReceived: 0,
@@ -39,7 +39,7 @@ it("should cap review points at 10", () => {
3939
}
4040

4141
const result = getContributorScore(mockPRs, stats)
42-
expect(result.score).toBe(10) // Should be capped at 10 points
42+
expect(result.score).toBe(5) // Should be capped at 5 points
4343
})
4444

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

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

123123
const result = getContributorScore(mockPRs, contributorStats)
124-
expect(result.score).toBe(10) // Should be capped at 10 points
124+
expect(result.score).toBe(5) // Should be capped at 5 points
125125
})
126126

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

0 commit comments

Comments
 (0)