Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
1ef5ecb6
Commit
1ef5ecb6
authored
Mar 01, 2017
by
Jeromy Johnson
Committed by
GitHub
Mar 01, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3730 from ipfs/feat/branch-archive
misc: add branch archiving script
parents
3ff5b743
c6355908
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
bin/archive-branches.sh
bin/archive-branches.sh
+56
-0
No files found.
bin/archive-branches.sh
0 → 100755
View file @
1ef5ecb6
#!/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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment