blob: 9721f71a446c6310ba55a98f3081f34e2e04e0ed (
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
94
95
96
97
98
|
#!/usr/bin/env bash
if [[ ! ${QUERY_STRING} ]]; then
echo "Script must be run through CGI" >&2
exit 1
fi
main() {
local qs=${QUERY_STRING}
local repo=${qs%%;*}
qs=${qs#*;}
local commit=${qs%%;*}
qs=${qs#*;}
local file=${qs%%;*}
[[ ${qs} == *\;* ]] && qs=${qs#*;} || qs=
local filter_maint= projects=
while [[ -n ${qs} ]]; do
local q=${qs%%;*}
case ${q} in
maintainer=*)
filter_maint="--maintainer ${q#maintainer=}"
;;
include-projects)
projects=--projects
;;
pkg=*)
pkgs=${q#pkg=}
filter_pkg="--pkg ${pkgs//://}"
;;
esac
[[ ${qs} == *\;* ]] && qs=${qs#*;} || qs=
done
if [[ ${repo} == */* ]]; then
echo "DANGER! SOMEONE TRIES TO ABUSE ME!" >&2
exit 1
fi
local topdir=$(dirname "${0}")/..
if ! cd "${topdir}/htdocs/output/${repo}" 2>/dev/null; then
echo "Status: 404 Not Found"
echo
echo "404 Not Found"
exit 0
fi
# generate HTML from XML
local verbose=
local lfile=${file}
if [[ ${file} == *.verbose.html ]]; then
file=${file%.verbose.html}.html
verbose=--verbose
fi
[[ ${file} == *.html ]] && lfile=${file%.html}.xml
local tree=( $(git ls-tree "${commit}" "${lfile}" 2>/dev/null) )
if [[ ! ${tree[*]} ]]; then
# fallback for stuff without .xml
lfile=${file}
tree=( $(git ls-tree "${commit}" "${lfile}" 2>/dev/null) )
if [[ ! ${tree[*]} ]]; then
echo "Status: 503 Service Unavailable"
echo "Retry-After: 30"
echo
echo "404 Not Found (if the report was just published, you may need to wait a minute or two for sync)"
exit 0
fi
fi
local revarg=
[[ ${commit} != HEAD ]] && revarg="--revision ${commit}"
local ct
case "${file}" in
*.css) ct=text/css;;
*.html) ct=text/html;;
*.xml) ct=application/xml;;
*) ct=text/plain;;
esac
echo "Content-Type: ${ct}"
echo
if [[ ${file} == *.html && ${lfile} == *.xml ]]; then
local ts=$(TZ=UTC git log --format='%cd' --date=iso-local -1 | cut -d' ' -f1-2)
git cat-file -p "${tree[2]}" \
| PYTHONIOENCODING=utf8 python \
"${topdir}"/pkgcheck2html/pkgcheck2html.py ${verbose} \
-x "${topdir}"/pkgcheck2html/excludes.json \
${filter_maint} ${projects} ${filter_pkg} -t "${ts}" -
else
git cat-file -p "${tree[2]}"
fi
}
main
|