Skip to content

Commit

Permalink
fix: Contributions count parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
firejune committed Nov 16, 2023
1 parent fb90e32 commit cb384e7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/app/api/v1/[username]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ type Params = {
export async function GET(request: NextRequest, { params }: Params) {
console.log('GET', `/api/v1/${params.username}`)

const data = await fetch(`https://github.com/${params.username}`)
const $ = load(await data.text())
const data = await fetch(`https://github.com/users/${params.username}/contributions`)
const text = await data.text()
const $ = load(text)
const $days = $('table.ContributionCalendar-grid td.ContributionCalendar-day')
const contribText = $('.js-yearly-contributions h2')
.text()
Expand All @@ -36,7 +37,13 @@ export async function GET(request: NextRequest, { params }: Params) {
const date = dateAttr.split('-').map(d => parseInt(d, 10))
const value = {
date: dateAttr,
count: Number($day.text().split(' ')[0]) || 0,
count:
parseInt(
$(`tool-tip[for=${$day.attr('id')}]`)
.text()
.split(' ')[0],
10,
) || 0,
intensity: Number($day.attr('data-level')) || 0,
}
return { date, value }
Expand Down

0 comments on commit cb384e7

Please sign in to comment.