d33d3872f55c3e6fade14113b203b5bd60dad5b0
[git-central.git] / server / post-receive-hudson
1 #!/bin/sh
2
3 . $(dirname $0)/functions
4
5 while read oldrev newrev refname ; do
6         case "$refname" in
7                 refs/tags/*)
8                         exit 0
9                         ;;
10                 refs/heads/*)
11                         short_refname=${refname##refs/heads/}
12                         ;;
13                 *)
14                         echo >&2 "*** Unknown type of update to $refname"
15                         exit 1
16                         ;;
17         esac
18
19         ignored=" $(git config hooks.post-receive-hudson.ignored) "
20         if [[ $ignored =~ " $short_refname " ]] ; then
21                 exit 0
22         fi
23
24         branch_config=$(wget -O - $HUDSON_URL/job/${short_refname}/config.xml 2>/dev/null)
25         if [ $? -ne 0 ] ; then
26                 # Create the job
27                 stable_config=$(wget -O - $HUDSON_URL/job/stable/config.xml 2>/dev/null)
28                 if [ $? -ne 0 ] ; then
29                         display_error_message "Could not get existing Hudson config for ${short_refname}"
30                         exit 0
31                 fi
32
33                 # Replace stable with our branch
34                 branch_config="${stable_config/<branch>stable</<branch>$short_refname<}"
35
36                 # Add email to recipients list
37                 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
38                         branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
39                 fi
40
41                 # Make the new job
42                 wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "$HUDSON_URL/createItem?name=${short_refname}" >/dev/null 2>/dev/null
43                 if [ $? -ne 0 ] ; then
44                         display_error_message "Could not create new Hudson job for ${short_refname}"
45                         exit 0
46                 fi
47         else
48                 # Add email to recipients list
49                 if [ "${branch_config/$USER_EMAIL/}" == "$branch_config" ] ; then
50                         branch_config="${branch_config/<recipients>/<recipients>$USER_EMAIL }"
51
52                         # Update the config
53                         wget --header "Content-Type: text/xml" --post-data="$branch_config" -O - "$HUDSON_URL/job/${short_refname}/config.xml" >/dev/null 2>/dev/null
54                         if [ $? -ne 0 ] ; then
55                                 display_error_message "Could not add $USER_EMAIL to Hudson job ${short_refname}"
56                                 exit 0
57                         fi
58                 fi
59         fi
60 done
61
62 exit 0
63