github: add script for listing old branches

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-04-28 23:17:02 +02:00
parent 9f0aa6abaa
commit d7bd3fb198
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
1 changed files with 21 additions and 0 deletions

21
github/list_old_branches.sh Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env bash
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\/}"
COMMIT_DATE_UNIX=$(getCommitUnix remotes/origin/$BRANCH_NAME)
if [[ ${COMMIT_DATE_UNIX} < ${OLDER_THAN} ]]; then
echo "${BRANCH_NAME}"
fi
done