infra-utils/github/list_old_branches.sh
Jakub Sokołowski 3d27194f93
github/list_old_branches.sh: ignore release branches
Signed-off-by: Jakub Sokołowski <jakub@status.im>
2020-05-12 15:50:01 +02:00

28 lines
781 B
Bash
Executable File

#!/usr/bin/env bash
# This can be easily used with something like:
# for B in $(list_old_branches.sh); do git branch --delete "${BRANCH}"; done
function getCommitUnix() {
git show --no-patch --no-notes --pretty='%at' ${1}
}
OLDER_THAN_DAYS="60"
CURRENT_TIME=$(date +%s)
OLDER_THAN_UNIX=$(( ${OLDER_THAN_DAYS} * 86400 ))
OLDER_THAN=$(( ${CURRENT_TIME} - ${OLDER_THAN_UNIX} ))
REMOTE="origin"
REMOTE_BRANCHES=$(git ls-remote --heads --heads ${REMOTE} | cut -f2)
for BRANCH in ${REMOTE_BRANCHES}; do
BRANCH_NAME="${BRANCH/#refs\/heads\/}"
if [[ ${BRANCH_NAME} = release* ]]; then
continue
fi
COMMIT_DATE_UNIX=$(getCommitUnix remotes/origin/$BRANCH_NAME)
if [[ ${COMMIT_DATE_UNIX} < ${OLDER_THAN} ]]; then
echo "${BRANCH_NAME}"
fi
done