Skip to content

Instantly share code, notes, and snippets.

@turbo
Created July 15, 2019 09:24
Show Gist options
  • Save turbo/36e87947a56cfaacec9d0356b3e521ba to your computer and use it in GitHub Desktop.
Save turbo/36e87947a56cfaacec9d0356b3e521ba to your computer and use it in GitHub Desktop.
[$github, $bitbucket]
| (flatten) as $all_projects
| ([$all_projects[] | select(.stats.languages != null).stats.languages | to_entries] | flatten) as $langstats
| (
[
$all_projects[]
| select(.stats.languages != null).stats.languages
| keys
]
| flatten
| [
group_by(.)[][0] as $language
| {
($language): {
in_projects: ([$langstats[] | select(.key == $language)] | length),
lines: ([$langstats[] | select(.key == $language).value.lines ] | add),
code: ([$langstats[] | select(.key == $language).value.code ] | add),
comment: ([$langstats[] | select(.key == $language).value.comment] | add),
files: ([$langstats[] | select(.key == $language).value.files ] | add)
}
}
]
| add
| to_entries
| sort_by(.value)
| reverse
| from_entries
) as $language_usage
| ($language_usage | [to_entries[].value]) as $language_usage_values
| {
date: (now),
stats: {
projects: ($all_projects | length),
scm_ratios: {
bitbucket: (($bitbucket | length) / ($all_projects | length)),
github: (($github | length) / ($all_projects | length))
},
code: {
lines: ([$language_usage_values[].lines ] | add),
code: ([$language_usage_values[].code ] | add),
comment: ([$language_usage_values[].comment] | add),
files: ([$language_usage_values[].files ] | add)
},
language_usage: $language_usage
},
projects: $all_projects
}
@henridf
Copy link

henridf commented Nov 25, 2019

@turbo nice pipeline. It would be great to have an example input to help learn some advanced jq via this example. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment