Skip to content

Instantly share code, notes, and snippets.

@alexeagle
Last active August 1, 2022 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexeagle/8d40bd35debc89f0450ebc5f3b610470 to your computer and use it in GitHub Desktop.
Save alexeagle/8d40bd35debc89f0450ebc5f3b610470 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Bazel Rulesets</title>
<meta name="description" content="Bazel rulesets vital statistics" />
<link rel="icon" type="image/png" href="/favicon.png" />
<!-- Webfont -->
<link
href="//fonts.googleapis.com/css?family=Source+Code+Pro:400,500,700|Open+Sans:400,600,700,800"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=Barlow:wght@300;400;500;600;700&display=swap"
rel="stylesheet"
/>
<!-- Bootstrap -->
<link
crossorigin="anonymous"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/devicons/devicon@v2.14.0/devicon.min.css"
/>
<style>
{{> css}}
</style>
</head>
<body>
<div class="wrapper">
{{> navbar}}
<div class="container">
<div class="row">
<div class="col-md-10">
<em>Last updated: {{> stats_updated}}</em>
<table>
<tr>
<th></th>
<th>Stars</th>
<th>Forks</th>
<th>Open Issues</th>
<th>
<a
href="https://docs.github.com/en/rest/reference/repos#get-community-profile-metrics"
>Community Health</a
>
</th>
<th>Last Update</th>
<th>Last Push</th>
<th>Last Tag</th>
<th>Commits last 52w</th>
</tr>
{{#each stats}}
<tr>
<th>
<a href="{{this.html_url}}"
>{{this.ghrepo}}</a
>
</th>
<td>{{this.repo.stargazers_count}}</td>
<td>{{this.repo.forks}}</td>
<td>{{this.repo.open_issues}}</td>
<td>
<a
href="https://github.com/{{this.ghrepo}}/community"
>
{{this.community_profile.health_percentage}}%
</a>
</td>
<td>
<span class="calc-age"
>{{this.repo.updated_at}}</span
>
</td>
<td>
<span class="calc-age"
>{{this.repo.pushed_at}}</span
>
</td>
<td>
{{#with this.latest_tag}}
<a href="{{this.url}}">
<span class="calc-age"
>{{this.committer.date}}</span
>
</a>
{{else}}<em>[no recent tag]</em>{{/with}}
</td>
<td>
<a
href="https://github.com/{{this.ghrepo}}/graphs/commit-activity"
>
<span
class="mini-bar-chart"
style="display: none"
>
{{this.participation}}
</span>
</a>
</td>
</tr>
{{/each}}
</table>
</div>
</div>
</div>
{{> footer}}
</div>
<script>
function age(d) {
const days = Math.floor(
(Date.now() - Date.parse(d)) / 1000 / 60 / 60 / 24
)
return `${days}d ago`
}
document.querySelectorAll('.calc-age').forEach((el) => {
el.innerHTML = age(el.innerHTML)
})
function barChart(s) {
return `<svg width="208" height="50">${s
.split(',')
.map(
(wk, idx) =>
`<rect width="4" height="${wk}" x="${idx * 4}" y="${
50 - wk
}" />`
)}</svg>`
}
document.querySelectorAll('.mini-bar-chart').forEach((el) => {
el.innerHTML = barChart(el.innerHTML)
el.style.display = 'inline-block'
})
</script>
</body>
</html>
#!/usr/bin/env bash
# Uses GitHub API to gather updates on the rulesets
# - show how active they are, recent releases, etc
# - tell us if there's a newer version we ought to slurp
set -o errexit -o pipefail -o nounset
GH_TOKEN=${GH_TOKEN}
function debug() {
# echo $@
true
}
function ghapi() {
curl 2>/dev/null \
-u "$USER:$GH_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/$1"
}
# Make the function visible to subshells
export -f ghapi
jq="node_modules/node-jq/bin/jq"
node src/config.js | \
$jq -r '.rulesets[]|[.ghrepo, .tag] | @tsv' |
tr '\t' ',' |
while IFS=$',' read -r ghrepo tag; do
out="stats/$ghrepo"
mkdir -p "$out"
ghapi "repos/$ghrepo" > $out/repo.json
ghapi "repos/$ghrepo/stats/participation" | $jq .all > $out/participation.json
ghapi "repos/$ghrepo/community/profile" > $out/community_profile.json
if [[ $tag =~ [0-9a-f]{40} ]]; then
debug "$ghrepo doesn't use a tag"
else
# rules_jvm_external has some tags starting with "2018"
# so we filter those out here by looking only for tags with a dot
latest_tag=$(ghapi repos/$ghrepo/tags |\
$jq -r '[.[] | select(.name | contains("."))] | .[0].name')
debug "$ghrepo current tag $tag latest tag $latest_tag"
# Exception: rules_webtesting has some older tags "v0.2.0" which appear first
# And has been dead for a year so don't bother checking it for releases
if [[ "$ghrepo" != "bazelbuild/rules_webtesting" ]]; then
if [[ "$tag" != "$latest_tag" ]]; then
echo >&2 "OUT OF DATE $ghrepo current tag $tag latest tag $latest_tag"
fi
fi
ghapi "repos/$ghrepo/commits/$latest_tag" | $jq -r .commit > $out/latest_tag.json
fi
done
date > stats/updated.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment