Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b8e06b

Browse files
committed
fix: Make WakaTime card compatible with new API
This commit makes sure that the WakaTime card works with the newWakaTime API. Seeanuraghazra#2698for more information.
1 parent688f4e4 commit6b8e06b

File tree

6 files changed

+66
-27
lines changed

6 files changed

+66
-27
lines changed

‎readme.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ You can provide multiple comma-separated values in the bg_color option to render
328328
-`layout` - Switch between two available layouts`default` &`compact`. Default`default`.
329329
-`langs_count` - Limit the number of languages on the card, defaults to all reported languages_(number)_.
330330
-`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`.
331-
-`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`.
332331

333332
* * *
334333

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

446445
#Wakatime Week Stats
447446

447+
>**Warning**
448+
>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.
449+
448450
Change the`?username=` value to your[Wakatime](https://wakatime.com) username.
449451

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

454-
>**Note**:
455-
>Please be aware that we currently only show data from Wakatime profiles that are public.
456-
457456
###Demo
458457

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

‎src/cards/wakatime-card.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
279279
:noCodingActivityNode({
280280
//@ts-ignore
281281
color:textColor,
282-
text:i18n.t("wakatimecard.nocodingactivity"),
282+
text:!stats.is_coding_activity_visible
283+
?i18n.t("wakatimecard.notpublic")
284+
:stats.is_other_usage_visible
285+
?i18n.t("wakatimecard.nocodingactivity")
286+
:i18n.t("wakatimecard.nocodedetails"),
283287
})
284288
}
285289
`;
@@ -304,17 +308,32 @@ const renderWakatimeCard = (stats = {}, options = { hide: [] }) => {
304308
noCodingActivityNode({
305309
//@ts-ignore
306310
color:textColor,
307-
text:i18n.t("wakatimecard.nocodingactivity"),
311+
text:!stats.is_coding_activity_visible
312+
?i18n.t("wakatimecard.notpublic")
313+
:stats.is_other_usage_visible
314+
?i18n.t("wakatimecard.nocodingactivity")
315+
:i18n.t("wakatimecard.nocodedetails"),
308316
}),
309317
],
310318
gap:lheight,
311319
direction:"column",
312320
}).join("");
313321
}
314322

323+
// Get title range text
324+
lettitleText=i18n.t("wakatimecard.title");
325+
switch(stats.range){
326+
case"last_7_days":
327+
titleText+=` (${i18n.t("wakatimecard.last7days")})`;
328+
break;
329+
case"last_year":
330+
titleText+=` (${i18n.t("wakatimecard.lastyear")})`;
331+
break;
332+
}
333+
315334
constcard=newCard({
316335
customTitle:custom_title,
317-
defaultTitle:i18n.t("wakatimecard.title"),
336+
defaultTitle:titleText,
318337
width:495,
319338
height,
320339
border_radius,

‎src/fetchers/wakatime-fetcher.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@ import { MissingParamError } from "../common/utils.js";
44
/**
55
* WakaTime data fetcher.
66
*
7-
*@param {{username: string, api_domain: string, range: string}} props Fetcher props.
7+
*@param {{username: string, api_domain: string}} props Fetcher props.
88
*@returns {Promise<WakaTimeData>} WakaTime data response.
99
*/
10-
constfetchWakatimeStats=async({ username, api_domain, range})=>{
10+
constfetchWakatimeStats=async({ username, api_domain})=>{
1111
if(!username)thrownewMissingParamError(["username"]);
1212

13-
try{
14-
const{ data}=awaitaxios.get(
15-
`https://${
16-
api_domain ?api_domain.replace(/\/$/gi,"") :"wakatime.com"
17-
}/api/v1/users/${username}/stats/${
18-
range||"all_time"
19-
}?is_including_today=true`,
20-
);
21-
22-
returndata.data;
23-
}catch(err){
24-
if(err.response.status<200||err.response.status>299){
25-
thrownewError(
26-
"Wakatime user not found, make sure you have a wakatime profile",
13+
// Loop through available ranges to get user data.
14+
for(constrangeof["all_time","last_7_days","last_year"]){
15+
try{
16+
const{ data}=awaitaxios.get(
17+
`https://${
18+
api_domain ?api_domain.replace(/\/$/gi,"") :"wakatime.com"
19+
}/api/v1/users/${username}/stats/${range}?is_including_today=true`,
2720
);
21+
22+
returndata.data;
23+
}catch(err){
24+
if(err.response.status===403&&range!=="last_year"){
25+
continue;
26+
}elseif(err.response.status<200||err.response.status>299){
27+
thrownewError(i18n.t("wakatimecard.nouser"));
28+
}
29+
throwerr;
2830
}
29-
throwerr;
3031
}
3132
};
3233

‎src/translations.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,26 @@ const wakatimeCardLocales = {
326326
vi:"Thống Kê Wakatime",
327327
se:"Wakatime statistik",
328328
},
329+
"wakatimecard.lastyear":{
330+
en:"last year",
331+
cn:"去年",
332+
},
333+
"wakatimecard.last7days":{
334+
en:"last 7 days",
335+
cn:"最近 7 天",
336+
},
337+
"wakatimecard.nouser":{
338+
en:"Wakatime user not found, make sure you have a Wakatime profile",
339+
cn:"未找到 Wakatime 用戶,請確保您擁有 Wakatime 個人資料",
340+
},
341+
"wakatimecard.notpublic":{
342+
en:"Wakatime user profile not public",
343+
cn:"Wakatime 用戶個人資料未公開",
344+
},
345+
"wakatimecard.nocodedetails":{
346+
en:"User doesn't publicly share detailed code statistics",
347+
cn:"用戶不公開分享詳細的代碼統計信息",
348+
},
329349
"wakatimecard.nocodingactivity":{
330350
ar:"لا يوجد نشاط برمجي لهذا الأسبوع",
331351
cn:"本周没有编程活动",

‎tests/__snapshots__/renderWakatimeCard.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout 1
123123
y="0"
124124
class="header"
125125
data-testid="header"
126-
>Wakatime Stats</text>
126+
>Wakatime Stats (last 7 days)</text>
127127
</g>
128128
</g>
129129
@@ -303,7 +303,7 @@ exports[`Test Render Wakatime Card should render correctly with compact layout w
303303
y="0"
304304
class="header"
305305
data-testid="header"
306-
>Wakatime Stats</text>
306+
>Wakatime Stats (last 7 days)</text>
307307
</g>
308308
</g>
309309

‎tests/renderWakatimeCard.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("Test Render Wakatime Card", () => {
4343
expect(
4444
document.querySelector('g[transform="translate(0, 0)"]>text.stat.bold')
4545
.textContent,
46-
).toBe("本周没有编程活动");
46+
).toBe("Wakatime 用戶個人資料未公開");
4747
});
4848

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp