Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: anuraghazra/github-readme-stats
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: anuraghazra/github-readme-stats
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: update_waka_to_new_api_2
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 8 files changed
  • 1 contributor

Commits on May 8, 2023

  1. fix: Make WakaTime card compatible with new API

    This commit makes sure that the WakaTime card works with the new
    WakaTime API. See #2698
    for more information.
    rickstaa committed May 8, 2023
    Copy the full SHA
    6b8e06b View commit details
  2. Copy the full SHA
    7ea55d0 View commit details
  3. Copy the full SHA
    d80d766 View commit details
  4. test: fix WakaTime tests

    rickstaa committed May 8, 2023
    Copy the full SHA
    65fa81f View commit details

Commits on May 9, 2023

  1. Copy the full SHA
    98fcc65 View commit details
3 changes: 1 addition & 2 deletions api/wakatime.js
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@ export default async (req, res) => {
langs_count,
hide,
api_domain,
range,
border_radius,
border_color,
} = req.query;
@@ -40,7 +39,7 @@ export default async (req, res) => {
}

try {
const stats = await fetchWakatimeStats({ username, api_domain, range });
const stats = await fetchWakatimeStats({ username, api_domain });

let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.FOUR_HOURS, 10),
7 changes: 3 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -328,7 +328,6 @@ You can provide multiple comma-separated values in the bg_color option to render
- `layout` - Switch between two available layouts `default` & `compact`. Default `default`.
- `langs_count` - Limit the number of languages on the card, defaults to all reported languages _(number)_.
- `api_domain` - Set a custom API domain for the card, e.g. to use services like [Hakatime](https://github.com/mujx/hakatime) or [Wakapi](https://github.com/muety/wakapi) _(string)_. Default `Waka API`.
- `range` – Request a range different from your WakaTime default, e.g. `last_7_days`. See [WakaTime API docs](https://wakatime.com/developers#stats) for a list of available options. _(YYYY-MM, last_7_days, last_30_days, last_6_months, last_year, or all_time)_. Default `all_time`.

* * *

@@ -445,15 +444,15 @@ You can use the `&hide_progress=true` option to hide the percentages and the pro

# Wakatime Week Stats

> **Warning**
> Please be aware that we currently only show data from Wakatime profiles that are public. You therefore have to make sure that **BOTH** `Display code time publicly` and `Display languages, editors, os, categories publicly` are enabled.
Change the `?username=` value to your [Wakatime](https://wakatime.com) username.

```md
[![Harlok's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=Harlok)](https://github.com/anuraghazra/github-readme-stats)
```

> **Note**:
> Please be aware that we currently only show data from Wakatime profiles that are public.
### Demo

[![Harlok's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=Harlok)](https://github.com/anuraghazra/github-readme-stats)
25 changes: 22 additions & 3 deletions src/cards/wakatime-card.js
Original file line number Diff line number Diff line change
@@ -279,7 +279,11 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
: noCodingActivityNode({
// @ts-ignore
color: textColor,
text: i18n.t("wakatimecard.nocodingactivity"),
text: !stats.is_coding_activity_visible
? i18n.t("wakatimecard.notpublic")
: stats.is_other_usage_visible
? i18n.t("wakatimecard.nocodingactivity")
: i18n.t("wakatimecard.nocodedetails"),
})
}
`;
@@ -304,17 +308,32 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
noCodingActivityNode({
// @ts-ignore
color: textColor,
text: i18n.t("wakatimecard.nocodingactivity"),
text: !stats.is_coding_activity_visible
? i18n.t("wakatimecard.notpublic")
: stats.is_other_usage_visible
? i18n.t("wakatimecard.nocodingactivity")
: i18n.t("wakatimecard.nocodedetails"),
}),
],
gap: lheight,
direction: "column",
}).join("");
}

// Get title range text
let titleText = i18n.t("wakatimecard.title");
switch (stats.range) {
case "last_7_days":
titleText += ` (${i18n.t("wakatimecard.last7days")})`;
break;
case "last_year":
titleText += ` (${i18n.t("wakatimecard.lastyear")})`;
break;
}

const card = new Card({
customTitle: custom_title,
defaultTitle: i18n.t("wakatimecard.title"),
defaultTitle: titleText,
width: 495,
height,
border_radius,
23 changes: 14 additions & 9 deletions src/fetchers/wakatime-fetcher.js
Original file line number Diff line number Diff line change
@@ -4,27 +4,32 @@ import { MissingParamError } from "../common/utils.js";
/**
* WakaTime data fetcher.
*
* @param {{username: string, api_domain: string, range: string}} props Fetcher props.
* @returns {Promise<WakaTimeData>} WakaTime data response.
* @param {{username: string, api_domain: string}} props Fetcher props.
* @returns {Promise<wakaTimeStatsRangeData>} WakaTime data response.
*/
const fetchWakatimeStats = async ({ username, api_domain, range }) => {
const fetchWakatimeStats = async ({ username, api_domain }) => {
if (!username) throw new MissingParamError(["username"]);

// Retrieve user range.
const { data: userdata } = await axios.get(
`https://${
api_domain ? api_domain.replace(/\/$/gi, "") : "wakatime.com"
}/api/v1/users/${username}/stats`,
);
const range = userdata.data.range;

// Loop through available ranges to get user data.
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/${range}?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 Error(i18n.t("wakatimecard.nouser"));
}
throw err;
}
20 changes: 20 additions & 0 deletions src/translations.js
Original file line number Diff line number Diff line change
@@ -326,6 +326,26 @@ const wakatimeCardLocales = {
vi: "Thống Kê Wakatime",
se: "Wakatime statistik",
},
"wakatimecard.lastyear": {
en: "last year",
cn: "去年",
},
"wakatimecard.last7days": {
en: "last 7 days",
cn: "最近 7 天",
},
"wakatimecard.nouser": {
en: "Wakatime user not found, make sure you have a Wakatime profile",
cn: "未找到 Wakatime 用户,请确保您拥有 Wakatime 个人资料",
},
"wakatimecard.notpublic": {
en: "Wakatime user profile not public",
cn: "Wakatime 用户个人资料未公开",
},
"wakatimecard.nocodedetails": {
en: "User doesn't publicly share detailed code statistics",
cn: "用户不公开分享详细的代码统计信息",
},
"wakatimecard.nocodingactivity": {
ar: "لا يوجد نشاط برمجي لهذا الأسبوع",
cn: "本周没有编程活动",
4 changes: 2 additions & 2 deletions tests/__snapshots__/renderWakatimeCard.test.js.snap
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
y="0"
class="header"
data-testid="header"
>Wakatime Stats</text>
>Wakatime Stats (last 7 days)</text>
</g>
</g>
@@ -303,7 +303,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout w
y="0"
class="header"
data-testid="header"
>Wakatime Stats</text>
>Wakatime Stats (last 7 days)</text>
</g>
</g>
34 changes: 34 additions & 0 deletions tests/fetchWakatime.test.js
Original file line number Diff line number Diff line change
@@ -8,6 +8,37 @@ afterEach(() => {
mock.reset();
});

const wakaTimeUserData = {
data: {
id: "aa437823-82d1-4b37-9b84-ab4ed89c8688",
user_id: "c7e2e900-858b-400e-bc1c-016345cf59b6",
range: "all_time",
timeout: 15,
writes_only: false,
holidays: 134,
status: "ok",
is_up_to_date: true,
days_minus_holidays: 231,
days_including_holidays: 365,
percent_calculated: 100,
human_readable_total: "691 hrs 5 mins",
is_already_updating: false,
is_stuck: false,
total_seconds_including_other_language: 2508467.924346,
is_up_to_date_pending_future: false,
total_seconds: 2487938.453846,
human_readable_daily_average: "2 hrs 59 mins",
human_readable_total_including_other_language: "696 hrs 47 mins",
daily_average_including_other_language: 10859.0,
daily_average: 10770.0,
human_readable_daily_average_including_other_language: "3 hrs",
username: "rickstaa",
is_including_today: false,
human_readable_range: "last year",
is_coding_activity_visible: true,
is_other_usage_visible: false,
},
};
const wakaTimeData = {
data: {
categories: [
@@ -103,6 +134,9 @@ const wakaTimeData = {
describe("Wakatime fetcher", () => {
it("should fetch correct wakatime data", async () => {
const username = "anuraghazra";
mock
.onGet(`https://wakatime.com/api/v1/users/${username}/stats`)
.reply(200, wakaTimeUserData);
mock
.onGet(
`https://wakatime.com/api/v1/users/${username}/stats/all_time?is_including_today=true`,
2 changes: 1 addition & 1 deletion tests/renderWakatimeCard.test.js
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ describe("Test Render Wakatime Card", () => {
expect(
document.querySelector('g[transform="translate(0, 0)"]>text.stat.bold')
.textContent,
).toBe("本周没有编程活动");
).toBe("Wakatime 用户个人资料未公开");
});

it("should render without rounding", () => {