From 408389fcc99aab4ae0e019dec1cdd32b91d09a43 Mon Sep 17 00:00:00 2001 From: cherryblossom000 <31467609+cherryblossom000@users.noreply.github.com> Date: Thu, 17 Jun 2021 21:56:01 +1000 Subject: [PATCH] Check if projects/languages/OSes/editors are present in Wakatime response (#393) --- source/app/mocks/api/axios/get/wakatime.mjs | 2 +- source/plugins/wakatime/index.mjs | 8 ++++---- source/plugins/wakatime/tests.yml | 8 ++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/source/app/mocks/api/axios/get/wakatime.mjs b/source/app/mocks/api/axios/get/wakatime.mjs index 2aef57c4..042dfbbf 100644 --- a/source/app/mocks/api/axios/get/wakatime.mjs +++ b/source/app/mocks/api/axios/get/wakatime.mjs @@ -43,7 +43,7 @@ export default function({faker, url, options, login = faker.internet.userName()} machines:stats(), operating_systems:stats(["Mac", "Windows", "Linux"]), project:null, - projects:stats(), + projects:/api_key=MOCKED_TOKEN_NO_PROJECTS/.test(url) ? null : stats(), total_seconds:faker.datatype.number(1000000000), total_seconds_including_other_language:faker.datatype.number(1000000000), }, diff --git a/source/plugins/wakatime/index.mjs b/source/plugins/wakatime/index.mjs index 387d8683..245c5d59 100644 --- a/source/plugins/wakatime/index.mjs +++ b/source/plugins/wakatime/index.mjs @@ -27,10 +27,10 @@ export default async function({login, q, imports, data, account}, {enabled = fal total:stats.total_seconds / (60 * 60), daily:stats.daily_average / (60 * 60), }, - projects:stats.projects.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), - languages:stats.languages.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), - 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), - editors:stats.editors.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), + projects:stats.projects?.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), + languages:stats.languages?.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), + 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), + editors:stats.editors?.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit), } //Result diff --git a/source/plugins/wakatime/tests.yml b/source/plugins/wakatime/tests.yml index a8e29ff6..81e96947 100644 --- a/source/plugins/wakatime/tests.yml +++ b/source/plugins/wakatime/tests.yml @@ -13,3 +13,11 @@ plugin_wakatime: yes plugin_wakatime_limit: 4 plugin_wakatime_sections: time, projects, projects-graphs, languages, languages-graphs, editors, editors-graphs, os, os-graphs + +- name: WakaTime plugin (projects hidden) + uses: lowlighter/metrics@latest + with: + token: NOT_NEEDED + plugin_wakatime_token: MOCKED_TOKEN_NO_PROJECTS + plugin_wakatime: yes + plugin_wakatime_sections: time, projects, languages