refactor(app/web): new features (#1124) [skip ci]
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
import * as compute from "./list/index.mjs"
|
||||
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, computed, graphql, queries, rest, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, computed, graphql, queries, rest, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.achievements))
|
||||
if ((!enabled) || (!q.achievements) || (!imports.metadata.plugins.achievements.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -37,7 +37,7 @@ export default async function({login, q, imports, data, computed, graphql, queri
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ inputs:
|
||||
Enable achievements plugin
|
||||
type: boolean
|
||||
default: no
|
||||
extras:
|
||||
- metrics.run.puppeteer.scrapping
|
||||
|
||||
plugin_achievements_threshold:
|
||||
description: |
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, rest, q, account, imports}, {enabled = false, markdown = "inline"} = {}) {
|
||||
export default async function({login, data, rest, q, account, imports}, {enabled = false, markdown = "inline", extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.activity))
|
||||
if ((!enabled) || (!q.activity) || (!imports.metadata.plugins.activity.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Context
|
||||
@@ -174,6 +174,6 @@ export default async function({login, data, rest, q, account, imports}, {enabled
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, queries, imports, q, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, queries, imports, q, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.anilist))
|
||||
if ((!enabled) || (!q.anilist) || (!imports.metadata.plugins.anilist.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -122,14 +122,7 @@ export default async function({login, data, queries, imports, q, account}, {enab
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
let message = "An error occured"
|
||||
if (error.isAxiosError) {
|
||||
const status = error.response?.status
|
||||
console.debug(error.response.data)
|
||||
message = `API returned ${status}`
|
||||
error = error.response?.data ?? null
|
||||
}
|
||||
throw {error: {message, instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ inputs:
|
||||
Enable aniList plugin
|
||||
type: boolean
|
||||
default: no
|
||||
extras:
|
||||
- metrics.run.puppeteer.scrapping
|
||||
|
||||
plugin_anilist_user:
|
||||
type: string
|
||||
|
||||
@@ -8,7 +8,6 @@ export default async function({login, graphql, rest, data, q, queries, imports,
|
||||
//Load inputs
|
||||
console.debug(`metrics/compute/${login}/base > started`)
|
||||
let {indepth, hireable, "repositories.forks": _forks, "repositories.affiliations": _affiliations, "repositories.batch": _batch} = imports.metadata.plugins.base.inputs({data, q, account: "bypass"})
|
||||
const extras = conf.settings.extras?.features ?? conf.settings.extras?.default
|
||||
const repositories = conf.settings.repositories || 100
|
||||
const forks = _forks ? "" : ", isFork: false"
|
||||
const affiliations = _affiliations?.length ? `, ownerAffiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]${conf.authenticated === login ? `, affiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]` : ""}` : ""
|
||||
@@ -90,7 +89,7 @@ export default async function({login, graphql, rest, data, q, queries, imports,
|
||||
}
|
||||
//Query contributions collection over account lifetime instead of last year
|
||||
if (account === "user") {
|
||||
if ((indepth) && (extras)) {
|
||||
if ((indepth) && (imports.metadata.plugins.base.extras("indepth", {...conf.settings, error:false}))) {
|
||||
const fields = ["totalRepositoriesWithContributedCommits", "totalCommitContributions", "restrictedContributionsCount", "totalIssueContributions", "totalPullRequestContributions", "totalPullRequestReviewContributions"]
|
||||
const start = new Date(data.user.createdAt)
|
||||
const end = new Date()
|
||||
|
||||
@@ -49,7 +49,6 @@ inputs:
|
||||
default: no
|
||||
extras:
|
||||
- metrics.api.github.overuse
|
||||
- plugins.base.indepth
|
||||
|
||||
base_hireable:
|
||||
description: |
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, data, imports, graphql, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, data, imports, graphql, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.calendar))
|
||||
if ((!enabled) || (!q.calendar) || (!imports.metadata.plugins.calendar.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -52,6 +52,6 @@ export default async function({login, q, data, imports, graphql, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, rest, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, rest, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.code))
|
||||
if ((!enabled) || (!q.code) || (!imports.metadata.plugins.code.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Context
|
||||
@@ -79,6 +79,6 @@ export default async function({login, q, imports, data, rest, account}, {enabled
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,8 @@ export default async function(
|
||||
},
|
||||
//Settings and tokens
|
||||
{
|
||||
enabled = false
|
||||
enabled = false,
|
||||
extras = false,
|
||||
} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({q, data, imports, account}, {enabled = false} = {}) {
|
||||
export default async function({q, data, imports, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.fortune))
|
||||
if ((!enabled) || (!q.fortune) || (!imports.metadata.plugins.fortune.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -40,6 +40,6 @@ export default async function({q, data, imports, account}, {enabled = false} = {
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
//Setup
|
||||
export default async function({q, imports, data, account}, {enabled = false} = {}) {
|
||||
export default async function({q, imports, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.nightscout))
|
||||
if ((!enabled) || (!q.nightscout) || (!imports.metadata.plugins.nightscout.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {url, datapoints, lowalert, highalert, urgentlowalert, urgenthighalert} = imports.metadata.plugins.nightscout.inputs({data, account, q})
|
||||
|
||||
if (!url || url === "https://example.herokuapp.com")
|
||||
throw {error: {message: "Nightscout site URL isn't set!"}}
|
||||
throw {error: {message: "Nightscout URL is not set"}}
|
||||
if (url.substring(url.length - 1) !== "/")
|
||||
url += "/"
|
||||
if (url.substring(0, 7) === "http://")
|
||||
@@ -48,9 +48,7 @@ export default async function({q, imports, data, account}, {enabled = false} = {
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({q, imports, data, account}, {enabled = false, token = ""} = {}) {
|
||||
export default async function({q, imports, data, account}, {enabled = false, token = "", extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.poopmap))
|
||||
if ((!enabled) || (!q.poopmap) || (!imports.metadata.plugins.poopmap.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
if (!token)
|
||||
@@ -32,6 +32,6 @@ export default async function({q, imports, data, account}, {enabled = false, tok
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.screenshot))
|
||||
if ((!enabled) || (!q.screenshot) || (!imports.metadata.plugins.screenshot.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {url, selector, title, background} = imports.metadata.plugins.screenshot.inputs({data, account, q})
|
||||
if (!url)
|
||||
throw {error: {message: "An url is required"}}
|
||||
throw {error: {message: "URL is not set"}}
|
||||
|
||||
//Start puppeteer and navigate to page
|
||||
console.debug(`metrics/compute/${login}/plugins > screenshot > starting browser`)
|
||||
@@ -37,8 +37,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {title: "Screenshot error", error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error, {title:"Screenshot error"})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ inputs:
|
||||
Enable screenshot plugin
|
||||
type: boolean
|
||||
default: no
|
||||
extras:
|
||||
- metrics.run.puppeteer.scrapping
|
||||
|
||||
plugin_screenshot_title:
|
||||
description: |
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, token} = {}) {
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, extras = false, token} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.stock))
|
||||
if ((!enabled) || (!q.stock) || (!imports.metadata.plugins.stock.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {symbol, interval, duration} = imports.metadata.plugins.stock.inputs({data, account, q})
|
||||
if (!token)
|
||||
throw {error: {message: "A token is required"}}
|
||||
throw {error: {message: "API token is not set"}}
|
||||
if (!symbol)
|
||||
throw {error: {message: "A company stock symbol is required"}}
|
||||
throw {error: {message: "Company stock symbol is not set"}}
|
||||
symbol = symbol.toLocaleUpperCase()
|
||||
|
||||
//Query API for company informations
|
||||
@@ -48,13 +48,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
let message = "An error occured"
|
||||
if (error.isAxiosError) {
|
||||
const status = error.response?.status
|
||||
const description = error.response?.data?.message ?? null
|
||||
message = `API returned ${status}${description ? ` (${description})` : ""}`
|
||||
error = error.response?.data ?? null
|
||||
}
|
||||
throw {error: {message, instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ export default async function({login, q, imports, data, rest, graphql, queries,
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.contributors))
|
||||
if ((!enabled) || (!q.contributors) || (!imports.metadata.plugins.contributors.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -70,7 +70,7 @@ export default async function({login, q, imports, data, rest, graphql, queries,
|
||||
|
||||
//Contributions categories
|
||||
const types = Object.fromEntries([...new Set(Object.keys(categories))].map(type => [type, new Set()]))
|
||||
if ((sections.includes("categories")) && (extras)) {
|
||||
if ((sections.includes("categories")) && (imports.metadata.plugins.contributors.extras("categories", {extras}))) {
|
||||
//Temporary directory
|
||||
const repository = `${repo.owner}/${repo.repo}`
|
||||
const path = imports.paths.join(imports.os.tmpdir(), `${repository.replace(/[^\w]/g, "_")}`)
|
||||
@@ -123,6 +123,6 @@ export default async function({login, q, imports, data, rest, graphql, queries,
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ inputs:
|
||||
format: comma-separated
|
||||
default: ""
|
||||
extras:
|
||||
- metrics.run.setup.community.templates
|
||||
- metrics.setup.community.templates
|
||||
|
||||
template:
|
||||
description: |
|
||||
@@ -185,7 +185,7 @@ inputs:
|
||||
type: string
|
||||
default: ""
|
||||
extras:
|
||||
- metrics.run.user.css
|
||||
- metrics.run.puppeteer.user.css
|
||||
|
||||
extras_js:
|
||||
description: |
|
||||
@@ -199,7 +199,7 @@ inputs:
|
||||
type: string
|
||||
default: ""
|
||||
extras:
|
||||
- metrics.run.user.js
|
||||
- metrics.run.puppeteer.user.js
|
||||
|
||||
config_timezone:
|
||||
description: |
|
||||
@@ -347,6 +347,8 @@ inputs:
|
||||
default: ""
|
||||
preset: no
|
||||
example: "@lunar-red"
|
||||
extras:
|
||||
- metrics.setup.community.presets
|
||||
|
||||
retries:
|
||||
description: |
|
||||
@@ -497,6 +499,8 @@ inputs:
|
||||
default: no
|
||||
testing: yes
|
||||
preset: no
|
||||
extras:
|
||||
- metrics.npm.optional.libxml2
|
||||
|
||||
debug_flags:
|
||||
description: |
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, graphql, queries, data, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, graphql, queries, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.discussions))
|
||||
if ((!enabled) || (!q.discussions) || (!imports.metadata.plugins.discussions.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -64,6 +64,6 @@ export default async function({login, q, imports, graphql, queries, data, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ export default async function({login, data, computed, imports, q, graphql, queri
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.followup))
|
||||
if ((!enabled) || (!q.followup) || (!imports.metadata.plugins.followup.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -56,37 +56,34 @@ export default async function({login, data, computed, imports, q, graphql, queri
|
||||
},
|
||||
}
|
||||
|
||||
//Extras features
|
||||
if (extras) {
|
||||
//Indepth mode
|
||||
if (indepth) {
|
||||
console.debug(`metrics/compute/${login}/plugins > followup > indepth`)
|
||||
followup.indepth = {repositories: {}}
|
||||
//Indepth mode
|
||||
if ((indepth)&&(imports.metadata.plugins.followup.extras("indepth", {extras}))) {
|
||||
console.debug(`metrics/compute/${login}/plugins > followup > indepth`)
|
||||
followup.indepth = {repositories: {}}
|
||||
|
||||
//Process repositories
|
||||
for (const {name: repo, owner: {login: owner}} of data.user.repositories.nodes) {
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > followup > processing ${owner}/${repo}`)
|
||||
followup.indepth.repositories[`${owner}/${repo}`] = {stats: {}}
|
||||
//Fetch users with push access
|
||||
let {repository: {collaborators: {nodes: collaborators}}} = await graphql(queries.followup["repository.collaborators"]({repo, owner})).catch(() => ({repository: {collaborators: {nodes: [{login: owner}]}}}))
|
||||
console.debug(`metrics/compute/${login}/plugins > followup > found ${collaborators.length} collaborators`)
|
||||
followup.indepth.repositories[`${owner}/${repo}`].collaborators = collaborators.map(({login}) => login)
|
||||
//Fetch issues and pull requests created by collaborators
|
||||
collaborators = collaborators.map(({login}) => `-author:${login}`).join(" ")
|
||||
const stats = await graphql(queries.followup.repository({repo, owner, collaborators}))
|
||||
followup.indepth.repositories[`${owner}/${repo}`] = stats
|
||||
//Aggregate global stats
|
||||
for (const [key, {issueCount: count}] of Object.entries(stats)) {
|
||||
const [section, type] = key.split("_")
|
||||
followup[section].collaborators[type] += count
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(error)
|
||||
console.debug(`metrics/compute/${login}/plugins > followup > an error occured while processing ${owner}/${repo}, skipping...`)
|
||||
//Process repositories
|
||||
for (const {name: repo, owner: {login: owner}} of data.user.repositories.nodes) {
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > followup > processing ${owner}/${repo}`)
|
||||
followup.indepth.repositories[`${owner}/${repo}`] = {stats: {}}
|
||||
//Fetch users with push access
|
||||
let {repository: {collaborators: {nodes: collaborators}}} = await graphql(queries.followup["repository.collaborators"]({repo, owner})).catch(() => ({repository: {collaborators: {nodes: [{login: owner}]}}}))
|
||||
console.debug(`metrics/compute/${login}/plugins > followup > found ${collaborators.length} collaborators`)
|
||||
followup.indepth.repositories[`${owner}/${repo}`].collaborators = collaborators.map(({login}) => login)
|
||||
//Fetch issues and pull requests created by collaborators
|
||||
collaborators = collaborators.map(({login}) => `-author:${login}`).join(" ")
|
||||
const stats = await graphql(queries.followup.repository({repo, owner, collaborators}))
|
||||
followup.indepth.repositories[`${owner}/${repo}`] = stats
|
||||
//Aggregate global stats
|
||||
for (const [key, {issueCount: count}] of Object.entries(stats)) {
|
||||
const [section, type] = key.split("_")
|
||||
followup[section].collaborators[type] += count
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(error)
|
||||
console.debug(`metrics/compute/${login}/plugins > followup > an error occured while processing ${owner}/${repo}, skipping...`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +117,6 @@ export default async function({login, data, computed, imports, q, graphql, queri
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, graphql, q, imports, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, graphql, q, imports, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.gists))
|
||||
if ((!enabled) || (!q.gists) || (!imports.metadata.plugins.gists.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -45,8 +45,6 @@ export default async function({login, data, graphql, q, imports, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.habits))
|
||||
if ((!enabled) || (!q.habits) || (!imports.metadata.plugins.habits.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -97,7 +97,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
||||
}
|
||||
|
||||
//Linguist
|
||||
if ((extras) && (charts)) {
|
||||
if ((charts)&&((imports.metadata.plugins.habits.extras("charts", {extras, error:false})))) {
|
||||
//Check if linguist exists
|
||||
console.debug(`metrics/compute/${login}/plugins > habits > searching recently used languages using linguist`)
|
||||
if (patches.length) {
|
||||
@@ -113,7 +113,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
||||
}
|
||||
|
||||
//Generating charts with chartist
|
||||
if (_charts === "chartist") {
|
||||
if ((_charts === "chartist")&&(imports.metadata.plugins.habits.extras("charts.type", {extras}))) {
|
||||
console.debug(`metrics/compute/${login}/plugins > habits > generating charts`)
|
||||
habits.charts = await Promise.all([
|
||||
{type: "line", data: {...empty(24), ...Object.fromEntries(Object.entries(habits.commits.hours).filter(([k]) => !Number.isNaN(+k)))}, low: 0, high: habits.commits.hours.max},
|
||||
@@ -164,9 +164,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.introduction))
|
||||
if ((!enabled) || (!q.introduction) || (!imports.metadata.plugins.introduction.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -26,6 +26,6 @@ export default async function({login, q, imports, data, graphql, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, graphql, q, imports, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, graphql, q, imports, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.isocalendar))
|
||||
if ((!enabled) || (!q.isocalendar) || (!imports.metadata.plugins.isocalendar.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -72,9 +72,7 @@ export default async function({login, data, graphql, q, imports, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.languages))
|
||||
if ((!enabled) || (!q.languages) || (!imports.metadata.plugins.languages.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Context
|
||||
@@ -63,51 +63,48 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
}
|
||||
}
|
||||
|
||||
//Extras features
|
||||
if (extras) {
|
||||
//Recently used languages
|
||||
if ((sections.includes("recently-used")) && (context.mode === "user")) {
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
|
||||
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, categories: _recent_categories ?? categories, days: _recent_days, load: _recent_load, timeout})
|
||||
Object.assign(languages.colors, languages["stats.recent"].colors)
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ${error}`)
|
||||
}
|
||||
//Recently used languages
|
||||
if ((sections.includes("recently-used")) && (context.mode === "user") && (imports.metadata.plugins.languages.extras("indepth", {extras}))) {
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
|
||||
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, categories: _recent_categories ?? categories, days: _recent_days, load: _recent_load, timeout})
|
||||
Object.assign(languages.colors, languages["stats.recent"].colors)
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
//Indepth mode
|
||||
if (indepth) {
|
||||
//Fetch gpg keys (web-flow is GitHub's public key when making changes from web ui)
|
||||
const gpg = []
|
||||
try {
|
||||
for (const username of [login, "web-flow"]) {
|
||||
const {data: keys} = await rest.users.listGpgKeysForUser({username})
|
||||
gpg.push(...keys.map(({key_id: id, raw_key: pub, emails}) => ({id, pub, emails})))
|
||||
if (username === login) {
|
||||
for (const {email} of gpg.flatMap(({emails}) => emails)) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > auto-adding ${email} to commits_authoring (fetched from gpg)`)
|
||||
data.shared["commits.authoring"].push(email)
|
||||
}
|
||||
//Indepth mode
|
||||
if ((indepth)&&(imports.metadata.plugins.languages.extras("indepth", {extras}))) {
|
||||
//Fetch gpg keys (web-flow is GitHub's public key when making changes from web ui)
|
||||
const gpg = []
|
||||
try {
|
||||
for (const username of [login, "web-flow"]) {
|
||||
const {data: keys} = await rest.users.listGpgKeysForUser({username})
|
||||
gpg.push(...keys.map(({key_id: id, raw_key: pub, emails}) => ({id, pub, emails})))
|
||||
if (username === login) {
|
||||
for (const {email} of gpg.flatMap(({emails}) => emails)) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > auto-adding ${email} to commits_authoring (fetched from gpg)`)
|
||||
data.shared["commits.authoring"].push(email)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ${error}`)
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ${error}`)
|
||||
}
|
||||
|
||||
//Analyze languages
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
|
||||
const existingColors = languages.colors
|
||||
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories, gpg}, {skipped, categories, timeout}))
|
||||
Object.assign(languages.colors, existingColors)
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed.commits} commits`)
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ${error}`)
|
||||
}
|
||||
//Analyze languages
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
|
||||
const existingColors = languages.colors
|
||||
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories, gpg}, {skipped, categories, timeout}))
|
||||
Object.assign(languages.colors, existingColors)
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed.commits} commits`)
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +155,6 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ inputs:
|
||||
type: boolean
|
||||
default: false
|
||||
extras:
|
||||
- metrics.api.github.overuse
|
||||
- metrics.cpu.overuse
|
||||
- metrics.run.tempdir
|
||||
- metrics.run.git
|
||||
|
||||
@@ -124,10 +124,6 @@ inputs:
|
||||
default: 15
|
||||
min: 1
|
||||
max: 30
|
||||
extras:
|
||||
- metrics.api.github.overuse
|
||||
- metrics.run.tempdir
|
||||
- metrics.run.git
|
||||
|
||||
plugin_languages_categories:
|
||||
description: |
|
||||
@@ -140,10 +136,6 @@ inputs:
|
||||
- programming
|
||||
- prose
|
||||
default: markup, programming
|
||||
extras:
|
||||
- metrics.api.github.overuse
|
||||
- metrics.run.tempdir
|
||||
- metrics.run.git
|
||||
|
||||
plugin_languages_recent_categories:
|
||||
description: |
|
||||
@@ -156,10 +148,6 @@ inputs:
|
||||
- programming
|
||||
- prose
|
||||
default: markup, programming
|
||||
extras:
|
||||
- metrics.api.github.overuse
|
||||
- metrics.run.tempdir
|
||||
- metrics.run.git
|
||||
|
||||
plugin_languages_recent_load:
|
||||
description: |
|
||||
@@ -168,10 +156,6 @@ inputs:
|
||||
default: 300
|
||||
min: 100
|
||||
max: 1000
|
||||
extras:
|
||||
- metrics.api.github.overuse
|
||||
- metrics.run.tempdir
|
||||
- metrics.run.git
|
||||
|
||||
plugin_languages_recent_days:
|
||||
description: |
|
||||
@@ -181,7 +165,3 @@ inputs:
|
||||
min: 0
|
||||
max: 365
|
||||
zero: disable
|
||||
extras:
|
||||
- metrics.api.github.overuse
|
||||
- metrics.run.tempdir
|
||||
- metrics.run.git
|
||||
|
||||
@@ -3,7 +3,7 @@ export default async function({login, q, imports, data, graphql, queries, accoun
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!extras) || (!q.licenses))
|
||||
if ((!enabled) || (!q.licenses) || (!imports.metadata.plugins.licenses.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -113,7 +113,7 @@ export default async function({login, q, imports, data, graphql, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ inputs:
|
||||
type: boolean
|
||||
default: no
|
||||
extras:
|
||||
- metrics.cpu.overuse
|
||||
- metrics.run.tempdir
|
||||
- metrics.run.git
|
||||
- metrics.run.licensed
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, imports, rest, q, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, imports, rest, q, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.lines))
|
||||
if ((!enabled) || (!q.lines) || (!imports.metadata.plugins.lines.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -42,6 +42,6 @@ export default async function({login, data, imports, rest, q, account}, {enabled
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ const modes = {
|
||||
}
|
||||
|
||||
//Setup
|
||||
export default async function({login, imports, data, q, account}, {enabled = false, token = "", sandbox = false} = {}) {
|
||||
export default async function({login, imports, data, q, account}, {enabled = false, token = "", sandbox = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.music))
|
||||
if ((!enabled) || (!q.music) || (!imports.metadata.plugins.music.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Initialization
|
||||
@@ -71,16 +71,16 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
}
|
||||
//Provider
|
||||
if (!(provider in providers))
|
||||
throw {error: {message: provider ? `Unsupported provider "${provider}"` : "Missing provider"}, ...raw}
|
||||
throw {error: {message: provider ? `Unsupported provider "${provider}"` : "Provider is not set"}, ...raw}
|
||||
//Mode
|
||||
if (!(mode in modes))
|
||||
throw {error: {message: `Unsupported mode "${mode}"`}, ...raw}
|
||||
//Playlist mode
|
||||
if (mode === "playlist") {
|
||||
if (!playlist)
|
||||
throw {error: {message: "Missing playlist url"}, ...raw}
|
||||
throw {error: {message: "Playlist URL is not set"}, ...raw}
|
||||
if (!providers[provider].embed.test(playlist))
|
||||
throw {error: {message: "Unsupported playlist url format"}, ...raw}
|
||||
throw {error: {message: "Unsupported playlist URL format"}, ...raw}
|
||||
}
|
||||
//Limit
|
||||
limit = Math.max(1, Math.min(100, Number(limit)))
|
||||
@@ -177,7 +177,7 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
//Prepare credentials
|
||||
const [client_id, client_secret, refresh_token] = token.split(",").map(part => part.trim())
|
||||
if ((!client_id) || (!client_secret) || (!refresh_token))
|
||||
throw {error: {message: "Spotify token must contain client id/secret and refresh token"}}
|
||||
throw {error: {message: "Token must contain client id, client secret and refresh token"}}
|
||||
//API call and parse tracklist
|
||||
try {
|
||||
//Request access token
|
||||
@@ -309,14 +309,7 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.isAxiosError) {
|
||||
const status = error.response?.status
|
||||
const description = error.response.data?.error_description ?? null
|
||||
const message = `API returned ${status}${description ? ` (${description})` : ""}`
|
||||
error = error.response?.data ?? null
|
||||
throw {error: {message, instance: error}, ...raw}
|
||||
}
|
||||
throw error
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -364,9 +357,9 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
//Prepare credentials
|
||||
const [client_id, client_secret, refresh_token] = token.split(",").map(part => part.trim())
|
||||
if ((!client_id) || (!client_secret) || (!refresh_token))
|
||||
throw {error: {message: "Spotify token must contain client id/secret and refresh token"}}
|
||||
throw {error: {message: "Token must contain client id, client secret and refresh token"}}
|
||||
else if (limit > 50)
|
||||
throw {error: {message: "Spotify top limit cannot be greater than 50"}}
|
||||
throw {error: {message: "Top limit cannot exceed 50 for this provider"}}
|
||||
|
||||
//API call and parse tracklist
|
||||
try {
|
||||
@@ -422,14 +415,7 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.isAxiosError) {
|
||||
const status = error.response?.status
|
||||
const description = error.response.data?.error_description ?? null
|
||||
const message = `API returned ${status}${description ? ` (${description})` : ""}`
|
||||
error = error.response?.data ?? null
|
||||
throw {error: {message, instance: error}, ...raw}
|
||||
}
|
||||
throw error
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -473,14 +459,7 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.isAxiosError) {
|
||||
const status = error.response?.status
|
||||
const description = error.response.data?.message ?? null
|
||||
const message = `API returned ${status}${description ? ` (${description})` : ""}`
|
||||
error = error.response?.data ?? null
|
||||
throw {error: {message, instance: error}, ...raw}
|
||||
}
|
||||
throw error
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -513,13 +492,11 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
}
|
||||
|
||||
//Unhandled error
|
||||
throw {error: {message: "An error occured (could not retrieve tracks)"}}
|
||||
throw {error: {message: "Failed to retrieve tracks"}}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ inputs:
|
||||
Enable music plugin
|
||||
type: boolean
|
||||
default: no
|
||||
extras:
|
||||
- metrics.run.puppeteer.scrapping
|
||||
|
||||
plugin_music_provider:
|
||||
description: |
|
||||
|
||||
@@ -3,7 +3,7 @@ export default async function({login, q, imports, rest, graphql, data, account,
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.notable))
|
||||
if ((!enabled) || (!q.notable) || (!imports.metadata.plugins.notable.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -32,75 +32,72 @@ export default async function({login, q, imports, rest, graphql, data, account,
|
||||
contributions = await Promise.all(contributions.map(async ({handle, stars, issues, pulls, avatarUrl, organization}) => ({name: handle.split("/").shift(), handle, stars, issues, pulls, avatar: await imports.imgb64(avatarUrl), organization})))
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > found ${contributions.length} notable contributions`)
|
||||
|
||||
//Extras features
|
||||
if (extras) {
|
||||
//Indepth
|
||||
if (indepth) {
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > indepth`)
|
||||
//Indepth
|
||||
if ((indepth)&&(imports.metadata.plugins.notable.extras("indepth", {extras}))) {
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > indepth`)
|
||||
|
||||
//Fetch issues
|
||||
const issues = {}
|
||||
if (types.includes("issue")) {
|
||||
let cursor = null
|
||||
let pushed = 0
|
||||
do {
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > retrieving user issues after ${cursor}`)
|
||||
const {user: {issues: {edges}}} = await graphql(queries.notable.issues({login, type: "issues", after: cursor ? `after: "${cursor}"` : ""}))
|
||||
cursor = edges?.[edges?.length - 1]?.cursor
|
||||
edges.map(({node: {repository: {nameWithOwner: repository}}}) => issues[repository] = (issues[repositories] ?? 0) + 1)
|
||||
pushed = edges.length
|
||||
} while ((pushed) && (cursor))
|
||||
}
|
||||
//Fetch issues
|
||||
const issues = {}
|
||||
if (types.includes("issue")) {
|
||||
let cursor = null
|
||||
let pushed = 0
|
||||
do {
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > retrieving user issues after ${cursor}`)
|
||||
const {user: {issues: {edges}}} = await graphql(queries.notable.issues({login, type: "issues", after: cursor ? `after: "${cursor}"` : ""}))
|
||||
cursor = edges?.[edges?.length - 1]?.cursor
|
||||
edges.map(({node: {repository: {nameWithOwner: repository}}}) => issues[repository] = (issues[repositories] ?? 0) + 1)
|
||||
pushed = edges.length
|
||||
} while ((pushed) && (cursor))
|
||||
}
|
||||
|
||||
//Fetch pull requests
|
||||
const pulls = {}
|
||||
if (types.includes("pull_request")) {
|
||||
let cursor = null
|
||||
let pushed = 0
|
||||
do {
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > retrieving user pull requests after ${cursor}`)
|
||||
const {user: {pullRequests: {edges}}} = await graphql(queries.notable.issues({login, type: "pullRequests", after: cursor ? `after: "${cursor}"` : ""}))
|
||||
cursor = edges?.[edges?.length - 1]?.cursor
|
||||
edges.map(({node: {repository: {nameWithOwner: repository}}}) => pulls[repository] = (pulls[repositories] ?? 0) + 1)
|
||||
pushed = edges.length
|
||||
} while ((pushed) && (cursor))
|
||||
}
|
||||
//Fetch pull requests
|
||||
const pulls = {}
|
||||
if (types.includes("pull_request")) {
|
||||
let cursor = null
|
||||
let pushed = 0
|
||||
do {
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > retrieving user pull requests after ${cursor}`)
|
||||
const {user: {pullRequests: {edges}}} = await graphql(queries.notable.issues({login, type: "pullRequests", after: cursor ? `after: "${cursor}"` : ""}))
|
||||
cursor = edges?.[edges?.length - 1]?.cursor
|
||||
edges.map(({node: {repository: {nameWithOwner: repository}}}) => pulls[repository] = (pulls[repositories] ?? 0) + 1)
|
||||
pushed = edges.length
|
||||
} while ((pushed) && (cursor))
|
||||
}
|
||||
|
||||
//Fetch commits
|
||||
for (const contribution of contributions) {
|
||||
//Prepare data
|
||||
const {handle, stars} = contribution
|
||||
const [owner, repo] = handle.split("/")
|
||||
try {
|
||||
//Count total commits on repository
|
||||
const {repository: {defaultBranchRef: {target: {history}}}} = await graphql(queries.notable.commits({owner, repo}))
|
||||
contribution.history = history.totalCount
|
||||
//Fetch commits
|
||||
for (const contribution of contributions) {
|
||||
//Prepare data
|
||||
const {handle, stars} = contribution
|
||||
const [owner, repo] = handle.split("/")
|
||||
try {
|
||||
//Count total commits on repository
|
||||
const {repository: {defaultBranchRef: {target: {history}}}} = await graphql(queries.notable.commits({owner, repo}))
|
||||
contribution.history = history.totalCount
|
||||
|
||||
//Load maintainers (errors probably means that token is not allowed to list contributors hence not a maintainer of said repo)
|
||||
const {data: collaborators} = await rest.repos.listCollaborators({owner, repo}).catch(() => ({data: []}))
|
||||
const maintainers = collaborators.filter(({role_name: role}) => ["admin", "maintain", "write"].includes(role)).map(({login}) => login)
|
||||
//Load maintainers (errors probably means that token is not allowed to list contributors hence not a maintainer of said repo)
|
||||
const {data: collaborators} = await rest.repos.listCollaborators({owner, repo}).catch(() => ({data: []}))
|
||||
const maintainers = collaborators.filter(({role_name: role}) => ["admin", "maintain", "write"].includes(role)).map(({login}) => login)
|
||||
|
||||
//Count total commits of user
|
||||
const {data: contributions = []} = await rest.repos.getContributorsStats({owner, repo})
|
||||
const commits = contributions.filter(({author}) => author.login.toLocaleLowerCase() === login.toLocaleLowerCase()).reduce((a, {total: b}) => a + b, 0)
|
||||
//Count total commits of user
|
||||
const {data: contributions = []} = await rest.repos.getContributorsStats({owner, repo})
|
||||
const commits = contributions.filter(({author}) => author.login.toLocaleLowerCase() === login.toLocaleLowerCase()).reduce((a, {total: b}) => a + b, 0)
|
||||
|
||||
//Save user data
|
||||
contribution.user = {
|
||||
commits,
|
||||
percentage: commits / contribution.history,
|
||||
maintainer: maintainers.includes(login),
|
||||
issues: issues[handle] ?? 0,
|
||||
pulls: pulls[handle] ?? 0,
|
||||
get stars() {
|
||||
return Math.round(this.maintainer ? stars : this.percentage * stars)
|
||||
},
|
||||
}
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > indepth > successfully processed ${owner}/${repo}`)
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(error)
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > indepth > failed to compute for ${owner}/${repo}`)
|
||||
//Save user data
|
||||
contribution.user = {
|
||||
commits,
|
||||
percentage: commits / contribution.history,
|
||||
maintainer: maintainers.includes(login),
|
||||
issues: issues[handle] ?? 0,
|
||||
pulls: pulls[handle] ?? 0,
|
||||
get stars() {
|
||||
return Math.round(this.maintainer ? stars : this.percentage * stars)
|
||||
},
|
||||
}
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > indepth > successfully processed ${owner}/${repo}`)
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(error)
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > indepth > failed to compute for ${owner}/${repo}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,6 +139,6 @@ export default async function({login, q, imports, rest, graphql, data, account,
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
//Setup
|
||||
export default async function({login, imports, data, q, account}, {enabled = false, token = null} = {}) {
|
||||
export default async function({login, imports, data, q, account}, {enabled = false, token = null, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.pagespeed) || ((!data.user.websiteUrl) && (!q["pagespeed.url"])))
|
||||
if ((!enabled) || (!q.pagespeed) || (!imports.metadata.plugins.pagespeed.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {detailed, screenshot, url, pwa} = imports.metadata.plugins.pagespeed.inputs({data, account, q})
|
||||
//Format url if needed
|
||||
if (!url)
|
||||
throw {error: {message: "Website URL is not set"}}
|
||||
if (!/^https?:[/][/]/.test(url))
|
||||
url = `https://${url}`
|
||||
const {protocol, host} = imports.url.parse(url)
|
||||
@@ -45,15 +47,13 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
let message = "An error occured"
|
||||
if (error.isAxiosError) {
|
||||
const status = error.response?.status
|
||||
let description = error.response?.data?.error?.message?.match(/Lighthouse returned error: (?<description>[A-Z_]+)/)?.groups?.description ?? null
|
||||
if ((status === 429) && (!description))
|
||||
description = 'consider using "plugin_pagespeed_token"'
|
||||
message = `API returned ${status}${description ? ` (${description})` : ""}`
|
||||
error = error.response?.data ?? null
|
||||
}
|
||||
throw {error: {message, instance: error}}
|
||||
throw imports.format.error(error, {descriptions:{"429":'(consider using "plugin_pagespeed_token")', custom(error) {
|
||||
const description = error.response?.data?.error?.message?.match(/Lighthouse returned error: (?<description>[A-Z_]+)/)?.groups?.description ?? null
|
||||
if (description) {
|
||||
const status = error.response?.status
|
||||
return `API error: ${status} (${description})`
|
||||
}
|
||||
return null
|
||||
}}})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, graphql, rest, q, queries, imports, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, graphql, rest, q, queries, imports, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.people))
|
||||
if ((!enabled) || (!q.people) || (!imports.metadata.plugins.people.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Context
|
||||
@@ -102,6 +102,6 @@ export default async function({login, data, graphql, rest, q, queries, imports,
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, imports, q, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, imports, q, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.posts))
|
||||
if ((!enabled) || (!q.posts) || (!imports.metadata.plugins.posts.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -51,12 +51,10 @@ export default async function({login, data, imports, q, queries, account}, {enab
|
||||
}
|
||||
|
||||
//Unhandled error
|
||||
throw {error: {message: "An error occured (could not retrieve posts)"}}
|
||||
throw {error: {message: "Failed to retrieve posts"}}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, imports, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, imports, graphql, q, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.projects))
|
||||
if ((!enabled) || (!q.projects) || (!imports.metadata.plugins.projects.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -66,9 +66,10 @@ export default async function({login, data, imports, graphql, q, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
let message = "An error occured"
|
||||
if (error.errors?.map(({type}) => type)?.includes("INSUFFICIENT_SCOPES"))
|
||||
message = "Insufficient token rights"
|
||||
throw {error: {message, instance: error}}
|
||||
throw imports.format.error(error, {descriptions:{custom(error) {
|
||||
if (error.errors?.map(({type}) => type)?.includes("INSUFFICIENT_SCOPES"))
|
||||
return "Insufficient token scopes"
|
||||
return null
|
||||
}}})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.reactions))
|
||||
if ((!enabled) || (!q.reactions) || (!imports.metadata.plugins.reactions.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -60,6 +60,6 @@ export default async function({login, q, imports, data, graphql, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, graphql, queries, data, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, graphql, queries, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.repositories))
|
||||
if ((!enabled) || (!q.repositories) || (!imports.metadata.plugins.repositories.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -30,7 +30,7 @@ export default async function({login, q, imports, graphql, queries, data, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.rss))
|
||||
if ((!enabled) || (!q.rss) || (!imports.metadata.plugins.rss.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {source, limit} = imports.metadata.plugins.rss.inputs({data, account, q})
|
||||
if (!source)
|
||||
throw {error: {message: "A RSS feed is required"}}
|
||||
throw {error: {message: "RSS feed URL is not set"}}
|
||||
|
||||
//Load rss feed
|
||||
const {title, description, link, items} = await (new imports.rss()).parseURL(source) //eslint-disable-line new-cap
|
||||
@@ -26,8 +26,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.skyline))
|
||||
if ((!enabled) || (!q.skyline) || (!imports.metadata.plugins.skyline.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -42,6 +42,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ inputs:
|
||||
type: boolean
|
||||
default: no
|
||||
extras:
|
||||
- metrics.cpu.overuse
|
||||
- metrics.npm.optional.gifencoder
|
||||
- metrics.run.puppeteer.scrapping
|
||||
|
||||
plugin_skyline_year:
|
||||
description: |
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.sponsors))
|
||||
if ((!enabled) || (!q.sponsors) || (!imports.metadata.plugins.sponsors.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -85,6 +85,6 @@ export default async function({login, q, imports, data, graphql, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.stackoverflow))
|
||||
if ((!enabled) || (!q.stackoverflow) || (!imports.metadata.plugins.stackoverflow.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {sections, user, limit, lines, "lines.snippet": codelines} = imports.metadata.plugins.stackoverflow.inputs({data, account, q})
|
||||
if (!user)
|
||||
throw {error: {message: "You must provide a stackoverflow user id"}}
|
||||
throw {error: {message: "Stack Overflow user id is not set"}}
|
||||
|
||||
//Initialization
|
||||
//See https://api.stackexchange.com/docs
|
||||
@@ -64,9 +64,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, graphql, data, imports, q, queries, account}, {enabled = false} = {}) {
|
||||
export default async function({login, graphql, data, imports, q, queries, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.stargazers))
|
||||
if ((!enabled) || (!q.stargazers) || (!imports.metadata.plugins.stargazers.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -59,7 +59,7 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
|
||||
//Generating charts
|
||||
let charts = null
|
||||
if (_charts === "chartist") {
|
||||
if ((_charts === "chartist")&&(imports.metadata.plugins.stargazers.extras("charts.type", {extras}))) {
|
||||
console.debug(`metrics/compute/${login}/plugins > stargazers > generating charts`)
|
||||
charts = await Promise.all([{data: total, low: total.min, high: total.max}, {data: increments, ref: 0, low: increments.min, high: increments.max, sign: true}].map(({data: {dates: set}, high, low, ref, sign = false}) =>
|
||||
imports.chartist("line", {
|
||||
@@ -100,6 +100,6 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.starlists))
|
||||
if ((!enabled) || (!q.starlists) || (!imports.metadata.plugins.starlists.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -101,6 +101,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ inputs:
|
||||
Enable starlists plugin
|
||||
type: boolean
|
||||
default: no
|
||||
extras:
|
||||
- metrics.run.puppeteer.scrapping
|
||||
|
||||
plugin_starlists_limit:
|
||||
description: |
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, graphql, q, queries, imports, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, graphql, q, queries, imports, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.stars))
|
||||
if ((!enabled) || (!q.stars) || (!imports.metadata.plugins.stars.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -30,8 +30,6 @@ export default async function({login, data, graphql, q, queries, imports, accoun
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.support))
|
||||
if ((!enabled) || (!q.support) || (!imports.metadata.plugins.support.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -24,7 +24,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
await frame.waitForSelector(".user-profile-names", {timeout: 5000})
|
||||
}
|
||||
catch {
|
||||
throw {error: {message: "Could not find matching account on github.community"}}
|
||||
throw {error: {message: "Account does not exists on github.community"}}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +81,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ inputs:
|
||||
description: |
|
||||
Enable support plugin
|
||||
type: boolean
|
||||
default: no
|
||||
default: no
|
||||
extras:
|
||||
- metrics.run.puppeteer.scrapping
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, data, imports, q, account}, {enabled = false} = {}) {
|
||||
export default async function({login, data, imports, q, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.topics))
|
||||
if ((!enabled) || (!q.topics) || (!imports.metadata.plugins.topics.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -88,8 +88,6 @@ export default async function({login, data, imports, q, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ inputs:
|
||||
Enable topics plugin
|
||||
type: boolean
|
||||
default: no
|
||||
extras:
|
||||
- metrics.run.puppeteer.scrapping
|
||||
|
||||
plugin_topics_mode:
|
||||
description: |
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, imports, data, rest, q, account}, {enabled = false} = {}) {
|
||||
export default async function({login, imports, data, rest, q, account}, {enabled = false, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.traffic))
|
||||
if ((!enabled) || (!q.traffic) || (!imports.metadata.plugins.traffic.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -27,9 +27,6 @@ export default async function({login, imports, data, rest, q, account}, {enabled
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
let message = "An error occured"
|
||||
if (error.status === 403)
|
||||
message = "Insufficient token rights"
|
||||
throw {error: {message, instance: error}}
|
||||
throw imports.format.error(error, {descriptions:{"403":"Insufficient token scopes"}})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, imports, data, q, account}, {enabled = false, token = ""} = {}) {
|
||||
export default async function({login, imports, data, q, account}, {enabled = false, token = "", extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled) || (!q.tweets))
|
||||
if ((!enabled) || (!q.tweets) || (!imports.metadata.plugins.tweets.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -93,13 +93,6 @@ export default async function({login, imports, data, q, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
let message = "An error occured"
|
||||
if (error.isAxiosError) {
|
||||
const status = error.response?.status
|
||||
const description = error.response?.data?.errors?.[0]?.message ?? null
|
||||
message = `API returned ${status}${description ? ` (${description})` : ""}`
|
||||
error = error.response?.data ?? null
|
||||
}
|
||||
throw {error: {message, instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, token} = {}) {
|
||||
export default async function({login, q, imports, data, account}, {enabled = false, token, extras = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if (!enabled || !q.wakatime)
|
||||
if ((!enabled) || (!q.wakatime) || (!imports.metadata.plugins.wakatime.extras("enabled", {extras})))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
@@ -46,13 +46,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
let message = "An error occured"
|
||||
if (error.isAxiosError) {
|
||||
const status = error.response?.status
|
||||
message = `API returned ${status}`
|
||||
error = error.response?.data ?? null
|
||||
}
|
||||
throw {error: {message, instance: error}}
|
||||
throw imports.format.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user