Latest review note
This commit is contained in:
@@ -57,12 +57,31 @@ cmd_write() {
|
||||
fi
|
||||
}
|
||||
|
||||
cmd_latest() {
|
||||
local branch="${1:-$(git branch --show-current)}"
|
||||
local blob obj note br rnd best="" best_round=-1
|
||||
while read -r blob obj; do
|
||||
note=$(git notes --ref="$NOTES_REF" show "$obj") || continue
|
||||
br=$(sed -n 's/^branch: //p' <<<"$note")
|
||||
[ "$br" = "$branch" ] || continue
|
||||
rnd=$(sed -n 's/^round: //p' <<<"$note")
|
||||
[[ "$rnd" =~ ^[0-9]+$ ]] || continue
|
||||
if [ "$rnd" -gt "$best_round" ]; then
|
||||
best_round=$rnd
|
||||
best=$note
|
||||
fi
|
||||
done < <(git notes --ref="$NOTES_REF" list)
|
||||
[ -n "$best" ] || die "no review notes for branch: $branch"
|
||||
printf '%s\n' "$best"
|
||||
}
|
||||
|
||||
main() {
|
||||
local cmd="${1:-}"
|
||||
if [ $# -gt 0 ]; then shift; fi
|
||||
case "$cmd" in
|
||||
show) cmd_show "$@" ;;
|
||||
write) cmd_write "$@" ;;
|
||||
latest) cmd_latest "$@" ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -49,4 +49,23 @@ sed 's/^verdict: request-changes/verdict: approve/' "$note" > "$tmp/note1b"
|
||||
"$rn" write "$tmp/note1b" --force
|
||||
"$rn" show | grep -q '^verdict: approve$' || fail "show should print the replaced note"
|
||||
|
||||
echo "ok: show/write"
|
||||
# latest finds the note by branch, even from a newer unreviewed tip
|
||||
echo three > c.txt && git add c.txt && git commit -qm three
|
||||
"$rn" latest main | grep -q '^verdict: approve$' || fail "latest should find the round 1 note"
|
||||
|
||||
# a note for another branch must not leak into the result
|
||||
sed -e 's/^branch: main/branch: other/' -e 's/^round: 1/round: 9/' "$tmp/note1b" > "$tmp/other"
|
||||
"$rn" write "$tmp/other"
|
||||
"$rn" latest main | grep -q '^verdict: approve$' || fail "latest should ignore other branches"
|
||||
|
||||
# round 2 on the new tip wins and carries previous (replaces the
|
||||
# other-branch note on the same commit, so --force)
|
||||
PREV=$(git rev-parse HEAD~1)
|
||||
sed -e 's/^round: 1/round: 2/' -e "s/^previous: none/previous: $PREV/" "$tmp/note1b" > "$tmp/note2"
|
||||
"$rn" write "$tmp/note2" --force
|
||||
"$rn" latest main | grep -q '^round: 2$' || fail "latest should pick the highest round"
|
||||
"$rn" latest main | grep -q "^previous: $PREV$" || fail "round 2 should carry previous"
|
||||
|
||||
if "$rn" latest nosuch >/dev/null 2>&1; then fail "latest should exit 1 for an unknown branch"; fi
|
||||
|
||||
echo "ok: show/write/latest"
|
||||
|
||||
Reference in New Issue
Block a user