Skip to content

Commit cd34641

Browse files
committed
fix: type errors in top three users fetch
1 parent 2991591 commit cd34641

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

utils/fetchTopThreeUsersByPullRequests.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function fetchTopThreeUsersByPullRequests(repoPath: string) {
1010
console.log('Using GitHub token for authentication')
1111
}
1212

13-
let url = `https://api.github.com/repos/fork-commit-merge/fork-commit-merge/pulls?state=closed&per_page=100`
13+
let url: string | null = `https://api.github.com/repos/fork-commit-merge/fork-commit-merge/pulls?state=closed&per_page=100`
1414
const userContributions = new Map()
1515
let requestCount = 0
1616
const MAX_REQUESTS = 10
@@ -20,7 +20,7 @@ export async function fetchTopThreeUsersByPullRequests(repoPath: string) {
2020
const controller = new AbortController()
2121
const timeout = setTimeout(() => controller.abort(), 15000)
2222

23-
const response = await fetch(url, {
23+
const response: Response = await fetch(url, {
2424
headers,
2525
signal: controller.signal
2626
})
@@ -54,13 +54,13 @@ export async function fetchTopThreeUsersByPullRequests(repoPath: string) {
5454
const nextLink = linkHeader
5555
? linkHeader.split(',').find((s: string) => s.includes('rel="next"'))
5656
: null
57-
url = nextLink ? nextLink.match(/<(.*)>/)?.[1] : null
57+
url = nextLink ? (RegExp(/<(.*)>/).exec(nextLink)?.[1] ?? null) : null
5858

5959
if (url) {
6060
await new Promise(resolve => setTimeout(resolve, 1000))
6161
}
6262
} catch (error) {
63-
if (error.name === 'AbortError') {
63+
if (error instanceof Error && error.name === 'AbortError') {
6464
console.log('Request timed out')
6565
} else if (error instanceof Response && error.status === 403) {
6666
console.log('Rate limit hit, pausing for 10 seconds before retry')
@@ -88,4 +88,3 @@ export async function fetchTopThreeUsersByPullRequests(repoPath: string) {
8888
return []
8989
}
9090
}
91-

0 commit comments

Comments
 (0)