Commit 1ef5ecb6 authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #3730 from ipfs/feat/branch-archive

misc: add branch archiving script
parents 3ff5b743 c6355908
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -x
auth=""
#auth="-u kubuxu:$GH_TOKEN"
org=ipfs
repo=go-ipfs
arch_repo=go-ipfs-archived
api_repo="repos/$org/$repo"
exclusions=(
'master'
'release'
)
gh_api_next() {
links=$(grep '^Link:' | sed -e 's/Link: //' -e 's/, /\n/g')
echo "$links" | grep '; rel="next"' >/dev/null || return
link=$(echo "$links" | grep '; rel="next"' | sed -e 's/^<//' -e 's/>.*//')
curl $auth -f -sD >(gh_api_next) $link
}
gh_api() {
curl $auth -f -sD >(gh_api_next) "https://api.github.com/$1" | jq -s '[.[] | .[]]'
}
pr_branches() {
gh_api "$api_repo/pulls" | jq -r '.[].head.label | select(test("^ipfs:"))' \
| sed 's/^ipfs://'
}
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:$org/$arch_repo.git" || true
cat <(active_branches) <(pr_branches) <((IFS=$'\n'; echo "${exclusions[*]}")) \
| sort -u | comm - <(origin_refs | sort) -13 |\
while read ref; do
git push archived "origin/$ref:refs/heads/$ref/$(date --rfc-3339=date)"
git push origin --delete "$ref"
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment