summaryrefslogtreecommitdiff
path: root/BitKeeper/triggers/post-outgoing.ciabot
blob: 75f21511d8cbae085a2cdc3ca8d92b00c99a7bc7 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
#
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# Copyright (C) 2004 Chris Larson <kergoth@handhelds.org>
#
# Sanity checks taken from the scripts on commits.bkbits.net
# 	Copyright (C) 2003 Leonard Norrgard <leonard.norrgard@refactor.fi>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

check_sanity () {
    if [ X$BK_STATUS = XDRYRUN -o X$BK_STATUS = XNOTHING ]; then
        return 1
    fi

    # In order to make sure only pushes to public BitKeeper repositories
    # are broadcasted to #commits, we check that a) the parent repository
    # is on bkbits.net and b) we are the client.
    
    # Is parent a public BitKeeper repository at bkbits.net?
    if !(echo $BKD_HOST|grep -q bitkeeper.com); then
        return 1
    fi
    
    if [ $BK_SIDE != client ]; then
        return 1
    fi
}

check_projects () {
    if [ ! -e $BK_ROOT/BitKeeper/triggers/ciabot.projects ]; then
        return 1
    fi

    while read _p _s _e; do
        _sshort=`echo $_s|sed -e's,.bkbits.net,,'`
        if (echo $BKD_ROOT|grep "/${_sshort}"); then
            project_name=${_p}
            return_address=${_e}
        fi
    done < $BK_ROOT/BitKeeper/triggers/ciabot.projects
    export project_name return_address
    return 0
}

# Check sanity - do we need to send anything?
check_sanity || exit 0

# Check projects - attempt to determine which bkbits project we are
check_projects || exit 0

if (grep -q 'ChangeSet' $BK_CSETLIST); then
    # new, correct csets-out format
    nums=`bk changes -d":REV: " - < $BK_CSETLIST`
else

    # Convert numbers from the cset list into something useful
    nums=
    for s in `cat $BK_CSETLIST`; do
        # translate cset serial to cset #
        n=`bk prs -h -d"\\$if(:DS: -eq $s){:REV:}" ChangeSet`
        # dont send notifications about empty ChangeSets
        if test -z `bk prs -h -r"$n" -d'$if(:LI: -eq 0){$if(:LD: -eq 0){:REV:}}' ChangeSet`; then
        	nums="$n $nums"
        fi
    done
fi

# Send notifications to CIA
if test -n "$nums"; then
    echo "Sending notification to CIA irc bot (cia.navi.cx)."
    (
        for n in $nums; do
            $BK_ROOT/BitKeeper/triggers/ciabot_bk.sh $n
        done
    ) &
fi
exit 0