]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/conflict-rss.sh
add a conflict detector that outputs to per-branchowner RSS feeds
[xonotic/xonotic.git] / misc / tools / conflict-rss.sh
1 #!/bin/sh
2
3 set -e
4
5 action=$1
6 outdir=$2
7 repodir=$3
8
9 branches()
10 {
11         git for-each-ref 'refs/remotes' | grep -vE '    refs/remotes/([^/]*/HEAD|.*/archived/.*)$'
12 }
13
14 escape_html()
15 {
16         sed -e 's/&/\&amp;/g; s/</&lt;/g; s/>/&gt;/g'
17 }
18
19 to_rss()
20 {
21         outdir=$1
22         name=$2
23         hash=$3
24         branch=$4
25
26         filename=$outdir/`echo -n "$name" | tr -c 'A-Za-z0-9' '_'`.xml
27         datetime=`date --rfc-2822`
28         branch=`echo "$branch" | escape_html`
29
30         if ! [ -f "$filename" ]; then
31                 cat >"$filename" <<EOF
32 <?xml version="1.0" encoding="UTF-8" ?>
33 <rss version="2.0">
34 <channel>
35         <title>Merge conflicts for $name</title>
36         <link>...</link>
37         <description>...</description>
38         <lastBuildDate>$datetime</lastBuildDate>
39         <ttl>3600</ttl>
40 EOF
41         fi
42         cat >>"$filename" <<EOF
43         <item>
44                 <title>$branch ($hash)</title>
45                 <link>...</link>
46                 <description><![CDATA[
47 EOF
48
49         escape_html >>"$filename"
50
51         cat >>"$filename" <<EOF
52                 ]]></description>
53         </item>
54 EOF
55 }
56
57 finish_rss()
58 {
59         cat <<EOF >>"$1"
60 </channel>
61 </rss>
62 EOF
63 }
64
65 if [ -z "$outdir" ]; then
66         set --
67 fi
68
69 case "$action" in
70         --init)
71                 rm -rf "$outdir"
72                 mkdir -p "$outdir"
73                 ;;
74         --finish)
75                 for f in "$outdir"/*; do
76                         [ -f "$f" ] || continue
77                         finish_rss "$f"
78                 done
79                 ;;
80         --add)
81                 (
82                         if [ -n "$repodir" ]; then
83                                 cd "$repodir"
84                         fi
85                         branches
86                 ) | while read -r HASH TYPE REFNAME; do
87                         echo >&2 -n "$repodir $REFNAME..."
88                         out=$( (
89                                 if [ -n "$repodir" ]; then
90                                         cd "$repodir"
91                                 fi
92                                 git reset --hard >/dev/null 2>&1
93                                 if out=`git merge --no-commit -- "$REFNAME" 2>&1`; then
94                                         good=true
95                                 else
96                                         good=false
97                                         echo "$out"
98                                 fi
99                                 git reset --hard >/dev/null 2>&1
100                         ) )
101                         if [ -n "$out" ]; then
102                                 n=${REFNAME#refs/remotes/[^/]*/}
103                                 case "$n" in
104                                         */*)
105                                                 b=${n#*/}
106                                                 n=${n%%/*}
107                                                 ;;
108                                         *)
109                                                 b="/$n"
110                                                 n=divVerent
111                                                 ;;
112                                 esac
113                                 echo "$out" | to_rss "$outdir" "$n" "$HASH" "$b"
114                                 echo >&2 " CONFLICT"
115                         else
116                                 echo >&2 " ok"
117                         fi
118                 done
119                 ;;
120         *)
121                 echo "Usage: $0 --init OUTDIR"
122                 echo "       $0 --add OUTDIR [REPODIR]"
123                 echo "       $0 --finish OUTDIR"
124                 exit 1
125                 ;;
126 esac