Skip to content

Commit 2edfed0

Browse files
authored
Merge pull request #243 from ethereum/remove-axios
Remove axios calls
2 parents a3a41a2 + 80beb6b commit 2edfed0

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/lib/api/ghRepoData.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import axios from "axios"
2-
31
import { Framework } from "@/lib/interfaces"
42

53
import EthDiamondBlackImage from "@/public/assets/eth-diamond-black.png"
@@ -128,25 +126,38 @@ export const ghRepoData = async (githubUrl: string) => {
128126
const split = githubUrl.split("/")
129127
const repoOwner = split[split.length - 2]
130128
const repoName = split[split.length - 1]
131-
const repoData = await axios.get(
129+
const repoReq = await fetch(
132130
`https://api.github.com/repos/${repoOwner}/${repoName}`,
133131
{
134132
headers: {
135133
Authorization: `Bearer ${process.env.GITHUB_TOKEN_READ_ONLY}`,
136134
},
137135
}
138136
)
139-
const languageData = await axios.get(
137+
if (!repoReq.ok) {
138+
console.log(repoReq.status, repoReq.statusText)
139+
throw new Error("Failed to fetch Github repo data")
140+
}
141+
142+
const repoData = await repoReq.json()
143+
144+
const languageReq = await fetch(
140145
`https://api.github.com/repos/${repoOwner}/${repoName}/languages`,
141146
{
142147
headers: {
143148
Authorization: `Bearer ${process.env.GITHUB_TOKEN_READ_ONLY}`,
144149
},
145150
}
146151
)
152+
if (!languageReq.ok) {
153+
console.log(languageReq.status, languageReq.statusText)
154+
throw new Error("Failed to fetch Github repo language data")
155+
}
156+
const languageData = await languageReq.json()
157+
147158
return {
148-
starCount: repoData.data.stargazers_count,
149-
languages: Object.keys(languageData.data),
159+
starCount: repoData.stargazers_count,
160+
languages: Object.keys(languageData),
150161
}
151162
}
152163

src/scripts/crowdin/reports/reportsHelpers.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// TODO: Refactor to fetch and remove axios package
2-
import axios, { AxiosResponse } from "axios"
31
import { ReportsModel } from "@crowdin/crowdin-api-client"
42

53
import {
@@ -107,10 +105,11 @@ export async function downloadReport(
107105
`${crowdinLangCode}—Retrieved JSON URL for report of file ID ${fileId}`
108106
)
109107

110-
const reportData: AxiosResponse<ReportData> = await axios.get(jsonUrl)
108+
const reportReq = await fetch(jsonUrl)
111109
console.log(`Downloaded report data for file ID ${fileId}`)
110+
const reportData: ReportData = await reportReq.json()
112111

113-
await saveReportDataToJson(reportData.data, fileId, crowdinLangCode)
112+
await saveReportDataToJson(reportData, fileId, crowdinLangCode)
114113
console.log(`Saved report data for file ID ${fileId} to JSON file`)
115114
} catch (error: unknown) {
116115
if (error instanceof Error) {

0 commit comments

Comments
 (0)