2020-05-13 02:14:01 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
|
|
|
|
org=filecoin-project
|
|
|
|
repo=lotus
|
2020-05-13 20:30:18 +00:00
|
|
|
arch_repo="$org/lotus-archived"
|
2020-05-13 02:14:01 +00:00
|
|
|
api_repo="repos/$org/$repo"
|
|
|
|
|
|
|
|
exclusions=(
|
|
|
|
'master'
|
2021-11-25 18:52:04 +00:00
|
|
|
'main'
|
2021-11-25 19:19:20 +00:00
|
|
|
'releases'
|
2020-05-13 02:14:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
gh_api_next() {
|
2021-11-25 19:14:19 +00:00
|
|
|
links=$(grep '^link:' | sed -e 's/link: //' -e 's/, /\n/g')
|
2020-05-13 02:14:01 +00:00
|
|
|
echo "$links" | grep '; rel="next"' >/dev/null || return
|
|
|
|
link=$(echo "$links" | grep '; rel="next"' | sed -e 's/^<//' -e 's/>.*//')
|
|
|
|
|
|
|
|
curl -n -f -sD >(gh_api_next) "$link"
|
|
|
|
}
|
|
|
|
|
|
|
|
gh_api() {
|
|
|
|
curl -n -f -sD >(gh_api_next) "https://api.github.com/$1" | jq -s '[.[] | .[]]'
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_branches() {
|
2020-05-13 02:19:14 +00:00
|
|
|
gh_api "$api_repo/pulls" | jq -r '.[].head.label | select(test("^'"$org"':"))' \
|
|
|
|
| sed 's/^'"$org"'://'
|
2020-05-13 02:14:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
origin_refs() {
|
|
|
|
format=${1-'%(refname:short)'}
|
|
|
|
|
|
|
|
git for-each-ref --format "$format" refs/remotes/origin | sed 's|^origin/||'
|
|
|
|
}
|
|
|
|
|
|
|
|
active_branches() {
|
|
|
|
origin_refs '%(refname:short) %(committerdate:unix)' |awk \
|
|
|
|
' BEGIN { monthAgo = systime() - 31*24*60*60 }
|
|
|
|
{ if ($2 > monthAgo) print $1 }
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
git remote add archived "git@github.com:$arch_repo.git" || true
|
|
|
|
|
2021-11-25 18:52:04 +00:00
|
|
|
branches_to_move="$(cat <(active_branches) <(pr_branches) <((IFS=$'\n'; echo "${exclusions[*]}")) | sort -u | comm - <(origin_refs | sort) -13 | grep -v -e '^release/' -e '^ntwk-')"
|
2020-05-13 02:14:01 +00:00
|
|
|
|
|
|
|
echo "================"
|
|
|
|
printf "%s\n" "$branches_to_move"
|
|
|
|
echo "================"
|
|
|
|
|
|
|
|
echo "Please confirm move of above branches [y/N]:"
|
|
|
|
|
2020-05-13 02:21:00 +00:00
|
|
|
read -r line
|
|
|
|
case "$line" in
|
2020-05-13 02:14:01 +00:00
|
|
|
[Yy]|[Yy][Ee][Ss]) ;;
|
|
|
|
*) exit 1 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
printf "%s\n" "$branches_to_move" | \
|
|
|
|
while read -r ref; do
|
|
|
|
git push archived "origin/$ref:refs/heads/$ref/$(date --rfc-3339=date)"
|
|
|
|
git push origin --delete "$ref"
|
|
|
|
done
|
|
|
|
|