Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load all language colours #467

Merged
merged 32 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
93edd5c
Try to replace colors
Nixinova Aug 3, 2021
1ea2f60
Set colour
Nixinova Aug 10, 2021
42e4e56
Move default
Nixinova Aug 10, 2021
e535b2f
Init colors
Nixinova Aug 10, 2021
9a43e36
Not lowercase
Nixinova Aug 10, 2021
4c18752
Bump Linguist
Nixinova Aug 10, 2021
3e0ba22
Only replace colour if set in config
Nixinova Aug 11, 2021
dce4d2e
Re-add default colour from fetch
Nixinova Aug 12, 2021
d9e1da2
Avoid overwriting existing colour if not found
Nixinova Aug 12, 2021
fb385ef
Avoid `??=`
Nixinova Aug 12, 2021
8f5f155
Debugging statement
Nixinova Aug 12, 2021
95aa9c7
Debug log all results
Nixinova Aug 12, 2021
bcc2739
Show debug statement
Nixinova Aug 12, 2021
2359219
Load all colors dirrectly from Linguist
Nixinova Aug 12, 2021
609ef63
Debug results
Nixinova Aug 12, 2021
d8ec3e5
Further debug
Nixinova Aug 13, 2021
1180a18
Default to fetched color [skip ci]
Nixinova Aug 13, 2021
2277289
Don't overwrite results.colors [skip ci]
Nixinova Aug 13, 2021
40afc09
Change debug statements [skip ci]
Nixinova Aug 13, 2021
adb935b
Assign recent colors to all colors
Nixinova Aug 13, 2021
8cb6f1b
Bump Linguist
Nixinova Aug 13, 2021
8f8cc1a
Remove debug [skip ci]
Nixinova Aug 13, 2021
6db4e5e
Revert "Bump Linguist"
Nixinova Aug 13, 2021
ca425f7
Debug
Nixinova Aug 19, 2021
26fb96e
Bump Linguist
Nixinova Aug 19, 2021
1abc78e
Debug
Nixinova Aug 19, 2021
53b44f6
Fix overwriting
Nixinova Aug 19, 2021
9a4971b
Remove debug
Nixinova Aug 19, 2021
d0aa80d
Make sure custom colors are used
Nixinova Aug 19, 2021
02412c6
Fix overwrite
Nixinova Aug 19, 2021
7f34d31
Merge branch 'master' into load-all-colors
Nixinova Aug 19, 2021
a65b8fb
Fix doc [skip ci]
Nixinova Aug 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"faker": "^5.5.3",
"jimp": "^0.16.1",
"js-yaml": "^4.1.0",
"linguist-js": "^1.6.1",
"linguist-js": "^1.7.0",
"marked": "^3.0.0",
"memory-cache": "^0.2.0",
"minimatch": "^3.0.4",
Expand Down
2 changes: 1 addition & 1 deletion source/plugins/languages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ For better results, it's advised to add either your surnames and eventually no-r
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
plugin_languages_recent_categories: markup, programming, data # Display only languages that match these categories in recently-used section
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
7 changes: 4 additions & 3 deletions source/plugins/languages/analyzers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import linguist from "linguist-js"
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}
const results = {total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:0}
for (const repository of repositories) {
//Skip repository if asked
if ((skipped.includes(repository.name.toLocaleLowerCase())) || (skipped.includes(`${repository.owner.login}/${repository.name}`.toLocaleLowerCase()))) {
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function recent({login, data, imports, rest, account}, {skipped = [

//Get user recent activity
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
const commits = [], pages = Math.ceil(load/100), results = {total:0, lines:{}, stats:{}, commits:0, files:0, missed:0, days}
const commits = [], pages = Math.ceil(load/100), results = {total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:0, days}
try {
for (let page = 1; page <= pages; page++) {
console.debug(`metrics/compute/${login}/plugins > languages > loading page ${page}`)
Expand Down Expand Up @@ -140,6 +140,7 @@ async function analyze({login, imports, data}, {results, path, categories = ["pr
//Gather language data
console.debug(`metrics/compute/${login}/plugins > languages > indepth > running linguist`)
const {results:files, languages:languageResults} = await linguist(path)
Object.assign(results.colors, Object.fromEntries(Object.entries(languageResults.all).map(([lang, {color}]) => [lang, color])))

//Processing diff
const per_page = 1
Expand Down Expand Up @@ -212,7 +213,7 @@ if (/languages.analyzers.mjs$/.test(process.argv[1])) {

//Prepare call
const imports = await import("../../app/metrics/utils.mjs")
const results = {total:0, lines:{}, stats:{}, missed:0}
const results = {total:0, lines:{}, colors:{}, stats:{}, missed:0}
console.debug = log => /exited with code null/.test(log) ? console.error(log.replace(/^.*--max-count=(?<step>\d+) --skip=(?<start>\d+).*$/, (_, step, start) => `error: skipped commits ${start} from ${Number(start)+Number(step)}`)) : null

//Analyze repository
Expand Down
16 changes: 13 additions & 3 deletions source/plugins/languages/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
//Iterate through user's repositories and retrieve languages data
console.debug(`metrics/compute/${login}/plugins > languages > processing ${data.user.repositories.nodes.length} repositories`)
const languages = {unique, sections, details, indepth, colors:{}, total:0, stats:{}, "stats.recent":{}}
const customColors = {}
for (const repository of data.user.repositories.nodes) {
//Skip repository if asked
if ((skipped.includes(repository.name.toLocaleLowerCase())) || (skipped.includes(`${repository.owner.login}/${repository.name}`.toLocaleLowerCase()))) {
Expand All @@ -47,7 +48,10 @@ export default async function({login, data, imports, q, rest, account}, {enabled
//Process repository languages
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
languages.stats[name] = (languages.stats[name] ?? 0) + size
languages.colors[name] = colors[name.toLocaleLowerCase()] ?? color ?? "#ededed"
if (colors[name.toLocaleLowerCase()])
customColors[name] = colors[name.toLocaleLowerCase()]
if (!languages.colors[name])
languages.colors[name] = color
languages.total += size
}
}
Expand All @@ -58,12 +62,15 @@ export default async function({login, data, imports, q, rest, account}, {enabled
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, categories:_recent_categories ?? categories, days:_recent_days, load:_recent_load})
Object.assign(languages.colors, languages["stats.recent"].colors)
}

//Indepth mode
if (indepth) {
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}, {skipped, categories}))
Object.assign(languages.colors, existingColors)
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed} commits`)
}
}
Expand All @@ -74,11 +81,14 @@ export default async function({login, data, imports, q, rest, account}, {enabled
languages[section] = Object.entries(stats).filter(([name]) => !ignored.includes(name.toLocaleLowerCase())).sort(([_an, a], [_bn, b]) => b - a).slice(0, limit).map(([name, value]) => ({name, value, size:value, color:languages.colors[name], x:0})).filter(({value}) => value / total > threshold)
const visible = {total:Object.values(languages[section]).map(({size}) => size).reduce((a, b) => a + b, 0)}
for (let i = 0; i < languages[section].length; i++) {
const {name} = languages[section][i]
languages[section][i].value /= visible.total
languages[section][i].x = (languages[section][i - 1]?.x ?? 0) + (languages[section][i - 1]?.value ?? 0)
languages[section][i].lines = lines[languages[section][i].name] ?? 0
if ((colors[i]) && (!colors[languages[section][i].name.toLocaleLowerCase()]))
languages[section][i].lines = lines[name] ?? 0
if ((colors[i]) && (!colors[name.toLocaleLowerCase()]))
languages[section][i].color = colors[i]
else
languages[section][i].color = customColors[name] ?? languages.colors[name] ?? "#ededed"
}
}

Expand Down