warbo-utilities: 8b326c74dfa4ad7e63554e79ce3aa40006c98de6

     1: {
     2:   artemis,
     3:   bash,
     4:   fail,
     5:   git,
     6:   git2html,
     7:   mhonarc,
     8:   pandoc,
     9:   python3,
    10:   raw,
    11:   runCommand,
    12:   withDeps,
    13:   wrap,
    14:   writeScript,
    15: }:
    16: 
    17: with rec {
    18:   script = wrap {
    19:     name = "genGitHtml";
    20:     paths = [
    21:       fail
    22:       git
    23:       git2html
    24:       mhonarc
    25:       pandoc
    26:     ];
    27:     file = raw."genGitHtml.sh";
    28:     vars = {
    29:       splicer = wrap {
    30:         name = "splicer";
    31:         paths = [ python3 ];
    32:         script = ''
    33:           #!${python3}/bin/python3
    34:           import os
    35:           import sys
    36:           pre, post = sys.stdin.read().split('READMESENTINEL')
    37:           print(pre)
    38:           print(open(os.getenv('READMEFILE'), 'r').read())
    39:           print(post)
    40:         '';
    41:       };
    42: 
    43:       cleaner = wrap {
    44:         name = "cleaner.py";
    45:         script = ''
    46:           #!${python3.withPackages (p: [ p.bleach ])}/bin/python3
    47:           import bleach
    48:           import sys
    49: 
    50:           print(bleach.clean(
    51:             sys.stdin.read(),
    52:             tags=[
    53:               'a',
    54:               'b',
    55:               'br',
    56:               'code',
    57:               'col',
    58:               'colgroup',
    59:               'div',
    60:               'em',
    61:               'emph',
    62:               'h1',
    63:               'h2',
    64:               'h3',
    65:               'h4',
    66:               'h5',
    67:               'hr',
    68:               'i',
    69:               'img',
    70:               'li',
    71:               'ol',
    72:               'p',
    73:               'pre',
    74:               'span',
    75:               'strong',
    76:               'table',
    77:               'tbody',
    78:               'td',
    79:               'th',
    80:               'thead',
    81:               'tr',
    82:               'ul',
    83:             ],
    84:             attributes={
    85:               'a'   : ['href', 'rel'],
    86:               'img' : ['alt',  'src'],
    87:             }))
    88:         '';
    89:       };
    90:     };
    91:   };
    92: 
    93:   test =
    94:     runCommand "genGitHtml-test"
    95:       {
    96:         inherit script;
    97:         buildInputs = [
    98:           artemis
    99:           fail
   100:           git
   101:           git2html
   102:           mhonarc
   103:           pandoc
   104:         ];
   105:         EDITOR = wrap {
   106:           name = "test-editor";
   107:           script = ''
   108:             #!${bash}/bin/bash
   109:             sed -i -e "s@^Subject: .*@Subject: $SUBJECT@g" "$1"
   110:             sed -i -e "s@Detailed description.@$BODY@g"    "$1"
   111:           '';
   112:         };
   113:         testReadme = ''
   114:           # Title 1 #
   115: 
   116:           Some text.
   117: 
   118:           ## Title 2 ##
   119: 
   120:           A [link](http://example.org).
   121: 
   122:           <script type="text/javascript">alert("XSS");</script>
   123: 
   124:           <pre><code>Some code</code></pre>
   125: 
   126:           <ul> <li>First</li> <li>Second</li> </ul>
   127: 
   128:           <span />
   129:         '';
   130:       }
   131:       ''
   132:         mkdir home
   133:         export HOME="$PWD/home"
   134:         git config --global user.email "you@example.com"
   135:         git config --global user.name "Your Name"
   136: 
   137:         mkdir html
   138:         mkdir test.git
   139:         pushd test.git
   140:           git init
   141:           SUBJECT="Need a foo" BODY="For testing" git artemis add
   142:           echo "Testing" > foo
   143:           git add foo
   144:           git commit -m "Added foo"
   145: 
   146:           SUBJECT="Need a bar" BODY="More testing" git artemis add
   147:           echo "Testing"     >> foo
   148:           echo "123"         >  bar
   149:           echo "$testReadme" >  README.md
   150:           git add foo bar README.md
   151:           git commit -m "Added bar and README"
   152:         popd
   153: 
   154:         if "$script"
   155:         then
   156:           fail "Should reject when no args"
   157:         fi
   158: 
   159:         if "$script" test.git
   160:         then
   161:           fail "Should reject when one arg"
   162:         fi
   163: 
   164:         "$script" test.git html
   165: 
   166:         if [[ -e test.git/repository ]]
   167:         then
   168:           fail "Left over repo should have been deleted"
   169:         fi
   170: 
   171:         [[ -e html/index.html          ]] || fail "No index.html"
   172:         [[ -e html/git/index.html      ]] || fail "No git/index.html"
   173:         [[ -e html/issues/threads.html ]] || fail "No issues/threads.html"
   174: 
   175:         for CODE in '<code>Some' '<span' '<ul>' '<li>'
   176:         do
   177:           grep "$CODE" < html/index.html || fail "HTML '$CODE' didn't survive"
   178:         done
   179:         < html/index.html | grep -v 'cloudflare' | grep '<script' &&
   180:           fail "Should've stripped '<script>' tag"
   181: 
   182:         mv html "$out"
   183:       '';
   184: };
   185: withDeps [ test ] script

Generated by git2html.