Project

General

Profile

Action Item #427 ยป MakeChangelog.sh

Hammel, 15 Aug 2014 17:30

 
1
#!/bin/bash
2
# Generate changelogs for all projects repositories:
3
# hg log -v -d ">YYYY-MM-DD" | egrep -v "^changeset:|^date:|^tag:|^files:|^user:|^description:|^parent:|^$" > Changelog
4
#
5
# Note: this script requires the use of the cdtools functions.
6
# ---------------------------------------------------------------------------------------------------------------------
7
function doHelp
8
{
9
    echo ""
10
    echo "Generate a Changelog for all project repositories."
11
    echo ""
12
    echo "$0 -p <proj> [-d YYYY-MM-DD]"
13
    echo "where"
14
    echo "-p <proj>    The name of the project file to source under ~/bin/changelogs."
15
    echo "             <proj> must match file name and contain the function doLogs()."
16
    echo "-d <date>    Specify the date equal to or after which changelogs should be generated."
17
    echo "             If no date is specified, it will be from the beginning of the current month."
18
}
19

    
20
function findProj
21
{
22
	SHF=~/bin/env/${PRJ}
23
	if [ ! -f $SHF ]
24
	then
25
		SHF=~/bin/env/${PRJ}.sh
26
		if [ ! -f $SHF ]
27
		then
28
			echo "Can't find project cdtools script: $SHF"
29
			exit 1
30
		fi
31
	fi
32
	echo "Found project cdtools script: $SHF"
33
}
34

    
35
#--------------------------------------------------------------
36
# Read command line arguments
37
#--------------------------------------------------------------
38
while getopts ":d:p:" Option
39
do
40
    case $Option in
41
    d) DATE=$OPTARG;;
42
    p) SCR=$OPTARG;;
43
    *) doHelp; exit 0;;
44
    esac
45
done
46

    
47
if [ "$SCR" = "" ]
48
then
49
	echo "You must specify a changelogs script to source."
50
	exit 1
51
fi
52
if [ ! -f ~/bin/changelogs/$SCR ]
53
then
54
	echo "~/bin/changelogs/$SCR does not exist."
55
	exit 1
56
fi
57

    
58
if [ "$DATE" = "" ]
59
then
60
    YEAR=`date +%Y`
61
    MON=`date +%m`
62
    DATE="$YEAR-$MON-01"
63
fi
64
CMD="hg log -v -d \">$DATE\" | egrep -v \"^changeset:|^date:|^tag:|^files:|^user:|^description:|^parent:|^$\" > Changelog"
65

    
66
# Source the changelogs script
67
. ~/bin/changelogs/$SCR
68
findProj 
69

    
70
# Setup
71
CWD=`pwd`
72
rm -rf logs
73
mkdir logs
74
cd logs
75
LOGDIR=`pwd`
76

    
77
# Call the project specific log generator
78
. $SHF
79
doLogs $LOGDIR
80

    
81
# Now generate the single log file
82
cd $LOGDIR
83
for file in `ls -1`
84
do
85
    if [ -s $file ]
86
    then
87
        repo=`echo $file | cut -f2 -d"."`
88
        hdr="Repository: $repo"
89

    
90
        echo "-----------------------------------------------------" >> Changelog
91
        echo "$hdr" >> Changelog
92
        echo "-----------------------------------------------------" >> Changelog
93

    
94
        # cat $file | sort >> Changelog
95
        cat $file >> Changelog
96
        echo "" >> Changelog
97
    fi
98
done
99

    
100
echo "Changelog generated: "
101
ls -1 $LOGDIR/Changelog
    (1-1/1)