Repo containing scripts to be used with dovel, and git hooks that powers our web interface.
- #!/bin/sh
- # for debugging
- # set -ex
- . hooks/aux.sh
- # . ./aux.sh
- ROOT="$HOME/dovel.email"
- REPO="$(basename $PWD)"
- OUT="$ROOT/$REPO"
- TMP="$(mktemp -d)"
- updategit() {
- cat <<- EOF > "$ROOT/git.html"
- $(pagehead "dovel")
- ← <a href="/">dovel website</a>
- <h1>Dovel project Git home</h1>
- Welcome! Here you'll find general info about our projects and how to
- contribute to them. We proudly use dovel email technology for our
- mailing lists. Its hooks are in the scripts repo. Please read the next
- sections before making a contribution.
- <p>
- To clone a repository use <kbd><b>git clone https://dovel.email/[repo]</b></kbd>,
- changing [repo] by the name you want.
- </p>
- <h2>Repositories</h2>
- <dl>
- EOF
- # TODO: change git folder
- for dir in "$HOME/git/dovel.email/"*
- do
- cat <<- EOF >> "$ROOT/git.html"
- <dt><a href=$(basename $dir)/index.html>$(basename $dir)</a></dt>
- <dd>$(cat "$dir/description")</dd>
- EOF
- done
- printf '\n</dl>\n<h2>Latest commit</h2>\n' >> "$ROOT/git.html"
- hash="$(git show --format='%h' -s)"
- cat <<- EOF >> "$ROOT/git.html"
- <p><a href="$REPO/log/$hash.html">$hash</a> on $REPO:</p>
- <pre>
- EOF
- git show -s "$hash" >> "$ROOT/git.html"
- cat <<- EOF >> "$ROOT/git.html"
- </pre>
- <h2>Contributing</h2>
- The dovel team uses the git email workflow to accept contributions.
- All email sent to dovel.email is considered as git mailling lists,
- see the next section on how we organize them.
- To send email about other subjects please address them to
- <a href=mailto:dovel@terminal.pink>dovel _AT_ terminal.pink</a>.
- <p>Browse the <a href=mail.html>mailing list</a> online.</p>
- <h3>Email addresses</h3>
- To send contributions use the repo name as address, i.e. to
- contribute to the server project send email to
- <kbd>server _AT_ dovel.email</kbd>. Please CC me as well so I
- can reply faster: <kbd>dovel _AT_ terminal.pink</kbd>.
- Please choose the subject wiselly since it is used to separate
- threads, if you choose a taken subject or a too generic one
- your email can go to another thread.
- <h3>Email etiquette</h3>
- We only accept plain text email. More info and recomendations can be
- found on <a href=//useplaintext.email>useplaintext.email</a>. Also
- <a href=//git-send-email.io>git-send-email.io</a> has instructions on
- how to setup git to send email for many platforms.
- </body>
- </html>
- EOF
- }
- updateindex() {
- echo "creating index.html"
- cat <<- EOF > "$OUT/index.html"
- $(pagehead "$REPO")
- $(pagesummary "$REPO")
- <hr>
- <p>Latest commit: $(git log -n 1 --format="(%h) by %an at %as: %s")</p>
- <main>
- EOF
- [ -f "$TMP/README.md" ] && mdown < "$TMP/README.md" >> "$OUT/index.html"
- [ -f "$TMP/README" ] && cat <<- EOF >> "$OUT/index.html"
- <pre>$(cat "$TMP/README")</pre>
- EOF
- printf "\t</main>\n</body>\n</html>\n" >> "$OUT/index.html"
- }
- createcommitpage() {
- cat <<- EOF
- $(pagehead "$REPO")
- $(pagesummary "$REPO")
- <hr>
- <h2>$1</h2>
- EOF
- # print commit
- git show --format='%an%n%ae%n%ad%n%p%n%B' -s "$1" | {
- read -r name
- read -r email
- read -r date
- read -r parent
- cat <<- EOF
- <p>Author: $name ($email)</p>
- <p>Date: $date</p>
- <p>Parent: <a href=$parent.html>$parent</a></p>
- <pre>$(cat -)</pre>
- EOF
- }
- # now the diff
- echo "<h3>Diff</h3>"
- for f in $(git show "$1" --name-only --format='')
- do
- cat << EOF
- <h4>$f</h4>
- <pre style="overflow-x:auto;white-space:pre">
- $(git show --format='' "$1" -- "$f" | escapehtml)
- </pre>
- EOF
- done
- cat <<- EOF
- </body>
- </html>
- EOF
- }
- updatelog() {
- echo "creating log.html"
- cat <<- EOF > "$OUT/log.html"
- $(pagehead "$REPO")
- $(pagesummary "$REPO")
- <hr>
- <h2>Log</h2>
- <table>
- <tr><th>Hash</th><th>Author</th><th>Date</th><th>Subject</td></tr>
- EOF
- git log -n 100 --format='%h%n%ad%n%an%n%s' --date=iso | while read -r h
- do
- read -r date
- read -r name
- read -r msg
- cat <<- EOF >> "$OUT/log.html"
- <tr><td><a href=log/$h.html>$h</a></td><td>$name</td><td>$date</td><td>$msg</td></tr>
- EOF
- [ -f "$OUT/log/$h.html" ] && continue
- echo "creating commit page $h"
- createcommitpage "$h" > "$OUT/log/$h.html"
- done
- cat <<- EOF >> "$OUT/log.html"
- </table>
- <p>Note: Only showing up to 100 commits, for full log clone the repo.</p>
- </body>
- </html>
- EOF
- }
- updaterefs() {
- echo "creating refs.html"
- cat <<- EOF > "$OUT/refs.html"
- $(pagehead "$REPO")
- $(pagesummary "$REPO")
- <hr>
- <h2>Branches</h2>
- <table>
- EOF
- git show-ref --heads | while read -r h n
- do
- echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html"
- done
- echo "</table>\n<h2>Tags</h2>\n<table>" >> "$OUT/refs.html"
- git show-ref --tags | while read -r h n
- do
- echo "<tr><td>$h</td><td>$n</td></tr>" >> "$OUT/refs.html"
- done
- cat <<- EOF >> "$OUT/refs.html"
- </table>
- </body>
- </html>
- EOF
- }
- filepage() {
- cat <<- EOF
- $(pagehead "$REPO")
- $(pagesummary "$REPO")
- <hr>
- <h2>$1</h2>
- <file>
- <pre>
- <ol>
- EOF
- # print file
- while IFS= read -r l
- do
- printf "<li>%s</li>\n" "$(printf "%s" "$l" | escapehtml)"
- done < "$TMP/$1"
- echo "</ol>\n</pre>\n</file>\n</body>\n</html>"
- }
- updatetree() {
- echo "creating tree.html"
- cat <<- EOF > "$OUT/tree.html"
- $(pagehead "$REPO")
- $(pagesummary "$REPO")
- <hr>
- <h2>Tree</h2>
- <table>
- <tr><th>Size</th><th>Name</th></tr>
- EOF
- (cd "$TMP" && find * -type f -printf '%s %p\n') | while read -r s f
- do
- cat <<- EOF >> "$OUT/tree.html"
- <tr>
- <td>$s</td>
- <td><a href=tree/$f.html>$f</a></td>
- </tr>
- EOF
- # create html page with file content
- read -r op x <<- EOF
- $(git show --format='' --name-status "$1" -- "$f")
- EOF
- case "$op" in
- "D") rm "$OUT/tree/$f.html" ;;
- "C"|"M") filepage "$f" > "$OUT/tree/$f.html" ;;
- "") echo "no change for file $f" ;;
- esac
- done
- cat <<- EOF >> "$OUT/tree.html"
- </table>
- </body>
- </html>
- EOF
- }
- # first argument should be the version, e.g. v0.1.0
- creategomod() {
- # create page with meta tag
- echo "<meta name=\"go-import\" content=\"dovel.email/server mod https://dovel.email\">" > "$OUT?go-get=1"
- TMP="$(mktemp -d)"
- mkdir -p "$TMP/dovel.email/$REPO@$1"
- git --work-tree="$TMP/dovel.email/$REPO@$1/" checkout -f main
- PREFIX="${OUT%/*}/dovel.email/$REPO"
- [ -d "$PREFIX/@v" ] || mkdir -p "$PREFIX/@v"
- (cd "$TMP" && find * -type f -print | zip -@ "$PREFIX/@v/$1.zip")
- echo "{\"Version\":\"$1\"}" > "$PREFIX/@v/$1.info"
- echo "$1" >> "$PREFIX/@v/list"
- cp "$TMP/dovel.email/$REPO@$1/go.mod" "$PREFIX/@v/$1.mod"
- rm -rf "$TMP"
- }
- [ -d "$OUT/log" ] || mkdir -p "$OUT/log"
- git clone . "$TMP"
- while read oldrev newrev ref
- do
- case "$ref" in
- "refs/heads/main")
- updategit
- updateindex
- updaterefs
- updatetree "$newrev"
- updatelog
- ;;
- "refs/tags/v"*)
- echo "received version tag $ref"
- # check repo for go mod
- tag="${ref#refs/tags/}"
- for mod in $(find "$TMP/" -name go.mod)
- do
- creategomod "$tag"
- done
- ;;
- *) echo "$ref received. Doing nothing." ;;
- esac
- done
- rm -rf "$TMP"
- git update-server-info