File tree 1 file changed +56
-0
lines changed 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$' \n\t '
4
+ set -x
5
+
6
+ auth=" "
7
+ # auth="-u kubuxu:$GH_TOKEN"
8
+ org=ipfs
9
+ repo=go-ipfs
10
+ arch_repo=go-ipfs-archived
11
+ api_repo=" repos/$org /$repo "
12
+
13
+ exclusions=(
14
+ ' master'
15
+ ' release'
16
+ )
17
+
18
+ gh_api_next () {
19
+ links=$( grep ' ^Link:' | sed -e ' s/Link: //' -e ' s/, /\n/g' )
20
+ echo " $links " | grep ' ; rel="next"' > /dev/null || return
21
+ link=$( echo " $links " | grep ' ; rel="next"' | sed -e ' s/^<//' -e ' s/>.*//' )
22
+
23
+ curl $auth -f -sD >( gh_api_next) $link
24
+ }
25
+
26
+ gh_api () {
27
+ curl $auth -f -sD >( gh_api_next) " https://api.github.com/$1 " | jq -s ' [.[] | .[]]'
28
+ }
29
+
30
+ pr_branches () {
31
+ gh_api " $api_repo /pulls" | jq -r ' .[].head.label | select(test("^ipfs:"))' \
32
+ | sed ' s/^ipfs://'
33
+ }
34
+
35
+ origin_refs () {
36
+ format=${1-' %(refname:short)' }
37
+
38
+ git for-each-ref --format " $format " refs/remotes/origin | sed ' s|^origin/||'
39
+ }
40
+
41
+ active_branches () {
42
+ origin_refs ' %(refname:short) %(committerdate:unix)' | awk \
43
+ ' BEGIN { monthAgo = systime() - 31*24*60*60 }
44
+ { if ($2 > monthAgo) print $1 }
45
+ '
46
+ }
47
+
48
+ git remote add archived
" [email protected] :$org /$arch_repo .git" || true
49
+
50
+ cat <( active_branches) <( pr_branches) <( (IFS=$' \n ' ; echo " ${exclusions[*]} " )) \
51
+ | sort -u | comm - <( origin_refs | sort) -13 | \
52
+ while read ref; do
53
+ git push archived " origin/$ref :refs/heads/$ref /$( date --rfc-3339=date) "
54
+ git push origin --delete " $ref "
55
+ done
56
+
You can’t perform that action at this time.
0 commit comments