mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
Merge pull request #3730 from ipfs/feat/branch-archive
misc: add branch archiving script
This commit is contained in:
56
bin/archive-branches.sh
Executable file
56
bin/archive-branches.sh
Executable file
@ -0,0 +1,56 @@
|
||||
#!/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
|
||||
|
Reference in New Issue
Block a user