feat(plugins/wakatime): add plugin_wakatime_repositories_visibility option (#1052)
This commit is contained in:
@@ -7,9 +7,13 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
|||||||
return null
|
return null
|
||||||
|
|
||||||
//Load inputs
|
//Load inputs
|
||||||
let {sections, days, limit, url, user, "languages.other": others} = imports.metadata.plugins.wakatime.inputs({data, account, q})
|
let {sections, days, limit, url, user, "languages.other": others, "repositories.visibility": repositoriesVisibility} = imports.metadata.plugins.wakatime.inputs({data, account, q})
|
||||||
|
|
||||||
if (!limit)
|
if (!limit)
|
||||||
limit = void limit
|
limit = void limit
|
||||||
|
|
||||||
|
const showOnlyGithubPublicRepos = repositoriesVisibility === "public"
|
||||||
|
|
||||||
const range = {
|
const range = {
|
||||||
"7": "last_7_days",
|
"7": "last_7_days",
|
||||||
"30": "last_30_days",
|
"30": "last_30_days",
|
||||||
@@ -20,14 +24,18 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
|||||||
//Querying api and format result (https://wakatime.com/developers#stats)
|
//Querying api and format result (https://wakatime.com/developers#stats)
|
||||||
console.debug(`metrics/compute/${login}/plugins > wakatime > querying api`)
|
console.debug(`metrics/compute/${login}/plugins > wakatime > querying api`)
|
||||||
const {data: {data: stats}} = await imports.axios.get(`${url}/api/v1/users/${user}/stats/${range}?api_key=${token}`)
|
const {data: {data: stats}} = await imports.axios.get(`${url}/api/v1/users/${user}/stats/${range}?api_key=${token}`)
|
||||||
|
|
||||||
|
const projectStats = stats.projects?.map(({name, percent, total_seconds:total}) => ({name, percent:percent / 100, total})).sort((a, b) => b.percent - a.percent)
|
||||||
|
const projects = showOnlyGithubPublicRepos ? await pickOnlyGithubPublicRepos({limit, login, axios:imports.axios, projects:projectStats}) : projectStats?.slice(0, limit)
|
||||||
|
|
||||||
const result = {
|
const result = {
|
||||||
sections,
|
sections,
|
||||||
days,
|
days,
|
||||||
|
projects,
|
||||||
time: {
|
time: {
|
||||||
total: (others ? stats.total_seconds_including_other_language : stats.total_seconds) / (60 * 60),
|
total: (others ? stats.total_seconds_including_other_language : stats.total_seconds) / (60 * 60),
|
||||||
daily: (others ? stats.daily_average_including_other_language : stats.daily_average) / (60 * 60),
|
daily: (others ? stats.daily_average_including_other_language : 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),
|
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),
|
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),
|
editors: stats.editors?.map(({name, percent, total_seconds: total}) => ({name, percent: percent / 100, total})).sort((a, b) => b.percent - a.percent).slice(0, limit),
|
||||||
@@ -47,3 +55,23 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
|||||||
throw {error: {message, instance: error}}
|
throw {error: {message, instance: error}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function pickOnlyGithubPublicRepos ({projects, axios, login, limit}) {
|
||||||
|
const result = []
|
||||||
|
|
||||||
|
for await (const project of projects) {
|
||||||
|
if (result.length >= limit) break
|
||||||
|
try {
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > wakatime > checking 'https://github.com/${login}/${project.name}'`)
|
||||||
|
await axios.head(`https://github.com/${login}/${project.name}`)
|
||||||
|
|
||||||
|
result.push(project)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length === 0) return undefined
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,3 +79,14 @@ inputs:
|
|||||||
description: Include other languages
|
description: Include other languages
|
||||||
type: boolean
|
type: boolean
|
||||||
default: no
|
default: no
|
||||||
|
|
||||||
|
plugin_wakatime_repositories_visibility:
|
||||||
|
description: |
|
||||||
|
Repositories visibility
|
||||||
|
|
||||||
|
Lets you hide private repositories.
|
||||||
|
type: string
|
||||||
|
default: all
|
||||||
|
values:
|
||||||
|
- public
|
||||||
|
- all
|
||||||
|
|||||||
Reference in New Issue
Block a user