Skip to content

Commit

Permalink
add type for commits
Browse files Browse the repository at this point in the history
  • Loading branch information
pettinarip committed Jan 22, 2024
1 parent 8e9a590 commit 4daba77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/hooks/useClientSideGitHubContributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { join } from "path"

import { useEffect, useState } from "react"

import type { Author, FileContributorsState } from "@/lib/types"
import type { Author, Commit, FileContributorsState } from "@/lib/types"

import {
CONTENT_DIR,
Expand All @@ -17,14 +17,14 @@ export const gitHubAuthHeaders = {
}),
}

const fetchGitHubCommits = async (filePath: string): Promise<any[]> => {
const fetchGitHubCommits = async (filePath: string): Promise<Commit[]> => {
const url = new URL(GITHUB_COMMITS_URL)
url.searchParams.set("path", filePath)

try {
const response = await fetch(url, gitHubAuthHeaders)
if (!response.ok) throw new Error(response.statusText)
return await response.json()
return (await response.json()) as Commit[]
} catch (error: unknown) {
if (error instanceof Error) {
console.error(filePath, error.message)
Expand Down
14 changes: 14 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ export type LocaleContributions = {
}

// GitHub contributors
export type Commit = {
commit: {
author: {
name: string
email: string
}
}
author: {
avatar_url: string
login: string
html_url: string
}
}

export type Author = {
name: string
email: string
Expand Down

0 comments on commit 4daba77

Please sign in to comment.