Add option to ignore languages/skip repositories in languages plugin (#22)
* Add option to ignore languages/skip repositories in languages plugin * Fix logs on error and first attempt to fix update of file larger than >1mb * Use variable branch name * Update version number
This commit is contained in:
@@ -43,6 +43,8 @@
|
||||
"base.metadata":"Metadata",
|
||||
},
|
||||
options:{
|
||||
"languages.ignored":"",
|
||||
"languages.skipped":"",
|
||||
"pagespeed.detailed":false,
|
||||
"habits.from":100,
|
||||
"music.playlist":"",
|
||||
@@ -103,8 +105,9 @@
|
||||
action() {
|
||||
return [
|
||||
`# Visit https://github.com/lowlighter/metrics/blob/master/action.yml for full reference`,
|
||||
`name: GitHub metrics as SVG image`,
|
||||
`name: GitHub metrics`,
|
||||
`on:`,
|
||||
` # Schedule updates`,
|
||||
` schedule: [{cron: "0 * * * *"}]`,
|
||||
` push: {branches: "master"}`,
|
||||
`jobs:`,
|
||||
@@ -113,16 +116,19 @@
|
||||
` steps:`,
|
||||
` - uses: lowlighter/metrics@latest`,
|
||||
` with:`,
|
||||
` # Setup a personal token in your secrets.`,
|
||||
` # You'll need to setup a personal token in your secrets.`,
|
||||
` token: ${"$"}{{ secrets.METRICS_TOKEN }}`,
|
||||
` # You can also setup a bot token for commits`,
|
||||
` # committer_token: ${"$"}{{ secrets.METRICS_BOT_TOKEN }}`,
|
||||
` # GITHUB_TOKEN is a special auto-generated token used for commits`,
|
||||
` committer_token: ${"$"}{{ secrets.GITHUB_TOKEN }}`,
|
||||
``,
|
||||
` # Options`,
|
||||
` user: ${this.user }`,
|
||||
` template: ${this.templates.selected}`,
|
||||
` base: ${Object.keys(this.plugins.enabled.base).join(", ") }`,
|
||||
...Object.entries(this.plugins.enabled).filter(([key, value]) => (key !== "base")&&(value)).map(([key]) => ` plugin_${key}: yes`)
|
||||
` base: ${Object.entries(this.plugins.enabled.base).filter(([key, value]) => value).map(([key]) => key).join(", ")||'""'}`,
|
||||
...[
|
||||
...Object.entries(this.plugins.enabled).filter(([key, value]) => (key !== "base")&&(value)).map(([key]) => ` plugin_${key}: yes`),
|
||||
...Object.entries(this.plugins.options).filter(([key, value]) => value).filter(([key, value]) => this.plugins.enabled[key.split(".")[0]]).map(([key, value]) => ` plugin_${key.replace(/[.]/, "_")}: ${typeof value === "boolean" ? {true:"yes", false:"no"}[value] : value}`)
|
||||
].sort(),
|
||||
].join("\n")
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</label>
|
||||
</div>
|
||||
<i>*Additional plugins may be available when used as GitHub Action</i>
|
||||
<template v-if="(plugins.enabled.music)||(plugins.enabled.pagespeed)||(plugins.enabled.habits)||(plugins.enabled.posts)||(plugins.enabled.isocalendar)||(plugins.enabled.projects)||(plugins.enabled.topics)">
|
||||
<template v-if="(plugins.enabled.music)||(plugins.enabled.pagespeed)||(plugins.enabled.languages)||(plugins.enabled.habits)||(plugins.enabled.posts)||(plugins.enabled.isocalendar)||(plugins.enabled.projects)||(plugins.enabled.topics)">
|
||||
<h3>2.3 Configure additional plugins</h3>
|
||||
<div class="options">
|
||||
<div class="options-group" v-if="plugins.enabled.music">
|
||||
@@ -72,6 +72,17 @@
|
||||
<input type="checkbox" v-model="plugins.options['pagespeed.detailed']" @change="load">
|
||||
</label>
|
||||
</div>
|
||||
<div class="options-group" v-if="plugins.enabled.languages">
|
||||
<h4>{{ plugins.descriptions.languages }}</h4>
|
||||
<label>
|
||||
Ignored languages (comma separated)
|
||||
<input type="text" v-model="plugins.options['languages.ignored']" @change="load">
|
||||
</label>
|
||||
<label>
|
||||
Skipped repositories (comma separated)
|
||||
<input type="text" v-model="plugins.options['languages.skipped']" @change="load">
|
||||
</label>
|
||||
</div>
|
||||
<div class="options-group" v-if="plugins.enabled.habits">
|
||||
<h4>{{ plugins.descriptions.habits }}</h4>
|
||||
<label>
|
||||
|
||||
@@ -1,18 +1,36 @@
|
||||
//Setup
|
||||
export default async function ({data, q}, {enabled = false} = {}) {
|
||||
export default async function ({login, data, q}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.languages))
|
||||
return null
|
||||
//Parameters override
|
||||
let {"languages.ignored":ignored = "", "languages.skipped":skipped = ""} = q
|
||||
//Ignored languages
|
||||
ignored = decodeURIComponent(ignored).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x)
|
||||
//Skipped repositories
|
||||
skipped = decodeURIComponent(skipped).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x)
|
||||
//Iterate through user's repositories and retrieve languages data
|
||||
const languages = {colors:{}, total:0, stats:{}}
|
||||
for (const repository of data.user.repositories.nodes) {
|
||||
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
|
||||
languages.stats[name] = (languages.stats[name] ?? 0) + size
|
||||
languages.colors[name] = color ?? "#ededed"
|
||||
languages.total += size
|
||||
}
|
||||
//Skip repository if asked
|
||||
if (skipped.includes(repository.name.toLocaleLowerCase())) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > skipped repository ${repository.name}`)
|
||||
continue
|
||||
}
|
||||
//Process repository languages
|
||||
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
|
||||
//Ignore language if asked
|
||||
if (ignored.includes(name.toLocaleLowerCase())) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ignored language ${name}`)
|
||||
continue
|
||||
}
|
||||
//Update language stats
|
||||
languages.stats[name] = (languages.stats[name] ?? 0) + size
|
||||
languages.colors[name] = color ?? "#ededed"
|
||||
languages.total += size
|
||||
}
|
||||
}
|
||||
//Compute languages stats
|
||||
Object.keys(languages.stats).map(name => languages.stats[name] /= languages.total)
|
||||
|
||||
@@ -129,7 +129,6 @@
|
||||
`${new imports.url.URLSearchParams({grant_type:"refresh_token", refresh_token, client_id, client_secret})}`,
|
||||
{headers:{"Content-Type":"application/x-www-form-urlencoded"}},
|
||||
)
|
||||
console.log(access)
|
||||
console.debug(`metrics/compute/${login}/plugins > music > got new access token`)
|
||||
//Retriev tracks
|
||||
tracks = (await imports.axios(`https://api.spotify.com/v1/me/player/recently-played?limit=${limit}&after=${timestamp}`, {headers:{
|
||||
|
||||
Reference in New Issue
Block a user