commit:     f87c07fff29036a13bbae97f8b08943dac292ae2
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon Dec  5 09:02:40 2016 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Dec  5 09:02:40 2016 +0000
URL:        https://gitweb.gentoo.org/proj/qa-scripts.git/commit/?id=f87c07ff

get-git-file: Generate gentoo-ci (+PR) HTML locally

 cgi-bin/get-git-file.sh | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/cgi-bin/get-git-file.sh b/cgi-bin/get-git-file.sh
index 8b48b08..56eecaa 100755
--- a/cgi-bin/get-git-file.sh
+++ b/cgi-bin/get-git-file.sh
@@ -18,31 +18,50 @@ main() {
                exit 1
        fi
 
-       if ! cd "$(dirname "${0}")/../htdocs/output/${repo}" 2>/dev/null; then
+       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
 
-       local tree=( $(git ls-tree "${commit}" "${file}" 2>/dev/null) )
+       # generate HTML from XML
+       local lfile=${file}
+       [[ ${file} == *.html ]] && lfile=${file%.html}.xml
+
+       local tree=( $(git ls-tree "${commit}" "${lfile}" 2>/dev/null) )
        if [[ ! ${tree[*]} ]]; then
-               echo "Status: 404 Not Found"
-               echo
-               echo "404 Not Found"
-               exit 0
+               # fallback for stuff without .xml
+               lfile=${file}
+               tree=( $(git ls-tree "${commit}" "${lfile}" 2>/dev/null) )
+               if [[ ! ${tree[*]} ]]; then
+                       echo "Status: 404 Not Found"
+                       echo
+                       echo "404 Not Found"
+                       exit 0
+               fi
        fi
 
        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
-       git cat-file -p "${tree[2]}"
+       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 -t "${ts}" -
+       else
+               git cat-file -p "${tree[2]}"
+       fi
 }
 
 main

Reply via email to