CLOCViz

Run some vizualizations on a repo

Published March 31, 2021 #git, #cloc, #clocviz

I've been looking at small tools that we could combine together to get a better sense of a repository. clocviz is a nifty on that puts a front end on top of cloc, so I packaged up a docker container that lets you pass in a url and will generate some static html for you.

First we package up clocviz

We'll build this using go 1.16.2 and then install a few dependancies, specifically cloc, wget, and git.

FROM golang:1.16.2-buster

RUN apt-get update && apt-get install -y cloc wget git

WORKDIR /app
RUN git clone https://github.com/cdkini/clocviz clocviz
RUN cd clocviz && go get && go build

COPY *sh ./
RUN chmod +x *sh
RUN chmod 777 /app

ENTRYPOINT /app/entry_point.sh

Script to pull down the repo and generate the html

This script expects the REPO environment variable to be set to a URI that git can clone. It will pull down the repo, then run clocviz, and then scrape the html into the /output directory (presumably mounted as a volume.)

  #/bin/bash
  REPO_WORK_DIR=/app/repository
  WORK_DIR=/output

  if [ -d ${REPO_WORK_DIR} ]; then
     echo Using repo in ${REPO_WORK_DIR}
  else
      if [ -z "$REPO" ]; then
          echo Please set the REPO env variable or mount ${REPO_WORK_DIR}
          exit 1
      fi

      git clone $REPO ${REPO_WORK_DIR}
  fi

  if [ ! -d ${WORK_DIR} ]; then
      echo Creating ${WORK_DIR}
      mkdir -p ${WORK_DIR}
  fi

  # clocviz serves static files from its filesystem, so we need to run it from there
  (cd /app/clocviz; clocviz $REPO_WORK_DIR &)

  cd $(mktemp -d)
  wget --recursive \
       --page-requisites \
       --convert-links \
       --no-parent \
       http://localhost:8080

   cp -r localhost:8080/* $WORK_DIR

Build the container

docker build . -t wschenk/clocviz

Do a run

  export REPO=https://github.com/ruby-git/ruby-git
  mkdir -p output

  docker run --rm -it \
         -v $PWD/output:/output \
         --env REPO \
         -u $(id -u) \
         wschenk/clocviz

Then test:

(cd output;npx live-server)

Thoughts

The output HTML needs a bit of work on smaller screens but that's pretty neat.

References

  1. https://github.com/cdkini/clocviz

Read next

See also

gitlog in sqlite

sql is great

askgit is a great way to look at information inside of a repository. However it currently doesn't support looking at the files inside of the commit itself – it gives you a view of the repository at the time of the commit, but not the patch itself. Since I don't know enough about golang and sqlite virtual tables, let's just create a sqlite3 database from the logfile. Get the gitlog We are going to use our favorite test repo, ruby-git because it's so deliciously meta.

Read more

Using Askgit

SQL is so nice

askgit provides a sql interface to your git repository. Let's install it and see what we can figure out about the repo. Installing Following the instructions on the website, we can build the go binary with: go get -v -tags=sqlite_vtable github.com/augmentable-dev/askgit This will download the package, the dependencies, and compile everything into an executable. If you can't figure out where it's installed, check that you have GOPATH set correctly, and it will end up in $GOPATH/bin.

Read more