11#! /bin/bash
22
3- # clean-ci [--dry-run] [--since="relative date"]
3+ # clean-ci [--dry-run] [--since="relative date"] [--remote=remote]
44#
55# Cleanup the ceph-ci.git repository branch list by deleting any branch with a
66# HEAD commit date older than (by default) 3 months.
77
88set -e
99
10- [email protected] :ceph/ceph-ci.git
10+ CEPH_CI=https://github.com/ceph/ceph-ci.git
11+ [email protected] :ceph/ceph-ci.git
1112DRY_RUN=0
1213SINCE=" 3 months ago"
1314
@@ -19,11 +20,13 @@ function eprintf {
1920
2021
2122function delete_refs {
22- if [[ DRY_RUN -eq 0 ]]; then
23- eprintf ' Deleting refs: %s' " $* "
24- git push --quiet " $CEPH_CI " --delete " $@ "
25- else
26- eprintf ' Would delete refs: %s' " $* "
23+ if [[ ${# TO_DELETE[@]} -gt 0 ]]; then
24+ if [[ DRY_RUN -eq 0 ]]; then
25+ eprintf ' Deleting refs: %s' " $* "
26+ git push --quiet " $REMOTE " --delete " $@ "
27+ else
28+ eprintf ' Would delete refs: %s' " $* "
29+ fi
2730 fi
2831}
2932
@@ -35,7 +38,7 @@ function iterate_ci {
3538 # Fetch the refs, shallow
3639 printf ' %s' " $REFS " | \
3740 cut -f2 | \
38- git fetch --quiet --depth=1 --refetch --filter=blob:none --stdin " $CEPH_CI "
41+ git fetch --quiet --depth=1 --refetch --filter=blob:none --stdin " $REMOTE "
3942
4043 declare -a TO_DELETE
4144
@@ -70,12 +73,14 @@ function iterate_ci {
7073}
7174
7275function main {
73- eval set -- $( getopt --name " $0 " --options ' h' --longoptions ' help,dry-run,since:' -- " $@ " )
76+ eval set -- $( getopt --name " $0 " --options ' h' --longoptions ' help,dry-run,since:,remote: ' -- " $@ " )
7477
7578 while [ " $# " -gt 0 ]; do
7679 case " $1 " in
7780 -h|--help)
78- printf ' %s: [--dry-run] [--since=<relative time>]\n' " $0 "
81+ printf ' %s: [--dry-run] [--since=<relative date>] [--remote=<remote>]\n' " $0 "
82+ printf ' \t--since=<relative date> is the same as in date(3) --date switch\n'
83+ printf ' \t--remote=<remote> is the remote name for ceph-ci to fetch/push to, by default: %s\n' " $REMOTE "
7984 exit 0
8085 ;;
8186 --dry-run)
@@ -86,6 +91,10 @@ function main {
8691 SINCE=" $2 "
8792 shift 2
8893 ;;
94+ --remote)
95+ REMOTE=" $2 "
96+ shift 2
97+ ;;
8998 --)
9099 shift
91100 break
0 commit comments