Last active
September 6, 2019 23:57
-
-
Save spiffxp/324824f2a5bf4d6c7d56c6b3a7f795ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
name=$(basename ${0%.*}) | |
data_dir=data/${name} | |
mkdir -p ${data_dir} | |
orgs="kubernetes kubernetes-client kubernetes-csi kubernetes-sigs kubernetes-incubator" | |
sigs_yaml=${data_dir}/sigs.yaml | |
prow_config_yaml=${data_dir}/config.yaml | |
prow_plugins_yaml=${data_dir}/plugins.yaml | |
testgrid_config_yaml=${data_dir}/testgrid.yaml | |
staging_src_build=${data_dir}/staging-build | |
online=true | |
refresh_sigs_yaml=${online} | |
refresh_repos_json=${online} | |
refresh_root_owners=${online} | |
refresh_prow_plugins_yaml=${online} | |
refresh_prow_config_yaml=${online} | |
refresh_testgrid_config_yaml=${online} | |
refresh_staging_src_build=${online} | |
refresh_contributing_md=${online} | |
refresh_code_of_conduct_md=${online} | |
output_audit_table=true | |
# not strictly needed yet | |
refresh_repo_json=false | |
refresh_repo_labels_txt=false | |
if ${refresh_sigs_yaml}; then | |
curl -s https://raw.githubusercontent.com/kubernetes/community/master/sigs.yaml > "${sigs_yaml}" | |
fi | |
if ${refresh_prow_config_yaml}; then | |
curl -s https://raw.githubusercontent.com/kubernetes/test-infra/master/prow/config.yaml > "${prow_config_yaml}" | |
fi | |
if ${refresh_prow_plugins_yaml}; then | |
curl -s https://raw.githubusercontent.com/kubernetes/test-infra/master/prow/plugins.yaml > "${prow_plugins_yaml}" | |
fi | |
if ${refresh_testgrid_config_yaml}; then | |
curl -s https://raw.githubusercontent.com/kubernetes/test-infra/master/testgrid/config.yaml > "${testgrid_config_yaml}" | |
fi | |
if ${refresh_staging_src_build}; then | |
curl -s https://raw.githubusercontent.com/kubernetes/kubernetes/master/staging/src/BUILD > "${staging_src_build}" | |
fi | |
sigs=$(<${sigs_yaml} yaml2json | jq -r '.sigs[].dir') | |
staging_repos=${data_dir}/staging-repos.txt | |
grep //staging ${staging_src_build} | tr -d '",' | cut -d/ -f5,6 | cut -d: -f1 | sort | uniq | sed -e 's/k8s.io/kubernetes/' >${staging_repos} | |
branch_protected_orgs=${data_dir}/orgs-with-branch-protection.txt | |
<${prow_config_yaml} yaml2json | jq '.["branch-protection"].orgs | keys[]' > ${branch_protected_orgs} | |
orgs_with_tide=${data_dir}/orgs-with-tide.txt | |
<${prow_config_yaml} yaml2json | jq '.tide.queries | map(.orgs // []) | flatten[]' > ${orgs_with_tide} | |
org_repos_with_tide=${data_dir}/org-repos-with-tide.txt | |
<${prow_config_yaml} yaml2json | jq '.tide.queries | map(.repos // []) | flatten[]' > ${org_repos_with_tide} | |
if ${output_audit_table}; then | |
echo "| org/repo | in sigs.yaml? | has owners? | has approve? | in tide? | branch protected? |" | |
echo "| -------- | ------------- | ----------- | ------------ | -------- | ----------------- |" | |
fi | |
for org in ${orgs}; do | |
repos_json=${data_dir}/${org}-repos.json | |
if ${refresh_repos_json}; then | |
curl -sH "Authorization: token ${GITHUB_TOKEN}" \ | |
"https://api.github.com/orgs/${org}/repos?per_page=100" > ${repos_json} | |
fi | |
org_repos=$(<${repos_json} jq -r .[].full_name) | |
for org_repo in ${org_repos}; do | |
repo=$(echo ${org_repo} | cut -d/ -f2) | |
repo_dir=${data_dir}/${org_repo} | |
mkdir -p ${repo_dir} | |
root_owners=${repo_dir}/OWNERS | |
if ${refresh_root_owners}; then | |
curl -s https://raw.githubusercontent.com/${org_repo}/master/OWNERS > ${root_owners} | |
fi | |
contributing_md=${repo_dir}/CONTRIBUTING.md | |
if ${refresh_contributing_md}; then | |
curl -s https://raw.githubusercontent.com/${org_repo}/master/CONTRIBUTING.md > ${contributing_md} | |
fi | |
code_of_conduct_md=${repo_dir}/code-of-conduct.md | |
if ${refresh_code_of_conduct_md}; then | |
curl -s https://raw.githubusercontent.com/${org_repo}/master/code-of-conduct.md > ${code_of_conduct_md} | |
fi | |
repo_json=${repo_dir}/repo.json | |
if ${refresh_repo_json}; then | |
curl -sH "Authorization: token ${GITHUB_TOKEN}" \ | |
"https://api.github.com/repos/${org_repo}" > ${repo_json} | |
fi | |
repo_labels_txt=${repo_dir}/labels.txt | |
if ${refresh_repo_labels_txt}; then | |
echo "" >${repo_labels_txt} | |
for i in $(seq 1 3); do | |
curl -sH "Authorization: token ${GITHUB_TOKEN}" \ | |
"https://api.github.com/repos/${org_repo}/labels?per_page=100&page=${i}" | jq .[].name >> ${repo_labels_txt} | |
done | |
fi | |
if ${output_audit_table}; then | |
in_sigs=$(grep -q ${org_repo} ${sigs_yaml} || echo -n "missing") | |
has_owners=$((grep -q "404: Not Found" ${root_owners} && echo -n "no owners") || true) | |
has_contributing_md=$((grep -q "404: Not Found" ${contributing_md} && echo -n "no CONTRIBUTING.md") || true) | |
has_code_of_conduct_md=$((grep -q "404: Not Found" ${code_of_conduct_md} && echo -n "no code-of-conduct.md") || true) | |
if grep -q ${org_repo} ${staging_repos}; then | |
# since k/k is done, assume staging repos done | |
has_approve="" | |
in_tide="" | |
branch_protected="" | |
else | |
has_approve=$(<${prow_plugins_yaml} yaml2json | jq -r \ | |
--arg o ${org} \ | |
--arg o_r ${org_repo} \ | |
'if ([.plugins[$o] // [], .plugins[$o_r] // []] | flatten | contains(["approve"])) then "" else "no approve" end') | |
in_tide=$(echo "{}" | jq -r \ | |
--slurpfile owt "${orgs_with_tide}" \ | |
--slurpfile orwt "${org_repos_with_tide}" \ | |
--arg o "${org}" \ | |
--arg o_r "${org_repo}" \ | |
'if (($owt | contains([$o])) // ($orwt | contains([$o_r]))) then "" else "not in tide" end') | |
branch_protected=$(echo "{}" | jq -r \ | |
--slurpfile bpo "${branch_protected_orgs}" \ | |
--arg o "${org}" \ | |
--arg o_r "${org_repo}" \ | |
'if ($bpo | contains([$o])) then "" else "no branch protection" end') | |
fi | |
echo -n "| [${org_repo}](https://github.com/${org_repo}) | " | |
echo -n "${in_sigs} | " | |
echo -n "${has_owners} | " | |
echo -n "${has_approve} | " | |
echo -n "${in_tide} | " | |
echo -n "${branch_protected} | " | |
echo | |
fi | |
done | |
done | sort -r -t '|' -k 3 -k 4 -k 5 -k 6 -k 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment