Skip to content

Commit

Permalink
Add options to configure which language categories to display (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Aug 17, 2021
1 parent 34004e8 commit 7534c37
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
2 changes: 2 additions & 0 deletions source/plugins/languages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ For better results, it's advised to add either your surnames and eventually no-r
plugin_languages_limit: 8 # Display up to 8 languages
plugin_languages_sections: most-used, recently-used # Display most used and recently used languages stats
plugin_languages_indepth: no # Get indepth stats (see documentation before enabling)
plugin_languages_categories: programming # Display only languages that match these categories in most-used section
plugin_languages_categories: markup, programming, data # Display only languages that match these categories in recently-used section

This comment has been minimized.

Copy link
@Nixinova

Nixinova Aug 18, 2021

Author Contributor

Missed a _recent here.

plugin_languages_recent_load: 500 # Load up to 500 events to compute recently used stats
plugin_languages_recent_days: 7 # Limit recently used stats to last week
commits_authoring: [email protected] # Surnames or email addresses used to identify your commits
Expand Down
14 changes: 7 additions & 7 deletions source/plugins/languages/analyzers.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import linguist from "linguist-js"

/**Indepth analyzer */
export async function indepth({login, data, imports, repositories}, {skipped}) {
export async function indepth({login, data, imports, repositories}, {skipped, categories}) {

//Compute repositories stats from fetched repositories
const results = {total:0, lines:{}, stats:{}, commits:0, files:0, missed:0}
Expand Down Expand Up @@ -29,7 +29,7 @@ export async function indepth({login, data, imports, repositories}, {skipped}) {
await git.clone(`https://github.com/${repo}`, ".").status()

//Analyze repository
await analyze(arguments[0], {results, path})
await analyze(arguments[0], {results, path, categories})
}
catch (error) {
console.debug(`metrics/compute/${login}/plugins > languages > indepth > an error occured while processing ${repo}, skipping...`)
Expand All @@ -44,7 +44,7 @@ export async function indepth({login, data, imports, repositories}, {skipped}) {
}

/**Recent languages activity */
export async function recent({login, data, imports, rest, account}, {skipped = [], days = 0, load = 0, tempdir = "recent"}) {
export async function recent({login, data, imports, rest, account}, {skipped = [], categories, days = 0, load = 0, tempdir = "recent"}) {

//Get user recent activity
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
Expand Down Expand Up @@ -118,7 +118,7 @@ export async function recent({login, data, imports, rest, account}, {skipped = [
await git.init().add(".").addConfig("user.name", data.shared["commits.authoring"]?.[0] ?? login).addConfig("user.email", "<>").commit("linguist").status()

//Analyze repository
await analyze(arguments[0], {results, path:imports.paths.join(path, directory)})
await analyze(arguments[0], {results, path:imports.paths.join(path, directory), categories})

//Since we reproduce a "partial repository" with a single commit, use number of commits retrieved instead
results.commits = commits.length
Expand All @@ -136,7 +136,7 @@ export async function recent({login, data, imports, rest, account}, {skipped = [
}

/**Analyze a single repository */
async function analyze({login, imports, data}, {results, path}) {
async function analyze({login, imports, data}, {results, path, categories = ["programming", "markup"]}) {
//Gather language data
console.debug(`metrics/compute/${login}/plugins > languages > indepth > running linguist`)
const {results:files, languages:languageResults} = await linguist(path)
Expand Down Expand Up @@ -166,12 +166,12 @@ async function analyze({login, imports, data}, {results, path}) {
if (/^[+]{3}\sb[/](?<file>[\s\S]+)$/.test(line)) {
file = line.match(/^[+]{3}\sb[/](?<file>[\s\S]+)$/)?.groups?.file.replace(/^/, `${path}/`) ?? null
lang = files[file] ?? null
if (lang in languageResults.data || lang in languageResults.prose)
if (["data", "markup", "programming", "prose"].map(type => categories.includes(type) && lang in languageResults[type]).filter(type => type).length === 0)
lang = null
edited.add(file)
return
}
//Ignore unkonwn languages
//Ignore unknown languages
if (!lang)
return
//Added line marker
Expand Down
8 changes: 4 additions & 4 deletions source/plugins/languages/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//Imports
import { indepth as indepth_analyzer, recent as recent_analyzer } from "./analyzers.mjs"
import {indepth as indepth_analyzer, recent as recent_analyzer} from "./analyzers.mjs"

//Setup
export default async function({login, data, imports, q, rest, account}, {enabled = false, extras = false} = {}) {
Expand All @@ -17,7 +17,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
}

//Load inputs
let {ignored, skipped, colors, aliases, details, threshold, limit, indepth, sections, "recent.load":_recent_load, "recent.days":_recent_days} = imports.metadata.plugins.languages.inputs({data, account, q})
let {ignored, skipped, colors, aliases, details, threshold, limit, indepth, sections, categories, "recent.categories":_recent_categories, "recent.load":_recent_load, "recent.days":_recent_days} = imports.metadata.plugins.languages.inputs({data, account, q})
threshold = (Number(threshold.replace(/%$/, "")) || 0) / 100
skipped.push(...data.shared["repositories.skipped"])
if (!limit)
Expand Down Expand Up @@ -57,13 +57,13 @@ export default async function({login, data, imports, q, rest, account}, {enabled
//Recently used languages
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, days:_recent_days, load:_recent_load})
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, categories:_recent_categories ?? categories, days:_recent_days, load:_recent_load})
}

//Indepth mode
if (indepth) {
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped}))
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped, categories}))
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed} commits`)
}
}
Expand Down
24 changes: 24 additions & 0 deletions source/plugins/languages/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ inputs:
description: Indepth languages processing (see documentation before enabling)
type: boolean
default: false

# GitHub language categories to display
plugin_languages_categories:
description: Language categories to display
type: array
format: comma-separated
values:
- data
- markup
- programming
- prose
default: markup, programming

# GitHub language categories to display in recently-used section
plugin_languages_recent_categories:
description: Language categories to display (for recently used section)
type: array
format: comma-separated
values:
- data
- markup
- programming
- prose
default: markup, programming

# Number of activity events to load (for recently used languages statistics)
# A high number will consume more requests
Expand Down
9 changes: 8 additions & 1 deletion source/plugins/languages/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
plugin_languages: yes
plugin_languages_ignored: html, css, dockerfile


- name: Language plugin (skipped repositories)
uses: lowlighter/metrics@latest
with:
Expand Down Expand Up @@ -40,6 +39,13 @@
plugin_languages: yes
plugin_languages_threshold: 2%

- name: Language plugin (with categories)
uses: lowlighter/metrics@latest
with:
token: MOCKED_TOKEN
plugin_languages: yes
plugin_languages_categories: programming, data

- name: Language plugin (complete)
uses: lowlighter/metrics@latest
with:
Expand All @@ -50,3 +56,4 @@
plugin_languages_colors: rainbow
plugin_languages_details: bytes-size, percentage
plugin_languages_threshold: 2%
plugin_languages_categories: programming, markup, data

0 comments on commit 7534c37

Please sign in to comment.