Reviewing PR from Vim: Critiq.vim
Tags: vim, productivity, git, github
Published: 2019-11-11 15:16:59

---
title: Reviewing PR from Vim: Critiq.vim
published: true
description: Yes, Github made some progress to smoothen the reviewer's job but I would still rather do it from my vim!
tags: vim, productivity, git, GitHub
cover_image: https://thepracticaldev.s3.amazonaws.com/i/a3d7e554k7q420qqsxn5.png
series: Vim Reviews
---

Reviewing PRs is daunting at times, even when dealing with merge requests less massive than the one showed in the cover picture. But regardless of the size of the PR, it has become my latest obsession: why should I quit the comfort of my own settings to review some code? Wouldn't I do the same faster if I was keeping my own cherished environment? 

So, after a quick web search, I found a few candidates and narrowed it to one by applying the "last commit on GitHub/Gitlab shouldn't be 3+ years old if issues are more recent" rule: [Critiq.vim](https://github.com/AGhost-7/critiq.vim/). 

# Preliminary work

Before using critiq.vim I had to make a few changes to [my config files](https://github.com/leojpod/dotfiles): mainly, I introduced a new file, which will be imported when loading zsh, that will load some secrets into environment variables to let Critiq use my GitHub account (the changes are in [this commit](https://github.com/leojpod/dotfiles/commit/e46b7bd35e13e5cb9e711658a611e61df692984d) if anyone is mad enough to check it). The nice thing to remember here is that you don't have to put your GitHub password to authenticate with Critiq (thanks for that!). Instead, you can just head to https://github.com/settings/tokens and generate an access token, give it just the rights you want and use that.

# Reviewing Critiq.vim
(pun intended)

The first thing you need to do once you've installed Critiq.vim is to simply call it: `:Critiq` which should list the open PRs from Github for your current project in a new tab (this was also a good opportunity for me to (re)learn about tabs in vim since I tend to do most things with only buffers). Pick one and press <kbd>Enter</kbd>. This should open 2 panes: the description of the PR in the upper pane and the diff in the lower one.

From there, just go about your business as you would in GH, with a few twists. 

### I don't get how it runs 🤔

`:CritiqCheckout` while it doesn't do exactly what it should (check out the branch locally), it does check out the code but under a weird name. I assume it does this to prevent conflicts with a potential local branch. Either way, after that you can just move to the previous tab to get your regular vim setting and go check that file or even simpler: `CritiqOpenFile` which will open the file in a new vertical pane for you. Isn't that neat? 


### That's code could be better! 

`:CritiqCommentLine` while the cursor is on the line you want to comment will open a new small pane at the bottom in which you can type your comment. When you're ready to submit it: `:CritiqSubmitComment`

I haven't found yet if there is a possibility to write up a suggestion directly but it's not too complicated to write it yourself since it is after all just a simple code sample typed as `suggestion`

### Approve/Reject/Comment

The last part of the process is now to submit your final assessment of the review: `:CritiqComment`, `:CritiqApprove` & `:CritiqRequestChanges` are here for that. They will open a new pane to write a comment justifying your assessment. Then use `:CritiqSubmitReview` and job done! 

I've created a quick terminal recording (with asciinema) to show how it works (which sadly doesn't keep my beloved colour scheme): 

[![asciicast](https://asciinema.org/a/14.png)](https://asciinema.org/a/280566)


# Final thoughts 

I'd like to see if it is possible to achieve the same thing for Gitlab as well. I also spend a good time on Gitlab-hosted projects and that would be grand!

Hope this can be somewhat useful to others and see you next time!