# Pull Gerrit comments

**URL:** <https://discuss.kakoune.com/t/pull-gerrit-comments/1012>\
**Category:** Recipes & Guides\
**Tags:** git\
**Created:** [May 12, 2020, 7:16am UTC](https://discuss.kakoune.com/t/pull-gerrit-comments/1012 "2020-05-12T07:16:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TeddyDD](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/teddydd/32/21_2.png) [@TeddyDD](https://discuss.kakoune.com/u/TeddyDD)\
**Post date:** [May 12, 2020, 7:16am UTC](https://discuss.kakoune.com/t/pull-gerrit-comments/1012/1 "2020-05-12T07:16:19Z")

</div>

Hacked in few minutes to get grep-like buffer with comments from Gerrit review. Works only if cwd is repo root and you have change id in commit. There is a lot of room for improvement but I don’t really care about Gerrit enough to bother. Hopefully this will be useful to someone

```auto
define-command -hidden gerrit-goto %{
    evaluate-commands -save-regs 'a' %{
        evaluate-commands -draft %{
            execute-keys -draft %{
                <a-i>p<a-:><a-;>x"ay
            }
        }
        execute-keys %{
            : edit<space><c-r>a<ret>
        }
    }
}

define-command gerrit-comments %{
    try %{ delete-buffer! *gerrit* }
    # edit -scratch *gerrit*
    evaluate-commands %sh{
        url="$(git config --get remote.origin.url | sed -e 's!^ssh://!!')"
        url="${url%/*}" # strip repo
        port="$(echo "$url" | awk -F : '{ print $NF }')"
        url="${url%:*}" # strip port
        output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-gerrit.XXXXXXXX)/fifo
        id=$(git log | grep -o -E "Change-Id:\s(.{41})" | head -n 1 | cut -f 2 -d ' ')
        mkfifo "${output}"
        (
            trap "rm -rf ${output}" EXIT
            ssh -p "$port" "$url" gerrit query --comments --patch-sets --format json $id |
                jq -r '.patchSets[] | select(.comments) | .comments[] | {file, line, message} | "\(.file) \(.line)\n\(.message)\n"' >${output}
        ) >/dev/null 2>&1 </dev/null &

        echo echo "$url" "$port"
        echo edit -fifo "${output}" '*gerrit*'
    }
    add-highlighter buffer/ regex '^[^\s]+\s(\d+)$' 0:blue 1:green
    map buffer normal <ret> :gerrit-goto<ret>
}

```

---

<div class="post-metadata">

**Author:** ![krobelus](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/krobelus/32/616_2.png) [@krobelus](https://discuss.kakoune.com/u/krobelus)\
**Post date:** [October 13, 2020, 6:17pm UTC](https://discuss.kakoune.com/t/pull-gerrit-comments/1012/2 "2020-10-13T18:17:30Z")

</div>

Looks neat! I’m working on a script for reading and writing GitLab review comments, there are quite some similarities.
