mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-08-06 14:24:23 +00:00
fix: Make WakaTime card compatible with new API (#2707)
* fix: Make WakaTime card compatible with new API This commit makes sure that the WakaTime card works with the new WakaTime API. See https://github.com/anuraghazra/github-readme-stats/issues/2698 for more information. * fix: fix chinese simplified translations * fix: improve WakaTime range order * test: fix WakaTime tests * refactor: remove WakaTime range loop * refactor: remove redundant WakaTime call * test: fix e2e tests Co-authored-by: Hakula Chen <i@hakula.xyz> --------- Co-authored-by: Hakula Chen <i@hakula.xyz>
This commit is contained in:
@@ -1,29 +1,29 @@
|
||||
import axios from "axios";
|
||||
import { MissingParamError } from "../common/utils.js";
|
||||
import { CustomError, MissingParamError } from "../common/utils.js";
|
||||
import { I18n } from "../common/I18n.js";
|
||||
|
||||
/**
|
||||
* WakaTime data fetcher.
|
||||
*
|
||||
* @param {{username: string, api_domain: string, range: string}} props Fetcher props.
|
||||
* @param {{username: string, api_domain: string }} props Fetcher props.
|
||||
* @returns {Promise<WakaTimeData>} WakaTime data response.
|
||||
*/
|
||||
const fetchWakatimeStats = async ({ username, api_domain, range }) => {
|
||||
const fetchWakatimeStats = async ({ username, api_domain }) => {
|
||||
if (!username) throw new MissingParamError(["username"]);
|
||||
|
||||
try {
|
||||
const { data } = await axios.get(
|
||||
`https://${
|
||||
api_domain ? api_domain.replace(/\/$/gi, "") : "wakatime.com"
|
||||
}/api/v1/users/${username}/stats/${
|
||||
range || "all_time"
|
||||
}?is_including_today=true`,
|
||||
}/api/v1/users/${username}/stats?is_including_today=true`,
|
||||
);
|
||||
|
||||
return data.data;
|
||||
} catch (err) {
|
||||
if (err.response.status < 200 || err.response.status > 299) {
|
||||
throw new Error(
|
||||
"Wakatime user not found, make sure you have a wakatime profile",
|
||||
throw new CustomError(
|
||||
`Could not resolve to a User with the login of '${username}'`,
|
||||
"WAKATIME_USER_NOT_FOUND",
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
|
||||
Reference in New Issue
Block a user