Last active
December 2, 2018 03:11
-
-
Save spiffxp/8ed7a757f97439ab490e8b71d4ee289b 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 | |
name=$(basename ${0%.*}) | |
data_dir=data/${name} | |
mkdir -p ${data_dir} | |
orgs="kubernetes kubernetes-sigs kubernetes-incubator kubernetes-client kubernetes-csi" | |
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 | |
refresh_sigs_yaml=false | |
refresh_repos=false | |
refresh_root_owners=false | |
refresh_prow_plugins_yaml=false | |
refresh_prow_config_yaml=false | |
refresh_testgrid_config_yaml=false | |
refresh_staging_src_build=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} yq -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} yq '.["branch-protection"].orgs | keys[]' > ${branch_protected_orgs} | |
orgs_with_tide=${data_dir}/orgs-with-tide.txt | |
<${prow_config_yaml} yq '.tide.queries | map(.orgs // []) | flatten[]' > ${orgs_with_tide} | |
org_repos_with_tide=${data_dir}/org-repos-with-tide.txt | |
<${prow_config_yaml} yq '.tide.queries | map(.repos // []) | flatten[]' > ${org_repos_with_tide} | |
# TODO: which repos are using prow for presubmits, postsubmits, periodics | |
# org_repos_with_presubmits=$(<${prow_config_yaml} yq -r '.presubmits | keys[]') | |
# org_repos_with_postsubmits=$(<${prow_config_yaml} yq -r '.postsubmits | keys[]') | |
echo "| org/repo | in sigs.yaml? | has owners? | has approve? | in tide? | branch protected? |" | |
echo "| -------- | ------------- | ----------- | ------------ | -------- | ----------------- |" | |
for org in ${orgs}; do | |
repos_json=${data_dir}/${org}-repos.json | |
if ${refresh_repos}; 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 | |
in_sigs=$(grep -q ${org_repo} ${sigs_yaml} || echo -n "missing") | |
has_owners=$(grep -q "404: Not Found" ${root_owners} && echo -n "no owners") | |
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} yq -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 | |
done | |
# sort by sigs, owners, branch_protected, approve, in_tide, name | |
done | sort -r -t '|' -k 3 -k 4 -k 5 -k 6 -k 7 -k 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment