Skip to content

Commit 408389f

Browse files
Check if projects/languages/OSes/editors are present in Wakatime response (lowlighter#393)
1 parent a77f699 commit 408389f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

source/app/mocks/api/axios/get/wakatime.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function({faker, url, options, login = faker.internet.userName()}
4343
machines:stats(),
4444
operating_systems:stats(["Mac", "Windows", "Linux"]),
4545
project:null,
46-
projects:stats(),
46+
projects:/api_key=MOCKED_TOKEN_NO_PROJECTS/.test(url) ? null : stats(),
4747
total_seconds:faker.datatype.number(1000000000),
4848
total_seconds_including_other_language:faker.datatype.number(1000000000),
4949
},

source/plugins/wakatime/index.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ export default async function({login, q, imports, data, account}, {enabled = fal
2727
total:stats.total_seconds / (60 * 60),
2828
daily:stats.daily_average / (60 * 60),
2929
},
30-
projects:stats.projects.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
31-
languages:stats.languages.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
32-
os:stats.operating_systems.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
33-
editors:stats.editors.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
30+
projects:stats.projects?.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
31+
languages:stats.languages?.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
32+
os:stats.operating_systems?.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
33+
editors:stats.editors?.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
3434
}
3535

3636
//Result

source/plugins/wakatime/tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@
1313
plugin_wakatime: yes
1414
plugin_wakatime_limit: 4
1515
plugin_wakatime_sections: time, projects, projects-graphs, languages, languages-graphs, editors, editors-graphs, os, os-graphs
16+
17+
- name: WakaTime plugin (projects hidden)
18+
uses: lowlighter/metrics@latest
19+
with:
20+
token: NOT_NEEDED
21+
plugin_wakatime_token: MOCKED_TOKEN_NO_PROJECTS
22+
plugin_wakatime: yes
23+
plugin_wakatime_sections: time, projects, languages

0 commit comments

Comments
 (0)