forked from rasecoiac03/github-tidy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch-inactivity
executable file
·51 lines (43 loc) · 1.34 KB
/
branch-inactivity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
GITHUB_API=${GITHUB_API:-https://api.github.com}
REPO=$1
RED='\033[0;31m'
WHITE='\033[1;37m'
GRAY='\033[1;30m'
NC='\033[0m' # No Color
print_separator() {
echo -e "${GRAY}============================================================${NC}"
}
check_branch() {
branch=$2
last_commit_date=$(curl -H "Authorization: token $GH_TOKEN" -sL $1/$branch | jq -r '.commit.commit.committer.date')
last_commit_diff_days=$(echo "(`date '+%s'` - `date '+%s' -d "$last_commit_date"`) / (24*3600)" | bc)
if [ $last_commit_diff_days -gt 89 ]; then
echo -e "${RED}inactive for more than 90 days (${last_commit_diff_days} days)${NC}"
return 1
fi
echo -e "OK (${last_commit_diff_days} days)"
return 0
}
read_branches() {
page=$2
branches=$(curl -H "Authorization: token $GH_TOKEN" -sL $1?page=$page | jq -r '.[].name')
branches_length=$(echo $branches | tr -d '\n' | wc -m)
if [ $branches_length -eq 0 ]; then
print_separator
echo "there is no more branches to check"
return 0
fi
for branch in $branches; do
print_separator
echo -e "checking ${WHITE}${branch}${NC}"
check_branch $1 $branch
done
page=$(($page+1))
return $page
}
page=1
while [ $page -gt 0 ]; do
read_branches $GITHUB_API/repos/$REPO/branches $page
page=$?
done