File: git-hook-notification-bts

package info (click to toggle)
git-stuff 11-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 468 kB
  • sloc: sh: 1,072; perl: 152; makefile: 128
file content (83 lines) | stat: -rwxr-xr-x 2,661 bytes parent folder | download
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
#! /bin/bash
#
# Copyright (c) 2009 Adeodato Simó (dato@net.com.org.es)
#
# This software may be used and distributed according to the terms
# of the MIT License, incorporated herein by reference.

# Purpose: this hook will tag Debian bugs as pending. The mail will
# include the commit message, and the portion of the diff corresponding
# to debian/changelog, plus a pointer to the URL that contains the full
# diff. It has some heuristics not to tag the same bug pending twice.
#
# Usage: make this script your post-receive hook, or exec this script
# from there. If you need to execute more than one script against
# post-receive's stdin, you can use pee(1), from the moreutils package.
# No configuration is necessary.

set -e
set -u

REPODIR=`readlink -f "$PWD"`
PROJECTROOT=`git repo-config hooks.projectroot`
REPOREL=${REPODIR#$PROJECTROOT}
REPOREL=${REPODIR#/srv/git.debian.org/git/}
REPOREL=${REPOREL#/srv/alioth.debian.org/chroot/home/}
REPOREL=${REPOREL/\/public_git\//\/}
BASEURL="`git repo-config hooks.baseurl`"
BASEURL="${BASEURL:-http://git.debian.org/}"
BASEURL="${BASEURL}?p=$REPOREL"

tempdir=`mktemp -d`
trap "rm -rf \"${tempdir}\"" EXIT

send_mail() { # send_mail bugno revno diff_file
    local bug="$1"
    local rev="$2"
    local diff="$3"
    local from=$(git show -s --pretty='format:%cn <%ce>' $rev |
                 perl -CI -MEncode -e 'print Encode::encode("MIME-Q", <STDIN>)')
    (cat <<EOF
From: $from
To: $bug-submitter@bugs.debian.org
Bcc: control@bugs.debian.org
Subject: Bug#$bug marked as pending
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
X-Mailer: http://snipr.com/post-receive-tag-pending

tag $bug pending
thanks

Hello,

Bug #$bug reported by you has been fixed in the Git repository. You can
see the changelog below, and you can check the diff of the fix at:

    ${BASEURL};a=commitdiff;h=`git show -s --pretty='format:%h' "$rev"`

---
EOF
    cat "$diff") | /usr/sbin/sendmail -oi -t
}

while read oldrev newrev refname; do
    git rev-parse --not --branches | grep -v $(git rev-parse $refname) |
    git rev-list --reverse --stdin "${oldrev}..${newrev}" |
    while read rev; do
        c="$tempdir/$rev.changelog"
        d="$tempdir/$rev.diff"
        git show ${rev}:debian/changelog >"$c" 2>/dev/null
        git show ${rev} -- debian/changelog >"$d"
        bugs=`dpkg-parsechangelog -l"$c" | sed -rne 's/^Closes: *//pi'`
        for bug in $bugs; do
            if  grep -qE '^\+.*\<'$bug'\>' "$d" &&
              ! grep -qE  '^-.*\<'$bug'\>' "$d"; then
              send_mail $bug "$rev" "$d"
            fi
        done
    done
done

# vi: et