commit 5307736cc9b6220ddee5e664e37f2279fedcd70a Author: Trevor Vallender Date: Thu May 2 19:55:34 2024 +0100 Add reviews We can now add very simple reviews as git notes! (and watch them float off into the void where noone will ever read them). diff --git a/README.md b/README.md new file mode 100644 index 0000000..c25306e --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# git-cr + +git-cr is a code review system which works at the commit, rather than PR, level. +It is designed for use by teams practising trunk-based development, where +reviews take place _after_ code is merged. If this sounds crazy, see +[my blog post on the topic](https://tsvallender.co.uk/blog_posts/a-vision-of-continuous-integration). + +git-cr stores code reviews in the same repository as your code, using +[git notes](https://git-scm.com/docs/git-notes). It allows you to review commits in +your own editor, with no other special tooling. It’s designed to be incredibly minimal +and meet you where you are. + +git-cr is a collection of BASH scripts, and should run on any UNIX-like system. + +git-cr is _very_ new and not ready for any kind of use! + +## Workflow + +```bash +git cr n # Review the currently checked out commit +``` + +## Features coming soon + +- List reviews on your commits only +- Tag necessary actions in reviews + - List actions needed + - Hook in your ticketing system to automatically make tickets from requested actions + +## Features coming maybe + +- Improved editor support for working with review files diff --git a/git-cr-new.bash b/git-cr-new.bash new file mode 100755 index 0000000..ae9b1c9 --- /dev/null +++ b/git-cr-new.bash @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +################################################################################ +# git-cr-new +# Adds a review at HEAD +################################################################################ + +set -o nounset +set -o pipefail +if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi + +USERNAME=$(git config user.name) +TMP_FILE=".git/REVIEW_EDITMSG.tmp" +MSG_FILE=".git/REVIEW_EDITMSG" + +main () { + # Get a formatted patch of the current permit as a starting point for the note + git diff HEAD~1 HEAD | grep -E '^[+-]' | sed -e '/---/i\\' | sed -e 's/^/# /' > "$TMP_FILE" + + vi "$TMP_FILE" + + # Remove comments + grep -Ev '^#' "$TMP_FILE" > "$MSG_FILE" + # Sign off + echo -e "\n--\nReviewed by $USERNAME\n--\n" >> "$MSG_FILE" + + git notes append --file="$MSG_FILE" +} + +main diff --git a/git-cr.bash b/git-cr.bash new file mode 100755 index 0000000..6bfe4ca --- /dev/null +++ b/git-cr.bash @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -o nounset +set -o pipefail +if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi + +while getopts "n" flag +do + case "${flag}" in + n) git-cr-new.bash;; + *) echo "Unexpected option ${flag}"; exit 1;; + esac +done