summaryrefslogtreecommitdiff
path: root/SDL_Core/tools/coding-style/old-branch-nagger.sh
blob: 1eed89e1d906eed6d126e6d2198c4eed4b8824d9 (plain)
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
#!/bin/bash

# All the branches excluding release branches and virtual HEAD branch
ALL_BRANCHES=`git branch -r | grep -v '\(origin/master$\|HEAD\|origin/release\)'`

# Branch names, access dates and last committer names
# The format is "<unix-date>  <oldness-text>  <author>  <branch-name>"
# Sorted by date, freshes branches first
BRANCH_COMMITS=$(for branch in $ALL_BRANCHES;do echo -e $(git log -1 --format="%at\t%ar\t%aE\t" $branch)$branch; done | sort -rn)

# List of all branch owners
BRANCH_OWNERS=$(echo "$BRANCH_COMMITS"|cut -f3|sort|uniq)

# 2 weeks here
TIME_THRESHOLD=$((60 * 60 * 24 * 7 * 2))
DATE_THRESHOLD=$(( $(date +%s) - $TIME_THRESHOLD ))

FLAGS=${1:-""}

for OWNER in $BRANCH_OWNERS; do
  # Oldness and names of branches which belong to $OWNER and that are more than 2 weeks old
  OLD_BRANCHES=$(echo "$BRANCH_COMMITS"|grep $OWNER|awk -F'\t' 'int($1) < '$DATE_THRESHOLD' {print $2 " " $4}')
  if [ -n "$OLD_BRANCHES" ];
  then
    if [[ $FLAGS == "-m" ]]; then
        SENDER="mail -s Your_branches_may_be_old $OWNER"
    else
        SENDER="cat"
    fi
    $SENDER <<EOF
Dear $OWNER, here are your branches you DID NOT update for more than two weeks,
please merge them to develop and/or remove:
$OLD_BRANCHES

EOF
  fi
done